@@ -24,6 +24,7 @@ import (
24
24
"time"
25
25
26
26
. "github.com/onsi/gomega"
27
+ "k8s.io/client-go/rest"
27
28
28
29
"sigs.k8s.io/cluster-api/cmd/clusterctl/internal/test"
29
30
"sigs.k8s.io/cluster-api/version"
@@ -69,7 +70,7 @@ func TestProxyGetConfig(t *testing.T) {
69
70
configFile := filepath .Join (dir , ".test-kubeconfig.yaml" )
70
71
g .Expect (os .WriteFile (configFile , []byte (tt .kubeconfigContents ), 0600 )).To (Succeed ())
71
72
72
- proxy := newProxy (Kubeconfig {Path : configFile , Context : tt .context })
73
+ proxy := NewProxy (Kubeconfig {Path : configFile , Context : tt .context })
73
74
conf , err := proxy .GetConfig ()
74
75
if tt .expectErr {
75
76
g .Expect (err ).To (HaveOccurred ())
@@ -88,18 +89,47 @@ func TestProxyGetConfig(t *testing.T) {
88
89
}
89
90
})
90
91
91
- t .Run ("configure timeout" , func (t * testing.T ) {
92
- g := NewWithT (t )
93
- dir , err := os .MkdirTemp ("" , "clusterctl" )
94
- g .Expect (err ).ToNot (HaveOccurred ())
95
- defer os .RemoveAll (dir )
96
- configFile := filepath .Join (dir , ".test-kubeconfig.yaml" )
97
- g .Expect (os .WriteFile (configFile , []byte (kubeconfig ("management" , "default" )), 0600 )).To (Succeed ())
92
+ t .Run ("configure option" , func (t * testing.T ) {
93
+ tests := []struct {
94
+ name string
95
+ option ProxyOption
96
+ optionTester func (t * testing.T , r * rest.Config , e error )
97
+ }{
98
+ {
99
+ name : "timeout" ,
100
+ option : InjectProxyTimeout (23 * time .Second ),
101
+ optionTester : func (t * testing.T , r * rest.Config , e error ) {
102
+ t .Helper ()
103
+ g := NewWithT (t )
104
+ g .Expect (e ).ToNot (HaveOccurred ())
105
+ g .Expect (r .Timeout .String ()).To (Equal ("23s" ))
106
+ },
107
+ },
108
+ {
109
+ name : "warning handler" ,
110
+ option : InjectWarningHandler (rest.NoWarnings {}),
111
+ optionTester : func (t * testing.T , r * rest.Config , e error ) {
112
+ t .Helper ()
113
+ g := NewWithT (t )
114
+ g .Expect (e ).ToNot (HaveOccurred ())
115
+ g .Expect (r .WarningHandler ).To (Equal (rest.NoWarnings {}))
116
+ },
117
+ },
118
+ }
119
+ for _ , tt := range tests {
120
+ t .Run (tt .name , func (t * testing.T ) {
121
+ g := NewWithT (t )
122
+ dir , err := os .MkdirTemp ("" , "clusterctl" )
123
+ g .Expect (err ).ToNot (HaveOccurred ())
124
+ defer os .RemoveAll (dir )
125
+ configFile := filepath .Join (dir , ".test-kubeconfig.yaml" )
126
+ g .Expect (os .WriteFile (configFile , []byte (kubeconfig ("management" , "default" )), 0600 )).To (Succeed ())
98
127
99
- proxy := newProxy (Kubeconfig {Path : configFile , Context : "management" }, InjectProxyTimeout (23 * time .Second ))
100
- conf , err := proxy .GetConfig ()
101
- g .Expect (err ).ToNot (HaveOccurred ())
102
- g .Expect (conf .Timeout .String ()).To (Equal ("23s" ))
128
+ proxy := NewProxy (Kubeconfig {Path : configFile , Context : "management" }, tt .option )
129
+ conf , err := proxy .GetConfig ()
130
+ tt .optionTester (t , conf , err )
131
+ })
132
+ }
103
133
})
104
134
}
105
135
@@ -123,7 +153,7 @@ func TestKUBECONFIGEnvVar(t *testing.T) {
123
153
configFile := filepath .Join (dir , ".test-kubeconfig.yaml" )
124
154
g .Expect (os .WriteFile (configFile , []byte (kubeconfigContents ), 0600 )).To (Succeed ())
125
155
126
- proxy := newProxy (
156
+ proxy := NewProxy (
127
157
// dont't give an explicit path but rather define the file in the
128
158
// configLoadingRules precedence chain.
129
159
Kubeconfig {Path : "" , Context : context },
@@ -151,7 +181,7 @@ func TestKUBECONFIGEnvVar(t *testing.T) {
151
181
configFile := filepath .Join (dir , ".test-kubeconfig.yaml" )
152
182
g .Expect (os .WriteFile (configFile , []byte (kubeconfigContents ), 0600 )).To (Succeed ())
153
183
154
- proxy := newProxy (
184
+ proxy := NewProxy (
155
185
// dont't give an explicit path but rather define the file in the
156
186
// configLoadingRules precedence chain.
157
187
Kubeconfig {Path : "" , Context : context },
@@ -229,7 +259,7 @@ func TestProxyCurrentNamespace(t *testing.T) {
229
259
g .Expect (os .WriteFile (configFile , []byte (tt .kubeconfigContents ), 0600 )).To (Succeed ())
230
260
}
231
261
232
- proxy := newProxy (Kubeconfig {Path : configFile , Context : tt .kubeconfigContext })
262
+ proxy := NewProxy (Kubeconfig {Path : configFile , Context : tt .kubeconfigContext })
233
263
ns , err := proxy .CurrentNamespace ()
234
264
if tt .expectErr {
235
265
g .Expect (err ).To (HaveOccurred ())
0 commit comments