Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit 0a0f777

Browse files
committed
Nit fixes to tests
- Added some more test cases: version without any revision attached. - Fixed breaking ensure/pkg-errors/case1 integration test.
1 parent 1e56bdd commit 0a0f777

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

cmd/dep/init_test.go

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,41 +40,43 @@ func TestIsStdLib(t *testing.T) {
4040

4141
func TestGetProjectPropertiesFromVersion(t *testing.T) {
4242
cases := []struct {
43-
version gps.Version
44-
expected gps.Version
43+
version gps.Version
44+
want gps.Version
4545
}{
4646
{
47-
version: gps.NewBranch("foo-branch").Is("some-revision"),
48-
expected: gps.NewBranch("foo-branch"),
47+
version: gps.NewBranch("foo-branch"),
48+
want: gps.NewBranch("foo-branch"),
4949
},
5050
{
51-
version: gps.NewVersion("foo-version").Is("some-revision"),
52-
expected: gps.NewVersion("foo-version"),
51+
version: gps.NewVersion("foo-version"),
52+
want: gps.NewVersion("foo-version"),
5353
},
5454
{
55-
version: gps.Revision("alsjd934"),
56-
expected: nil,
55+
version: gps.NewBranch("foo-branch").Is("some-revision"),
56+
want: gps.NewBranch("foo-branch"),
57+
},
58+
{
59+
version: gps.NewVersion("foo-version").Is("some-revision"),
60+
want: gps.NewVersion("foo-version"),
61+
},
62+
{
63+
version: gps.Revision("some-revision"),
64+
want: nil,
5765
},
58-
// This fails. Hence, testing separately below.
59-
// {
60-
// version: gps.NewVersion("v1.0.0"),
61-
// expected: gps.NewVersion("^1.0.0"),
62-
// },
6366
}
6467

6568
for _, c := range cases {
6669
actualProp := getProjectPropertiesFromVersion(c.version)
67-
if c.expected != actualProp.Constraint {
68-
t.Fatalf("Expected %q to be equal to %q", actualProp.Constraint, c.expected)
70+
if c.want != actualProp.Constraint {
71+
t.Fatalf("Expected project property to be %v, got %v", actualProp.Constraint, c.want)
6972
}
7073
}
7174

75+
// Test to have caret in semver version
7276
outsemver := getProjectPropertiesFromVersion(gps.NewVersion("v1.0.0"))
73-
expectedSemver, _ := gps.NewSemverConstraint("^1.0.0")
74-
// Comparing outsemver.Constraint and expectedSemver fails with error
75-
// "comparing uncomparable type semver.rangeConstraint", although they have
76-
// same value and same type "gps.semverConstraint" as per "reflect".
77-
if outsemver.Constraint.String() != expectedSemver.String() {
78-
t.Fatalf("Expected %q to be equal to %q", outsemver, expectedSemver)
77+
wantSemver, _ := gps.NewSemverConstraint("^1.0.0")
78+
79+
if outsemver.Constraint.String() != wantSemver.String() {
80+
t.Fatalf("Expected semver to be %v, got %v", outsemver.Constraint, wantSemver)
7981
}
8082
}

cmd/dep/testdata/harness_tests/ensure/pkg-errors/case1/final/Gopkg.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)