@@ -19,51 +19,57 @@ import (
1919 . "github.com/onsi/ginkgo"
2020 . "github.com/onsi/gomega"
2121 "github.com/spf13/pflag"
22- "sigs. k8s.io/kustomize/kyaml /sets"
22+ "k8s.io/apimachinery/pkg/util /sets"
2323)
2424
2525var _ = Describe ("CMD Switches" , func () {
2626 Context ("Testing Switches interface" , func () {
2727 It ("should disable runner" , func () {
28- s := New ([]string {"runner-a" , Disable ("runner-b" )})
28+ s := New ("runner-a" , "runner-b" )
29+ Expect (s .Set ("*,-runner-b" )).ToNot (HaveOccurred ())
2930 Expect (s .Enabled ("runner-a" )).To (BeTrue ())
3031 Expect (s .Enabled ("runner-b" )).To (BeFalse ())
3132 })
3233 It ("should return all items" , func () {
33- s := New ([]string {"runner-a" , Disable ("runner-b" )})
34+ s := New ("runner-a" , "runner-b" )
35+ Expect (s .Set ("*,-runner-b" )).ToNot (HaveOccurred ())
3436
35- expected := make (sets.String )
36- expected .Insert ("runner-a" , "runner-b" )
37+ expected := sets .NewString ("runner-a" , "runner-b" )
3738 Expect (s .All ()).To (Equal (expected ))
3839 })
40+ It ("should return all enabled items" , func () {
41+ s := New ("runner-a" , Disable ("runner-b" ))
42+
43+ expected := sets .NewString ("runner-a" )
44+ Expect (s .EnabledByDefault ()).To (Equal (expected ))
45+ })
3946 It ("should return all disabled items" , func () {
40- s := New ([] string { "runner-a" , Disable ("runner-b" )} )
47+ s := New ("runner-a" , Disable ("runner-b" ))
4148
42- expected := make (sets.String )
43- expected .Insert ("runner-b" )
49+ expected := sets .NewString ("runner-b" )
4450 Expect (s .DisabledByDefault ()).To (Equal (expected ))
4551 })
4652 It ("should return string" , func () {
47- s := New ([] string { "runner-a" , Disable ( "runner-b" )} )
48-
49- Expect (s .String ()).To (Equal ("map[ runner-a:true runner-b:false] " ))
53+ s := New ("runner-a" , "runner-b" )
54+ Expect ( s . Set ( "*,-runner-b" )). ToNot ( HaveOccurred ())
55+ Expect (s .String ()).To (Equal ("runner-a,- runner-b" ))
5056 })
5157 })
5258
5359 Context ("Testing flag package behavior" , func () {
54- It ("should keep default settings when no flag is passed" , func () {
60+ It ("should disable all controllers when no flag is passed" , func () {
5561 fs := flag .NewFlagSet ("" , flag .ExitOnError )
56- controllers := New ([] string { "runner-a" , Disable ("runner-b" ), "runner-c" } )
62+ controllers := New ("runner-a" , Disable ("runner-b" ), "runner-c" )
5763 fs .Var (controllers , "controllers" , "" )
5864
5965 Expect (fs .Parse ([]string {})).NotTo (HaveOccurred ())
60- Expect (controllers .Enabled ("runner-a" )).To (BeTrue ())
66+ Expect (controllers .Enabled ("runner-a" )).To (BeFalse ())
6167 Expect (controllers .Enabled ("runner-b" )).To (BeFalse ())
62- Expect (controllers .Enabled ("runner-c" )).To (BeTrue ())
68+ Expect (controllers .Enabled ("runner-c" )).To (BeFalse ())
6369 })
6470 It ("should keep default settings when * is passed" , func () {
6571 fs := flag .NewFlagSet ("" , flag .ExitOnError )
66- controllers := New ([] string { "runner-a" , Disable ("runner-b" ), "runner-c" } )
72+ controllers := New ("runner-a" , Disable ("runner-b" ), "runner-c" )
6773 fs .Var (controllers , "controllers" , "" )
6874
6975 Expect (fs .Parse ([]string {"--controllers=*" })).NotTo (HaveOccurred ())
@@ -73,7 +79,7 @@ var _ = Describe("CMD Switches", func() {
7379 })
7480 It ("should override default settings" , func () {
7581 fs := flag .NewFlagSet ("" , flag .ExitOnError )
76- controllers := New ([] string { "runner-a" , Disable ("runner-b" ), "runner-c" } )
82+ controllers := New ("runner-a" , Disable ("runner-b" ), "runner-c" )
7783 fs .Var (controllers , "controllers" , "" )
7884
7985 Expect (fs .Parse ([]string {"--controllers=runner-a,-runner-c" })).NotTo (HaveOccurred ())
@@ -83,7 +89,7 @@ var _ = Describe("CMD Switches", func() {
8389 })
8490 It ("should override some of default settings" , func () {
8591 fs := flag .NewFlagSet ("" , flag .ExitOnError )
86- controllers := New ([] string { "runner-a" , Disable ("runner-b" ), "runner-c" } )
92+ controllers := New ("runner-a" , Disable ("runner-b" ), "runner-c" )
8793 fs .Var (controllers , "controllers" , "" )
8894
8995 Expect (fs .Parse ([]string {"--controllers=*,-runner-a" })).NotTo (HaveOccurred ())
@@ -94,19 +100,19 @@ var _ = Describe("CMD Switches", func() {
94100 })
95101
96102 Context ("Testing pflag package behavior" , func () {
97- It ("should keep default settings when no flag is passed" , func () {
103+ It ("should disable all controllers when no flag is passed" , func () {
98104 fs := pflag .NewFlagSet ("" , pflag .ExitOnError )
99- controllers := New ([] string { "runner-a" , Disable ("runner-b" ), "runner-c" } )
105+ controllers := New ("runner-a" , Disable ("runner-b" ), "runner-c" )
100106 fs .Var (controllers , "controllers" , "" )
101107
102108 Expect (fs .Parse ([]string {})).NotTo (HaveOccurred ())
103- Expect (controllers .Enabled ("runner-a" )).To (BeTrue ())
109+ Expect (controllers .Enabled ("runner-a" )).To (BeFalse ())
104110 Expect (controllers .Enabled ("runner-b" )).To (BeFalse ())
105- Expect (controllers .Enabled ("runner-c" )).To (BeTrue ())
111+ Expect (controllers .Enabled ("runner-c" )).To (BeFalse ())
106112 })
107113 It ("should keep default settings when * is passed" , func () {
108114 fs := pflag .NewFlagSet ("" , pflag .ExitOnError )
109- controllers := New ([] string { "runner-a" , Disable ("runner-b" ), "runner-c" } )
115+ controllers := New ("runner-a" , Disable ("runner-b" ), "runner-c" )
110116 fs .Var (controllers , "controllers" , "" )
111117
112118 Expect (fs .Parse ([]string {"--controllers=*" })).NotTo (HaveOccurred ())
@@ -116,7 +122,7 @@ var _ = Describe("CMD Switches", func() {
116122 })
117123 It ("should override default settings" , func () {
118124 fs := pflag .NewFlagSet ("" , pflag .ExitOnError )
119- controllers := New ([] string { "runner-a" , Disable ("runner-b" ), "runner-c" } )
125+ controllers := New ("runner-a" , Disable ("runner-b" ), "runner-c" )
120126 fs .Var (controllers , "controllers" , "" )
121127
122128 Expect (fs .Parse ([]string {"--controllers=runner-a,-runner-c" })).NotTo (HaveOccurred ())
@@ -126,7 +132,7 @@ var _ = Describe("CMD Switches", func() {
126132 })
127133 It ("should override some of default settings" , func () {
128134 fs := pflag .NewFlagSet ("" , pflag .ExitOnError )
129- controllers := New ([] string { "runner-a" , Disable ("runner-b" ), "runner-c" } )
135+ controllers := New ("runner-a" , Disable ("runner-b" ), "runner-c" )
130136 fs .Var (controllers , "controllers" , "" )
131137
132138 Expect (fs .Parse ([]string {"--controllers=*,-runner-a" })).NotTo (HaveOccurred ())
0 commit comments