Skip to content

Commit 28f4e14

Browse files
committed
crypto/internal/fips140deps: fix test for running in FIPS snapshot
In a FIPS snapshot, the import paths have a snapshot version number. Remove that version in the test before proceeding with the usual checks. Change-Id: I15c9d11dcac6d33330b334b8e5056c215bffa75c Reviewed-on: https://go-review.googlesource.com/c/go/+/629977 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Roland Shoemaker <[email protected]> Reviewed-by: Filippo Valsorda <[email protected]>
1 parent a2a4f00 commit 28f4e14

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/crypto/internal/fips140deps/fipsdeps_test.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,27 @@ func TestImports(t *testing.T) {
4040
{{range .XTestImports -}}
4141
{{$path}} {{.}}
4242
{{end -}}`, "crypto/internal/fips140/...")
43-
out, err := cmd.CombinedOutput()
43+
bout, err := cmd.CombinedOutput()
4444
if err != nil {
45-
t.Fatalf("go list: %v\n%s", err, out)
45+
t.Fatalf("go list: %v\n%s", err, bout)
46+
}
47+
out := string(bout)
48+
49+
// In a snapshot, all the paths are crypto/internal/fips140/v1.2.3/...
50+
// Determine the version number and remove it for the test.
51+
_, v, _ := strings.Cut(out, "crypto/internal/fips140/")
52+
v, _, _ = strings.Cut(v, "/")
53+
v, _, _ = strings.Cut(v, " ")
54+
if strings.HasPrefix(v, "v") && strings.Count(v, ".") == 2 {
55+
out = strings.ReplaceAll(out, "crypto/internal/fips140/"+v, "crypto/internal/fips140")
4656
}
4757

4858
allPackages := make(map[string]bool)
4959

5060
// importCheck is the set of packages that import crypto/internal/fips140/check.
5161
importCheck := make(map[string]bool)
5262

53-
for _, line := range strings.Split(string(out), "\n") {
63+
for _, line := range strings.Split(out, "\n") {
5464
if line == "" {
5565
continue
5666
}

0 commit comments

Comments
 (0)