@@ -15,6 +15,7 @@ import (
15
15
ecv1beta1 "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1"
16
16
"github.com/replicatedhq/embedded-cluster/pkg/metrics"
17
17
"github.com/replicatedhq/embedded-cluster/pkg/release"
18
+ "github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig"
18
19
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
19
20
)
20
21
@@ -82,10 +83,16 @@ func TestGetInstallationConfig(t *testing.T) {
82
83
83
84
for _ , tt := range tests {
84
85
t .Run (tt .name , func (t * testing.T ) {
86
+ rc := runtimeconfig .New (nil , runtimeconfig .WithEnvSetter (& testEnvSetter {}))
87
+ rc .SetDataDir (t .TempDir ())
88
+
85
89
mockManager := & installation.MockInstallationManager {}
86
90
tt .setupMock (mockManager )
87
91
88
- controller , err := NewInstallController (WithInstallationManager (mockManager ))
92
+ controller , err := NewInstallController (
93
+ WithRuntimeConfig (rc ),
94
+ WithInstallationManager (mockManager ),
95
+ )
89
96
require .NoError (t , err )
90
97
91
98
result , err := controller .GetInstallationConfig (t .Context ())
@@ -120,7 +127,7 @@ func TestConfigureInstallation(t *testing.T) {
120
127
mock .InOrder (
121
128
m .On ("ValidateConfig" , config ).Return (nil ),
122
129
m .On ("SetConfig" , * config ).Return (nil ),
123
- m .On ("ConfigureHost" , t .Context (), config ).Return (nil ),
130
+ m .On ("ConfigureHost" , t .Context ()).Return (nil ),
124
131
)
125
132
},
126
133
expectedErr : false ,
@@ -159,7 +166,7 @@ func TestConfigureInstallation(t *testing.T) {
159
166
mock .InOrder (
160
167
m .On ("ValidateConfig" , config ).Return (nil ),
161
168
m .On ("SetConfig" , configWithCIDRs ).Return (nil ),
162
- m .On ("ConfigureHost" , t .Context (), & configWithCIDRs ).Return (nil ),
169
+ m .On ("ConfigureHost" , t .Context ()).Return (nil ),
163
170
)
164
171
},
165
172
expectedErr : false ,
@@ -168,14 +175,20 @@ func TestConfigureInstallation(t *testing.T) {
168
175
169
176
for _ , tt := range tests {
170
177
t .Run (tt .name , func (t * testing.T ) {
178
+ rc := runtimeconfig .New (nil , runtimeconfig .WithEnvSetter (& testEnvSetter {}))
179
+ rc .SetDataDir (t .TempDir ())
180
+
171
181
mockManager := & installation.MockInstallationManager {}
172
182
173
183
// Create a copy of the config to avoid modifying the original
174
184
configCopy := * tt .config
175
185
176
186
tt .setupMock (mockManager , & configCopy )
177
187
178
- controller , err := NewInstallController (WithInstallationManager (mockManager ))
188
+ controller , err := NewInstallController (
189
+ WithRuntimeConfig (rc ),
190
+ WithInstallationManager (mockManager ),
191
+ )
179
192
require .NoError (t , err )
180
193
181
194
err = controller .ConfigureInstallation (t .Context (), tt .config )
@@ -258,49 +271,39 @@ func TestRunHostPreflights(t *testing.T) {
258
271
},
259
272
}
260
273
261
- expectedProxy := & ecv1beta1.ProxySpec {
262
- HTTPProxy : "http://proxy.example.com" ,
263
- HTTPSProxy : "https://proxy.example.com" ,
264
- ProvidedNoProxy : "provided-proxy.com" ,
265
- NoProxy : "no-proxy.com" ,
266
- }
267
-
268
274
tests := []struct {
269
275
name string
270
- setupMocks func (* installation. MockInstallationManager , * preflight.MockHostPreflightManager )
276
+ setupMocks func (* preflight.MockHostPreflightManager )
271
277
expectedErr bool
272
278
}{
273
279
{
274
280
name : "successful run preflights" ,
275
- setupMocks : func (im * installation. MockInstallationManager , pm * preflight.MockHostPreflightManager ) {
281
+ setupMocks : func (pm * preflight.MockHostPreflightManager ) {
276
282
mock .InOrder (
277
- im .On ("GetConfig" ).Return (& types.InstallationConfig {}, nil ),
278
- pm .On ("PrepareHostPreflights" , t .Context (), mock .Anything ).Return (expectedHPF , expectedProxy , nil ),
283
+ pm .On ("PrepareHostPreflights" , t .Context (), mock .Anything ).Return (expectedHPF , nil ),
279
284
pm .On ("RunHostPreflights" , t .Context (), mock .MatchedBy (func (opts preflight.RunHostPreflightOptions ) bool {
280
- return expectedHPF == opts .HostPreflightSpec && expectedProxy == opts . Proxy
285
+ return expectedHPF == opts .HostPreflightSpec
281
286
})).Return (nil ),
282
287
)
283
288
},
284
289
expectedErr : false ,
285
290
},
286
291
{
287
292
name : "prepare preflights error" ,
288
- setupMocks : func (im * installation. MockInstallationManager , pm * preflight.MockHostPreflightManager ) {
293
+ setupMocks : func (pm * preflight.MockHostPreflightManager ) {
289
294
mock .InOrder (
290
- im .On ("GetConfig" ).Return (& types.InstallationConfig {}, nil ),
291
- pm .On ("PrepareHostPreflights" , t .Context (), mock .Anything ).Return (nil , nil , errors .New ("prepare error" )),
295
+ pm .On ("PrepareHostPreflights" , t .Context (), mock .Anything ).Return (nil , errors .New ("prepare error" )),
292
296
)
293
297
},
294
298
expectedErr : true ,
295
299
},
296
300
{
297
301
name : "run preflights error" ,
298
- setupMocks : func (im * installation. MockInstallationManager , pm * preflight.MockHostPreflightManager ) {
302
+ setupMocks : func (pm * preflight.MockHostPreflightManager ) {
299
303
mock .InOrder (
300
- im .On ("GetConfig" ).Return (& types.InstallationConfig {}, nil ),
301
- pm .On ("PrepareHostPreflights" , t .Context (), mock .Anything ).Return (expectedHPF , expectedProxy , nil ),
304
+ pm .On ("PrepareHostPreflights" , t .Context (), mock .Anything ).Return (expectedHPF , nil ),
302
305
pm .On ("RunHostPreflights" , t .Context (), mock .MatchedBy (func (opts preflight.RunHostPreflightOptions ) bool {
303
- return expectedHPF == opts .HostPreflightSpec && expectedProxy == opts . Proxy
306
+ return expectedHPF == opts .HostPreflightSpec
304
307
})).Return (errors .New ("run preflights error" )),
305
308
)
306
309
},
@@ -310,12 +313,20 @@ func TestRunHostPreflights(t *testing.T) {
310
313
311
314
for _ , tt := range tests {
312
315
t .Run (tt .name , func (t * testing.T ) {
313
- mockInstallationManager := & installation.MockInstallationManager {}
314
316
mockPreflightManager := & preflight.MockHostPreflightManager {}
315
- tt .setupMocks (mockInstallationManager , mockPreflightManager )
317
+ tt .setupMocks (mockPreflightManager )
318
+
319
+ rc := runtimeconfig .New (nil )
320
+ rc .SetDataDir (t .TempDir ())
321
+ rc .SetProxySpec (& ecv1beta1.ProxySpec {
322
+ HTTPProxy : "http://proxy.example.com" ,
323
+ HTTPSProxy : "https://proxy.example.com" ,
324
+ ProvidedNoProxy : "provided-proxy.com" ,
325
+ NoProxy : "no-proxy.com" ,
326
+ })
316
327
317
328
controller , err := NewInstallController (
318
- WithInstallationManager ( mockInstallationManager ),
329
+ WithRuntimeConfig ( rc ),
319
330
WithHostPreflightManager (mockPreflightManager ),
320
331
WithReleaseData (getTestReleaseData ()),
321
332
)
@@ -324,12 +335,11 @@ func TestRunHostPreflights(t *testing.T) {
324
335
err = controller .RunHostPreflights (t .Context (), RunHostPreflightsOptions {})
325
336
326
337
if tt .expectedErr {
327
- assert .Error (t , err )
338
+ require .Error (t , err )
328
339
} else {
329
- assert .NoError (t , err )
340
+ require .NoError (t , err )
330
341
}
331
342
332
- mockInstallationManager .AssertExpectations (t )
333
343
mockPreflightManager .AssertExpectations (t )
334
344
})
335
345
}
@@ -857,3 +867,15 @@ func WithInfraManager(infraManager infra.InfraManager) InstallControllerOption {
857
867
c .infraManager = infraManager
858
868
}
859
869
}
870
+
871
+ type testEnvSetter struct {
872
+ env map [string ]string
873
+ }
874
+
875
+ func (e * testEnvSetter ) Setenv (key string , val string ) error {
876
+ if e .env == nil {
877
+ e .env = make (map [string ]string )
878
+ }
879
+ e .env [key ] = val
880
+ return nil
881
+ }
0 commit comments