1
- // Copyright 2019 The Kubernetes Authors.
1
+ // Copyright 2020 The Kubernetes Authors.
2
2
//
3
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
4
// you may not use this file except in compliance with the License.
@@ -17,6 +17,12 @@ package installation
17
17
import (
18
18
"path/filepath"
19
19
"testing"
20
+
21
+ "github.com/google/go-cmp/cmp"
22
+
23
+ "sigs.k8s.io/krew/internal/testutil"
24
+ "sigs.k8s.io/krew/pkg/constants"
25
+ "sigs.k8s.io/krew/pkg/index"
20
26
)
21
27
22
28
func testdataPath (t * testing.T ) string {
@@ -26,3 +32,49 @@ func testdataPath(t *testing.T) string {
26
32
}
27
33
return filepath .Join (pwd , "testdata" )
28
34
}
35
+
36
+ func TestListInstalledPlugins (t * testing.T ) {
37
+ tests := []struct {
38
+ name string
39
+ plugins []index.Plugin
40
+ expected map [string ]string
41
+ }{
42
+ {
43
+ name : "single plugin" ,
44
+ plugins : []index.Plugin {testutil .NewPlugin ().WithName ("test" ).WithVersion ("v0.0.1" ).V ()},
45
+ expected : map [string ]string {"test" : "v0.0.1" },
46
+ },
47
+ {
48
+ name : "multiple plugins" ,
49
+ plugins : []index.Plugin {
50
+ testutil .NewPlugin ().WithName ("plugin-a" ).WithVersion ("v0.0.1" ).V (),
51
+ testutil .NewPlugin ().WithName ("plugin-b" ).WithVersion ("v0.1.0" ).V (),
52
+ testutil .NewPlugin ().WithName ("plugin-c" ).WithVersion ("v1.0.0" ).V (),
53
+ },
54
+ expected : map [string ]string {
55
+ "plugin-a" : "v0.0.1" ,
56
+ "plugin-b" : "v0.1.0" ,
57
+ "plugin-c" : "v1.0.0" ,
58
+ },
59
+ },
60
+ }
61
+
62
+ for _ , test := range tests {
63
+ t .Run (test .name , func (t * testing.T ) {
64
+ tempDir , cleanup := testutil .NewTempDir (t )
65
+ defer cleanup ()
66
+
67
+ for _ , plugin := range test .plugins {
68
+ tempDir .WritePlugin (plugin .Name + constants .ManifestExtension , plugin )
69
+ }
70
+
71
+ actual , err := ListInstalledPlugins (tempDir .Root ())
72
+ if err != nil {
73
+ t .Fatal (err )
74
+ }
75
+ if diff := cmp .Diff (test .expected , actual ); diff != "" {
76
+ t .Error (diff )
77
+ }
78
+ })
79
+ }
80
+ }
0 commit comments