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

cmd/dep: fix vndrImporter's rev->constraint logic #1058

Merged
merged 5 commits into from
Aug 29, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/dep/root_analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ func isVersion(pi gps.ProjectIdentifier, value string, sm gps.SourceManager) (bo
}

for _, version := range versions {
if version.Type() != gps.IsVersion && version.Type() != gps.IsSemver {
continue
}

if value == version.String() {
return true, version, nil
}
Expand Down
35 changes: 35 additions & 0 deletions cmd/dep/root_analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,41 @@ func TestProjectExistsInLock(t *testing.T) {
}
}

func TestIsVersion(t *testing.T) {
testcases := map[string]struct {
wantIsVersion bool
wantVersion gps.Version
}{
"v1.0.0": {wantIsVersion: true, wantVersion: gps.NewVersion("v1.0.0").Pair("ff2948a2ac8f538c4ecd55962e919d1e13e74baf")},
"3f4c3bea144e112a69bbe5d8d01c1b09a544253f": {wantIsVersion: false},
"master": {wantIsVersion: false},
}

pi := gps.ProjectIdentifier{ProjectRoot: gps.ProjectRoot("github.com/sdboyer/deptest")}
h := test.NewHelper(t)
defer h.Cleanup()

ctx := newTestContext(h)
sm, err := ctx.SourceManager()
h.Must(err)
defer sm.Release()

for value, testcase := range testcases {
t.Run(value, func(t *testing.T) {
gotIsVersion, gotVersion, err := isVersion(pi, value, sm)
h.Must(err)

if testcase.wantIsVersion != gotIsVersion {
t.Fatalf("Expected isVersion for %s to be %t", value, testcase.wantIsVersion)
}

if testcase.wantVersion != gotVersion {
t.Fatalf("Expected version for %s to be %s, got %s", value, testcase.wantVersion, gotVersion)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GOT and WNT style logging? 😅

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that a standard? I thought the test failure message was clear and I'm not sure what I should be changing it to. 😊

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's our standard 😛 Have been following since Sam picked that in one of my old PRs :)

t.Fatalf("unexpected isVersion result for %s: \n\t(GOT) %v \n\t(WNT) %v", value, gotIsVersion, testcase.wantIsVersion)

t.Fatalf("unexpected version for %s: \n\t(GOT) %v \n\t(WNT) %v", value, gotVersion, testcase.wantVersion)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the example! I have been doing my own thing and didn't know about the new standard. I'll make sure to use it going forward.

}
})
}
}

// convertTestCase is a common set of validations applied to the result
// of an importer converting from an external config format to dep's.
type convertTestCase struct {
Expand Down