Commit Graph

7 Commits

Author SHA1 Message Date
Fraser Waters 0f4ddc2ccf
Use EqualError/ErrorContains instead of Error ()
<!--- 
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->

This is a pass over all of /sdk to replace asserts that just checked we
had an error with asserts for what the error value is.

Just checking for an error is a weak test that can result in error paths
being broken and tests not detecting it.
2023-12-08 06:40:14 +00:00
Fraser Waters 6a63558b2f
Use context.Background in tests ()
As suggested by the [godocs](https://pkg.go.dev/context#Background).

This means a search for `context.TODO` now just shows up places we
really do seem to be missing a threaded in context in real code.
2023-09-25 12:25:26 +00:00
Michael Bridgen 3507b09a5d Support clones from Azure DevOps
In general, go-git can't clone from Azure DevOps, because the latter
requires the capabilities multi_ack and multi_ack_detailed, which aren't
implemented. However, there's now a workaround, which boils down to
this: pretend, for the initial clone, that those capabilities _are_
supported, and expect them not to be used.

(See https://github.com/go-git/go-git/pull/613 for more on this
workaround.)

Signed-off-by: Michael Bridgen <mbridgen@pulumi.com>
2023-02-02 16:56:51 +00:00
Eng Zer Jun 48eff4676a
test: use T.TempDir to create temporary test directory
This commit replaces `ioutil.TempDir` with `t.TempDir` in tests. The
directory created by `t.TempDir` is automatically removed when the test
and all its subtests complete.

Prior to this commit, temporary directory created using `ioutil.TempDir`
needs to be removed manually by calling `os.RemoveAll`, which is omitted
in some tests. The error handling boilerplate e.g.
	defer func() {
		if err := os.RemoveAll(dir); err != nil {
			t.Fatal(err)
		}
	}
is also tedious, but `t.TempDir` handles this for us nicely.

Reference: https://pkg.go.dev/testing#T.TempDir
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-12-03 15:17:08 +08:00
Michael Bridgen 4478bc0f69
Work with all kinds of branch names ()
* Generalise git branch test

In  the git checkout was adapted so it would work with simple
branch names (i.e., "main" rather than "refs/heads/main"). However, it
still won't work with a branch that's not the default branch -- this
test demonstrates so.

* Support all simple and full branch names

If you want to have a non-default branch checked out, you need to fetch
it _and_ make a local reference for it. If you don't giv e a specific
reference, *Repository.Clone(...) updates remote heads, but does not
create local refs.

So, to support the varieties of branch names that people might use, the
provided branch name needs to be interpreted, and used for the
*Repository.Clone(...).

* Support cloning at a tag

Although the field is .Branch, we might expect people to ask for a tag
too. It's probably possible, with some back and forth, to disambiguate
between a simple branch name and a simple tag name; but, for the sake of
simplicity, require people to give `refs/tags/tag`.

* Queue changelog entry

* Check more cases of supplied branch name

 - ... including things that should result in an error
 - verify that the remote named in a remote ref is "origin"; anything
   else is surely a mistake

Signed-off-by: Michael Bridgen <mbridgen@pulumi.com>
2022-08-22 13:41:17 +01:00
Fraser Waters c9094f2ceb
Update go-git to v5 ()
* Update go-git to v5

* Add to CHANGELOG
2022-08-09 12:46:28 +01:00
Michael Bridgen c48b9d9eaf
Accept short branch names in GitRepo.Branch ()
* Accept short branch names in GitRepo.Branch

Users often give short names for branches -- e.g., `dev`, rather than
`refs/heads/dev`. This commit makes that work rather than produce an
error, by adopting the heuristic that anything that doesn't look like a
full branch name (i.e., not starting with ref/heads/) must be a short
name.

Signed-off-by: Michael Bridgen <mbridgen@pulumi.com>
2022-07-13 16:42:45 +01:00