@@ -9,13 +9,18 @@ import (
9
9
"github.com/stretchr/testify/mock"
10
10
"github.com/stretchr/testify/require"
11
11
12
+ appconfig "github.com/replicatedhq/embedded-cluster/api/internal/managers/app/config"
12
13
"github.com/replicatedhq/embedded-cluster/api/internal/managers/kubernetes/infra"
13
14
"github.com/replicatedhq/embedded-cluster/api/internal/managers/kubernetes/installation"
14
15
"github.com/replicatedhq/embedded-cluster/api/internal/statemachine"
15
16
"github.com/replicatedhq/embedded-cluster/api/internal/store"
16
17
"github.com/replicatedhq/embedded-cluster/api/types"
18
+ ecv1beta1 "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1"
17
19
"github.com/replicatedhq/embedded-cluster/pkg/kubernetesinstallation"
18
20
"github.com/replicatedhq/embedded-cluster/pkg/metrics"
21
+ "github.com/replicatedhq/embedded-cluster/pkg/release"
22
+ kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
23
+ "github.com/replicatedhq/kotskinds/multitype"
19
24
)
20
25
21
26
func TestGetInstallationConfig (t * testing.T ) {
@@ -253,20 +258,49 @@ func TestGetInstallationStatus(t *testing.T) {
253
258
}
254
259
255
260
func TestSetupInfra (t * testing.T ) {
261
+ // Create an app config
262
+ appConfig := kotsv1beta1.Config {
263
+ Spec : kotsv1beta1.ConfigSpec {
264
+ Groups : []kotsv1beta1.ConfigGroup {
265
+ {
266
+ Name : "test-group" ,
267
+ Title : "Test Group" ,
268
+ Items : []kotsv1beta1.ConfigItem {
269
+ {
270
+ Name : "test-item" ,
271
+ Type : "text" ,
272
+ Title : "Test Item" ,
273
+ Default : multitype.BoolOrString {StrVal : "default" },
274
+ Value : multitype.BoolOrString {StrVal : "value" },
275
+ },
276
+ },
277
+ },
278
+ },
279
+ },
280
+ }
281
+ configValues := kotsv1beta1.ConfigValues {
282
+ Spec : kotsv1beta1.ConfigValuesSpec {
283
+ Values : map [string ]kotsv1beta1.ConfigValue {
284
+ "test-item" : {Default : "default" , Value : "value" },
285
+ },
286
+ },
287
+ }
288
+
256
289
tests := []struct {
257
290
name string
258
291
currentState statemachine.State
259
292
expectedState statemachine.State
260
- setupMocks func (kubernetesinstallation.Installation , * installation.MockInstallationManager , * infra.MockInfraManager , * metrics.MockReporter , * store.MockStore )
293
+ setupMocks func (kubernetesinstallation.Installation , * installation.MockInstallationManager , * infra.MockInfraManager , * metrics.MockReporter , * store.MockStore , * appconfig. MockAppConfigManager )
261
294
expectedErr error
262
295
}{
263
296
{
264
297
name : "successful setup" ,
265
298
currentState : StateInstallationConfigured ,
266
299
expectedState : StateSucceeded ,
267
- setupMocks : func (ki kubernetesinstallation.Installation , im * installation.MockInstallationManager , fm * infra.MockInfraManager , mr * metrics.MockReporter , st * store.MockStore ) {
300
+ setupMocks : func (ki kubernetesinstallation.Installation , im * installation.MockInstallationManager , fm * infra.MockInfraManager , mr * metrics.MockReporter , st * store.MockStore , am * appconfig. MockAppConfigManager ) {
268
301
mock .InOrder (
269
- fm .On ("Install" , mock .Anything , ki ).Return (nil ),
302
+ am .On ("GetKotsadmConfigValues" , appConfig ).Return (configValues , nil ),
303
+ fm .On ("Install" , mock .Anything , ki , configValues ).Return (nil ),
270
304
// TODO: we are not yet reporting
271
305
// mr.On("ReportInstallationSucceeded", mock.Anything),
272
306
)
@@ -277,9 +311,10 @@ func TestSetupInfra(t *testing.T) {
277
311
name : "install infra error" ,
278
312
currentState : StateInstallationConfigured ,
279
313
expectedState : StateInfrastructureInstallFailed ,
280
- setupMocks : func (ki kubernetesinstallation.Installation , im * installation.MockInstallationManager , fm * infra.MockInfraManager , mr * metrics.MockReporter , st * store.MockStore ) {
314
+ setupMocks : func (ki kubernetesinstallation.Installation , im * installation.MockInstallationManager , fm * infra.MockInfraManager , mr * metrics.MockReporter , st * store.MockStore , am * appconfig. MockAppConfigManager ) {
281
315
mock .InOrder (
282
- fm .On ("Install" , mock .Anything , ki ).Return (errors .New ("install error" )),
316
+ am .On ("GetKotsadmConfigValues" , appConfig ).Return (configValues , nil ),
317
+ fm .On ("Install" , mock .Anything , ki , configValues ).Return (errors .New ("install error" )),
283
318
st .LinuxInfraMockStore .On ("GetStatus" ).Return (types.Status {Description : "install error" }, nil ),
284
319
// TODO: we are not yet reporting
285
320
// mr.On("ReportInstallationFailed", mock.Anything, errors.New("install error")),
@@ -291,9 +326,10 @@ func TestSetupInfra(t *testing.T) {
291
326
name : "install infra error without report if infra store fails" ,
292
327
currentState : StateInstallationConfigured ,
293
328
expectedState : StateInfrastructureInstallFailed ,
294
- setupMocks : func (ki kubernetesinstallation.Installation , im * installation.MockInstallationManager , fm * infra.MockInfraManager , mr * metrics.MockReporter , st * store.MockStore ) {
329
+ setupMocks : func (ki kubernetesinstallation.Installation , im * installation.MockInstallationManager , fm * infra.MockInfraManager , mr * metrics.MockReporter , st * store.MockStore , am * appconfig. MockAppConfigManager ) {
295
330
mock .InOrder (
296
- fm .On ("Install" , mock .Anything , ki ).Return (errors .New ("install error" )),
331
+ am .On ("GetKotsadmConfigValues" , appConfig ).Return (configValues , nil ),
332
+ fm .On ("Install" , mock .Anything , ki , configValues ).Return (errors .New ("install error" )),
297
333
st .LinuxInfraMockStore .On ("GetStatus" ).Return (nil , assert .AnError ),
298
334
)
299
335
},
@@ -303,9 +339,10 @@ func TestSetupInfra(t *testing.T) {
303
339
name : "install infra panic" ,
304
340
currentState : StateInstallationConfigured ,
305
341
expectedState : StateInfrastructureInstallFailed ,
306
- setupMocks : func (ki kubernetesinstallation.Installation , im * installation.MockInstallationManager , fm * infra.MockInfraManager , mr * metrics.MockReporter , st * store.MockStore ) {
342
+ setupMocks : func (ki kubernetesinstallation.Installation , im * installation.MockInstallationManager , fm * infra.MockInfraManager , mr * metrics.MockReporter , st * store.MockStore , am * appconfig. MockAppConfigManager ) {
307
343
mock .InOrder (
308
- fm .On ("Install" , mock .Anything , ki ).Panic ("this is a panic" ),
344
+ am .On ("GetKotsadmConfigValues" , appConfig ).Return (configValues , nil ),
345
+ fm .On ("Install" , mock .Anything , ki , configValues ).Panic ("this is a panic" ),
309
346
st .LinuxInfraMockStore .On ("GetStatus" ).Return (types.Status {Description : "this is a panic" }, nil ),
310
347
// TODO: we are not yet reporting
311
348
// mr.On("ReportInstallationFailed", mock.Anything, errors.New("this is a panic")),
@@ -317,10 +354,21 @@ func TestSetupInfra(t *testing.T) {
317
354
name : "invalid state transition" ,
318
355
currentState : StateNew ,
319
356
expectedState : StateNew ,
320
- setupMocks : func (ki kubernetesinstallation.Installation , im * installation.MockInstallationManager , fm * infra.MockInfraManager , mr * metrics.MockReporter , st * store.MockStore ) {
357
+ setupMocks : func (ki kubernetesinstallation.Installation , im * installation.MockInstallationManager , fm * infra.MockInfraManager , mr * metrics.MockReporter , st * store.MockStore , am * appconfig. MockAppConfigManager ) {
321
358
},
322
359
expectedErr : assert .AnError , // Just check that an error occurs, don't care about exact message
323
360
},
361
+ {
362
+ name : "config values error" ,
363
+ currentState : StateInstallationConfigured ,
364
+ expectedState : StateInstallationConfigured ,
365
+ setupMocks : func (ki kubernetesinstallation.Installation , im * installation.MockInstallationManager , fm * infra.MockInfraManager , mr * metrics.MockReporter , st * store.MockStore , am * appconfig.MockAppConfigManager ) {
366
+ mock .InOrder (
367
+ am .On ("GetKotsadmConfigValues" , appConfig ).Return (kotsv1beta1.ConfigValues {}, assert .AnError ),
368
+ )
369
+ },
370
+ expectedErr : assert .AnError ,
371
+ },
324
372
}
325
373
326
374
for _ , tt := range tests {
@@ -334,14 +382,17 @@ func TestSetupInfra(t *testing.T) {
334
382
mockInfraManager := & infra.MockInfraManager {}
335
383
mockMetricsReporter := & metrics.MockReporter {}
336
384
mockStore := & store.MockStore {}
337
- tt .setupMocks (ki , mockInstallationManager , mockInfraManager , mockMetricsReporter , mockStore )
385
+ mockAppConfigManager := & appconfig.MockAppConfigManager {}
386
+ tt .setupMocks (ki , mockInstallationManager , mockInfraManager , mockMetricsReporter , mockStore , mockAppConfigManager )
338
387
339
388
controller , err := NewInstallController (
340
389
WithInstallation (ki ),
341
390
WithStateMachine (sm ),
342
391
WithInstallationManager (mockInstallationManager ),
343
392
WithInfraManager (mockInfraManager ),
393
+ WithAppConfigManager (mockAppConfigManager ),
344
394
WithMetricsReporter (mockMetricsReporter ),
395
+ WithReleaseData (getTestReleaseData (& appConfig )),
345
396
WithStore (mockStore ),
346
397
)
347
398
require .NoError (t , err )
@@ -451,3 +502,11 @@ func TestGetInfra(t *testing.T) {
451
502
})
452
503
}
453
504
}
505
+
506
+ func getTestReleaseData (appConfig * kotsv1beta1.Config ) * release.ReleaseData {
507
+ return & release.ReleaseData {
508
+ EmbeddedClusterConfig : & ecv1beta1.Config {},
509
+ ChannelRelease : & release.ChannelRelease {},
510
+ AppConfig : appConfig ,
511
+ }
512
+ }
0 commit comments