15
15
package integrationtest
16
16
17
17
import (
18
- "fmt "
18
+ "path "
19
19
"regexp"
20
+ "strings"
20
21
"testing"
22
+
23
+ "github.com/google/go-cmp/cmp"
21
24
)
22
25
23
26
func TestKrewVersion (t * testing.T ) {
@@ -26,21 +29,34 @@ func TestKrewVersion(t *testing.T) {
26
29
test , cleanup := NewTest (t )
27
30
defer cleanup ()
28
31
29
- output := test .Krew ("version" ).RunOrFailOutput ()
32
+ stdOut := string (test .Krew ("version" ).RunOrFailOutput ())
33
+
34
+ lineSplit := regexp .MustCompile (`\s+` )
35
+ actual := make (map [string ]string )
36
+ for _ , line := range strings .Split (stdOut , "\n " ) {
37
+ if line == "" {
38
+ continue
39
+ }
40
+ optionValue := lineSplit .Split (line , 2 )
41
+ if len (optionValue ) < 2 {
42
+ t .Errorf ("Expect `krew version` to output `OPTION VALUE` pair separated by spaces, got: %v" , optionValue )
43
+ }
44
+ actual [optionValue [0 ]] = optionValue [1 ]
45
+ }
30
46
31
- requiredSubstrings := []string {
32
- fmt .Sprintf (`BasePath\s+%s` , test .Root ()),
33
- "GitTag" ,
34
- "GitCommit" ,
35
- `IndexURI\s+https://github.com/kubernetes-sigs/krew-index.git` ,
36
- "IndexPath" ,
37
- "InstallPath" ,
38
- "BinPath" ,
47
+ requiredSubstrings := map [string ]string {
48
+ "OPTION" : "VALUE" ,
49
+ "BasePath" : test .Root (),
50
+ "GitTag" : "unknown" ,
51
+ "GitCommit" : "unknown" ,
52
+ "IndexURI" : "https://github.com/kubernetes-sigs/krew-index.git" ,
53
+ "IndexPath" : path .Join (test .Root (), "index" ),
54
+ "InstallPath" : path .Join (test .Root (), "store" ),
55
+ "BinPath" : path .Join (test .Root (), "bin" ),
56
+ "DetectedPlatform" : "linux/amd64" ,
39
57
}
40
58
41
- for _ , p := range requiredSubstrings {
42
- if regexp .MustCompile (p ).FindSubmatchIndex (output ) == nil {
43
- t .Errorf ("Expected to find %q in output of `krew version`" , p )
44
- }
59
+ if diff := cmp .Diff (actual , requiredSubstrings ); diff != "" {
60
+ t .Errorf ("`krew version` output mismatch (-got, +want):\n %s" , diff )
45
61
}
46
62
}
0 commit comments