@@ -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 ())
@@ -96,11 +97,25 @@ func TestProxyGetConfig(t *testing.T) {
96
97
configFile := filepath .Join (dir , ".test-kubeconfig.yaml" )
97
98
g .Expect (os .WriteFile (configFile , []byte (kubeconfig ("management" , "default" )), 0600 )).To (Succeed ())
98
99
99
- proxy := newProxy (Kubeconfig {Path : configFile , Context : "management" }, InjectProxyTimeout (23 * time .Second ))
100
+ proxy := NewProxy (Kubeconfig {Path : configFile , Context : "management" }, InjectProxyTimeout (23 * time .Second ))
100
101
conf , err := proxy .GetConfig ()
101
102
g .Expect (err ).ToNot (HaveOccurred ())
102
103
g .Expect (conf .Timeout .String ()).To (Equal ("23s" ))
103
104
})
105
+
106
+ t .Run ("configure warning handler" , func (t * testing.T ) {
107
+ g := NewWithT (t )
108
+ dir , err := os .MkdirTemp ("" , "clusterctl" )
109
+ g .Expect (err ).ToNot (HaveOccurred ())
110
+ defer os .RemoveAll (dir )
111
+ configFile := filepath .Join (dir , ".test-kubeconfig.yaml" )
112
+ g .Expect (os .WriteFile (configFile , []byte (kubeconfig ("management" , "default" )), 0o600 )).To (Succeed ())
113
+
114
+ proxy := NewProxy (Kubeconfig {Path : configFile , Context : "management" }, InjectWarningHandler (rest.NoWarnings {}))
115
+ conf , err := proxy .GetConfig ()
116
+ g .Expect (err ).ToNot (HaveOccurred ())
117
+ g .Expect (conf .WarningHandler ).To (Equal (rest.NoWarnings {}))
118
+ })
104
119
}
105
120
106
121
// These tests are emulating the files passed in via KUBECONFIG env var by
@@ -123,7 +138,7 @@ func TestKUBECONFIGEnvVar(t *testing.T) {
123
138
configFile := filepath .Join (dir , ".test-kubeconfig.yaml" )
124
139
g .Expect (os .WriteFile (configFile , []byte (kubeconfigContents ), 0600 )).To (Succeed ())
125
140
126
- proxy := newProxy (
141
+ proxy := NewProxy (
127
142
// dont't give an explicit path but rather define the file in the
128
143
// configLoadingRules precedence chain.
129
144
Kubeconfig {Path : "" , Context : context },
@@ -151,7 +166,7 @@ func TestKUBECONFIGEnvVar(t *testing.T) {
151
166
configFile := filepath .Join (dir , ".test-kubeconfig.yaml" )
152
167
g .Expect (os .WriteFile (configFile , []byte (kubeconfigContents ), 0600 )).To (Succeed ())
153
168
154
- proxy := newProxy (
169
+ proxy := NewProxy (
155
170
// dont't give an explicit path but rather define the file in the
156
171
// configLoadingRules precedence chain.
157
172
Kubeconfig {Path : "" , Context : context },
@@ -229,7 +244,7 @@ func TestProxyCurrentNamespace(t *testing.T) {
229
244
g .Expect (os .WriteFile (configFile , []byte (tt .kubeconfigContents ), 0600 )).To (Succeed ())
230
245
}
231
246
232
- proxy := newProxy (Kubeconfig {Path : configFile , Context : tt .kubeconfigContext })
247
+ proxy := NewProxy (Kubeconfig {Path : configFile , Context : tt .kubeconfigContext })
233
248
ns , err := proxy .CurrentNamespace ()
234
249
if tt .expectErr {
235
250
g .Expect (err ).To (HaveOccurred ())
0 commit comments