Skip to content

Commit dfd0419

Browse files
committed
add unit test
1 parent 22628bd commit dfd0419

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

cmd/flagutils/utils_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2021 The Kubernetes Authors.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package flagutils
5+
6+
import (
7+
"fmt"
8+
"testing"
9+
10+
"sigs.k8s.io/cli-utils/pkg/inventory"
11+
)
12+
13+
func TestConvertInventoryPolicy(t *testing.T) {
14+
testcases := []struct {
15+
value string
16+
policy inventory.InventoryPolicy
17+
err error
18+
}{
19+
{
20+
value: "strict",
21+
policy: inventory.InventoryPolicyMustMatch,
22+
},
23+
{
24+
value: "adopt",
25+
policy: inventory.AdoptIfNoInventory,
26+
},
27+
{
28+
value: "random",
29+
err: fmt.Errorf("inventory policy must be one of strict, adopt"),
30+
},
31+
}
32+
for _, tc := range testcases {
33+
t.Run(tc.value, func(t *testing.T) {
34+
policy, err := ConvertInventoryPolicy(tc.value)
35+
if tc.err == nil {
36+
if err != nil {
37+
t.Errorf("unexpected error %v", err)
38+
}
39+
if policy != tc.policy {
40+
t.Errorf("expected %v but got %v", policy, tc.policy)
41+
}
42+
}
43+
if err == nil && tc.err != nil {
44+
t.Errorf("expected an error, but not happened")
45+
}
46+
})
47+
}
48+
}

0 commit comments

Comments
 (0)