File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed
Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments