Skip to content

Commit 85dfc4d

Browse files
author
Jay Conrod
committed
module: add unit test for MatchPathMajor, CheckPathMajor
Requested in CL 201497. The corresponding change will be made there after this is merged. Change-Id: I0726c475a34a5959e5b43f126e6bf03815686385 Reviewed-on: https://go-review.googlesource.com/c/mod/+/201517 Reviewed-by: Bryan C. Mills <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 69ba298 commit 85dfc4d

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

module/module.go

+3
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,9 @@ func MatchPathMajor(v, pathMajor string) bool {
511511
// CheckPathMajor returns a non-nil error if the semantic version v
512512
// does not match the path major version pathMajor.
513513
func CheckPathMajor(v, pathMajor string) error {
514+
// TODO(jayconrod): return errors or panic for invalid inputs. This function
515+
// (and others) was covered by integration tests for cmd/go, and surrounding
516+
// code protected against invalid inputs like non-canonical versions.
514517
if strings.HasPrefix(pathMajor, ".v") && strings.HasSuffix(pathMajor, "-unstable") {
515518
pathMajor = strings.TrimSuffix(pathMajor, "-unstable")
516519
}

module/module_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -317,3 +317,26 @@ func TestUnescapePath(t *testing.T) {
317317
}
318318
}
319319
}
320+
321+
func TestMatchPathMajor(t *testing.T) {
322+
for _, test := range []struct {
323+
v, pathMajor string
324+
want bool
325+
}{
326+
{"v0.0.0", "", true},
327+
{"v0.0.0", "/v2", false},
328+
{"v0.0.0", ".v0", true},
329+
{"v0.0.0-20190510104115-cbcb75029529", ".v1", true},
330+
{"v1.0.0", "/v2", false},
331+
{"v1.0.0", ".v1", true},
332+
{"v1.0.0", ".v1-unstable", true},
333+
{"v2.0.0+incompatible", "", true},
334+
{"v2.0.0", "", false},
335+
{"v2.0.0", "/v2", true},
336+
{"v2.0.0", ".v2", true},
337+
} {
338+
if got := MatchPathMajor(test.v, test.pathMajor); got != test.want {
339+
t.Errorf("MatchPathMajor(%q, %q) = %v, want %v", test.v, test.pathMajor, got, test.want)
340+
}
341+
}
342+
}

0 commit comments

Comments
 (0)