Skip to content

Commit 1f4b8b3

Browse files
authored
make TestKrewVersion a substring check (#497)
Instead of full map comparison, relax it to be "map has all these keys with the values that contain these strings". This way, we can test krew version stamping (as it's not deterministic at testing-time) as well as add more 'krew version' values without needing to strictly match test. Signed-off-by: Ahmet Alp Balkan <[email protected]>
1 parent 867ad1e commit 1f4b8b3

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

integration_test/version_test.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ import (
1919
"regexp"
2020
"strings"
2121
"testing"
22-
23-
"github.com/google/go-cmp/cmp"
2422
)
2523

2624
func TestKrewVersion(t *testing.T) {
@@ -47,16 +45,21 @@ func TestKrewVersion(t *testing.T) {
4745
requiredSubstrings := map[string]string{
4846
"OPTION": "VALUE",
4947
"BasePath": test.Root(),
50-
"GitTag": "unknown",
51-
"GitCommit": "unknown",
48+
"GitTag": "",
49+
"GitCommit": "",
5250
"IndexURI": "https://github.com/kubernetes-sigs/krew-index.git",
5351
"IndexPath": path.Join(test.Root(), "index"),
5452
"InstallPath": path.Join(test.Root(), "store"),
5553
"BinPath": path.Join(test.Root(), "bin"),
56-
"DetectedPlatform": "linux/amd64",
54+
"DetectedPlatform": "/",
5755
}
5856

59-
if diff := cmp.Diff(actual, requiredSubstrings); diff != "" {
60-
t.Errorf("`krew version` output mismatch (-got, +want):\n%s", diff)
57+
for k, v := range requiredSubstrings {
58+
got, ok := actual[k]
59+
if !ok {
60+
t.Errorf("`krew version` output doesn't contain field %q", k)
61+
} else if !strings.Contains(got, v) {
62+
t.Errorf("`krew version` %q field doesn't contain string %q (got: %q)", k, v, got)
63+
}
6164
}
6265
}

0 commit comments

Comments
 (0)