@@ -37,7 +37,7 @@ func TestGetInstallationConfig(t *testing.T) {
37
37
mock .InOrder (
38
38
m .On ("GetConfig" ).Return (config , nil ),
39
39
m .On ("SetConfigDefaults" , config ).Return (nil ),
40
- m .On ("ValidateConfig" , config ).Return (nil ),
40
+ m .On ("ValidateConfig" , config , 9001 ).Return (nil ),
41
41
)
42
42
},
43
43
expectedErr : false ,
@@ -73,7 +73,7 @@ func TestGetInstallationConfig(t *testing.T) {
73
73
mock .InOrder (
74
74
m .On ("GetConfig" ).Return (config , nil ),
75
75
m .On ("SetConfigDefaults" , config ).Return (nil ),
76
- m .On ("ValidateConfig" , config ).Return (errors .New ("validation error" )),
76
+ m .On ("ValidateConfig" , config , 9001 ).Return (errors .New ("validation error" )),
77
77
)
78
78
},
79
79
expectedErr : true ,
@@ -85,6 +85,7 @@ func TestGetInstallationConfig(t *testing.T) {
85
85
t .Run (tt .name , func (t * testing.T ) {
86
86
rc := runtimeconfig .New (nil , runtimeconfig .WithEnvSetter (& testEnvSetter {}))
87
87
rc .SetDataDir (t .TempDir ())
88
+ rc .SetManagerPort (9001 )
88
89
89
90
mockManager := & installation.MockInstallationManager {}
90
91
tt .setupMock (mockManager )
@@ -114,7 +115,7 @@ func TestConfigureInstallation(t *testing.T) {
114
115
tests := []struct {
115
116
name string
116
117
config * types.InstallationConfig
117
- setupMock func (* installation.MockInstallationManager , * types.InstallationConfig )
118
+ setupMock func (* installation.MockInstallationManager , runtimeconfig. RuntimeConfig , * types.InstallationConfig )
118
119
expectedErr bool
119
120
}{
120
121
{
@@ -123,29 +124,29 @@ func TestConfigureInstallation(t *testing.T) {
123
124
LocalArtifactMirrorPort : 9000 ,
124
125
DataDirectory : t .TempDir (),
125
126
},
126
- setupMock : func (m * installation.MockInstallationManager , config * types.InstallationConfig ) {
127
+ setupMock : func (m * installation.MockInstallationManager , rc runtimeconfig. RuntimeConfig , config * types.InstallationConfig ) {
127
128
mock .InOrder (
128
- m .On ("ValidateConfig" , config ).Return (nil ),
129
+ m .On ("ValidateConfig" , config , 9001 ).Return (nil ),
129
130
m .On ("SetConfig" , * config ).Return (nil ),
130
- m .On ("ConfigureHost" , t .Context ()).Return (nil ),
131
+ m .On ("ConfigureHost" , t .Context (), rc ).Return (nil ),
131
132
)
132
133
},
133
134
expectedErr : false ,
134
135
},
135
136
{
136
137
name : "validate error" ,
137
138
config : & types.InstallationConfig {},
138
- setupMock : func (m * installation.MockInstallationManager , config * types.InstallationConfig ) {
139
- m .On ("ValidateConfig" , config ).Return (errors .New ("validation error" ))
139
+ setupMock : func (m * installation.MockInstallationManager , rc runtimeconfig. RuntimeConfig , config * types.InstallationConfig ) {
140
+ m .On ("ValidateConfig" , config , 9001 ).Return (errors .New ("validation error" ))
140
141
},
141
142
expectedErr : true ,
142
143
},
143
144
{
144
145
name : "set config error" ,
145
146
config : & types.InstallationConfig {},
146
- setupMock : func (m * installation.MockInstallationManager , config * types.InstallationConfig ) {
147
+ setupMock : func (m * installation.MockInstallationManager , rc runtimeconfig. RuntimeConfig , config * types.InstallationConfig ) {
147
148
mock .InOrder (
148
- m .On ("ValidateConfig" , config ).Return (nil ),
149
+ m .On ("ValidateConfig" , config , 9001 ).Return (nil ),
149
150
m .On ("SetConfig" , * config ).Return (errors .New ("set config error" )),
150
151
)
151
152
},
@@ -157,16 +158,16 @@ func TestConfigureInstallation(t *testing.T) {
157
158
GlobalCIDR : "10.0.0.0/16" ,
158
159
DataDirectory : t .TempDir (),
159
160
},
160
- setupMock : func (m * installation.MockInstallationManager , config * types.InstallationConfig ) {
161
+ setupMock : func (m * installation.MockInstallationManager , rc runtimeconfig. RuntimeConfig , config * types.InstallationConfig ) {
161
162
// Create a copy with expected CIDR values after computation
162
163
configWithCIDRs := * config
163
164
configWithCIDRs .PodCIDR = "10.0.0.0/17"
164
165
configWithCIDRs .ServiceCIDR = "10.0.128.0/17"
165
166
166
167
mock .InOrder (
167
- m .On ("ValidateConfig" , config ).Return (nil ),
168
+ m .On ("ValidateConfig" , config , 9001 ).Return (nil ),
168
169
m .On ("SetConfig" , configWithCIDRs ).Return (nil ),
169
- m .On ("ConfigureHost" , t .Context ()).Return (nil ),
170
+ m .On ("ConfigureHost" , t .Context (), rc ).Return (nil ),
170
171
)
171
172
},
172
173
expectedErr : false ,
@@ -177,13 +178,14 @@ func TestConfigureInstallation(t *testing.T) {
177
178
t .Run (tt .name , func (t * testing.T ) {
178
179
rc := runtimeconfig .New (nil , runtimeconfig .WithEnvSetter (& testEnvSetter {}))
179
180
rc .SetDataDir (t .TempDir ())
181
+ rc .SetManagerPort (9001 )
180
182
181
183
mockManager := & installation.MockInstallationManager {}
182
184
183
185
// Create a copy of the config to avoid modifying the original
184
186
configCopy := * tt .config
185
187
186
- tt .setupMock (mockManager , & configCopy )
188
+ tt .setupMock (mockManager , rc , & configCopy )
187
189
188
190
controller , err := NewInstallController (
189
191
WithRuntimeConfig (rc ),
@@ -273,15 +275,15 @@ func TestRunHostPreflights(t *testing.T) {
273
275
274
276
tests := []struct {
275
277
name string
276
- setupMocks func (* preflight.MockHostPreflightManager )
278
+ setupMocks func (* preflight.MockHostPreflightManager , runtimeconfig. RuntimeConfig )
277
279
expectedErr bool
278
280
}{
279
281
{
280
282
name : "successful run preflights" ,
281
- setupMocks : func (pm * preflight.MockHostPreflightManager ) {
283
+ setupMocks : func (pm * preflight.MockHostPreflightManager , rc runtimeconfig. RuntimeConfig ) {
282
284
mock .InOrder (
283
- pm .On ("PrepareHostPreflights" , t .Context (), mock .Anything ).Return (expectedHPF , nil ),
284
- pm .On ("RunHostPreflights" , t .Context (), mock .MatchedBy (func (opts preflight.RunHostPreflightOptions ) bool {
285
+ pm .On ("PrepareHostPreflights" , t .Context (), rc , mock .Anything ).Return (expectedHPF , nil ),
286
+ pm .On ("RunHostPreflights" , t .Context (), rc , mock .MatchedBy (func (opts preflight.RunHostPreflightOptions ) bool {
285
287
return expectedHPF == opts .HostPreflightSpec
286
288
})).Return (nil ),
287
289
)
@@ -290,19 +292,19 @@ func TestRunHostPreflights(t *testing.T) {
290
292
},
291
293
{
292
294
name : "prepare preflights error" ,
293
- setupMocks : func (pm * preflight.MockHostPreflightManager ) {
295
+ setupMocks : func (pm * preflight.MockHostPreflightManager , rc runtimeconfig. RuntimeConfig ) {
294
296
mock .InOrder (
295
- pm .On ("PrepareHostPreflights" , t .Context (), mock .Anything ).Return (nil , errors .New ("prepare error" )),
297
+ pm .On ("PrepareHostPreflights" , t .Context (), rc , mock .Anything ).Return (nil , errors .New ("prepare error" )),
296
298
)
297
299
},
298
300
expectedErr : true ,
299
301
},
300
302
{
301
303
name : "run preflights error" ,
302
- setupMocks : func (pm * preflight.MockHostPreflightManager ) {
304
+ setupMocks : func (pm * preflight.MockHostPreflightManager , rc runtimeconfig. RuntimeConfig ) {
303
305
mock .InOrder (
304
- pm .On ("PrepareHostPreflights" , t .Context (), mock .Anything ).Return (expectedHPF , nil ),
305
- pm .On ("RunHostPreflights" , t .Context (), mock .MatchedBy (func (opts preflight.RunHostPreflightOptions ) bool {
306
+ pm .On ("PrepareHostPreflights" , t .Context (), rc , mock .Anything ).Return (expectedHPF , nil ),
307
+ pm .On ("RunHostPreflights" , t .Context (), rc , mock .MatchedBy (func (opts preflight.RunHostPreflightOptions ) bool {
306
308
return expectedHPF == opts .HostPreflightSpec
307
309
})).Return (errors .New ("run preflights error" )),
308
310
)
@@ -313,9 +315,6 @@ func TestRunHostPreflights(t *testing.T) {
313
315
314
316
for _ , tt := range tests {
315
317
t .Run (tt .name , func (t * testing.T ) {
316
- mockPreflightManager := & preflight.MockHostPreflightManager {}
317
- tt .setupMocks (mockPreflightManager )
318
-
319
318
rc := runtimeconfig .New (nil )
320
319
rc .SetDataDir (t .TempDir ())
321
320
rc .SetProxySpec (& ecv1beta1.ProxySpec {
@@ -325,6 +324,9 @@ func TestRunHostPreflights(t *testing.T) {
325
324
NoProxy : "no-proxy.com" ,
326
325
})
327
326
327
+ mockPreflightManager := & preflight.MockHostPreflightManager {}
328
+ tt .setupMocks (mockPreflightManager , rc )
329
+
328
330
controller , err := NewInstallController (
329
331
WithRuntimeConfig (rc ),
330
332
WithHostPreflightManager (mockPreflightManager ),
@@ -566,29 +568,25 @@ func TestGetInstallationStatus(t *testing.T) {
566
568
func TestSetupInfra (t * testing.T ) {
567
569
tests := []struct {
568
570
name string
569
- setupMocks func (* preflight.MockHostPreflightManager , * installation.MockInstallationManager , * infra.MockInfraManager , * metrics.MockReporter )
571
+ setupMocks func (runtimeconfig. RuntimeConfig , * preflight.MockHostPreflightManager , * installation.MockInstallationManager , * infra.MockInfraManager , * metrics.MockReporter )
570
572
expectedErr bool
571
573
}{
572
574
{
573
575
name : "successful setup with passed preflights" ,
574
- setupMocks : func (pm * preflight.MockHostPreflightManager , im * installation.MockInstallationManager , fm * infra.MockInfraManager , r * metrics.MockReporter ) {
576
+ setupMocks : func (rc runtimeconfig. RuntimeConfig , pm * preflight.MockHostPreflightManager , im * installation.MockInstallationManager , fm * infra.MockInfraManager , r * metrics.MockReporter ) {
575
577
preflightStatus := & types.Status {
576
578
State : types .StateSucceeded ,
577
579
}
578
- config := & types.InstallationConfig {
579
- AdminConsolePort : 8000 ,
580
- }
581
580
mock .InOrder (
582
581
pm .On ("GetHostPreflightStatus" , t .Context ()).Return (preflightStatus , nil ),
583
- im .On ("GetConfig" ).Return (config , nil ),
584
- fm .On ("Install" , t .Context (), config ).Return (nil ),
582
+ fm .On ("Install" , t .Context (), rc ).Return (nil ),
585
583
)
586
584
},
587
585
expectedErr : false ,
588
586
},
589
587
{
590
588
name : "successful setup with failed preflights" ,
591
- setupMocks : func (pm * preflight.MockHostPreflightManager , im * installation.MockInstallationManager , fm * infra.MockInfraManager , r * metrics.MockReporter ) {
589
+ setupMocks : func (rc runtimeconfig. RuntimeConfig , pm * preflight.MockHostPreflightManager , im * installation.MockInstallationManager , fm * infra.MockInfraManager , r * metrics.MockReporter ) {
592
590
preflightStatus := & types.Status {
593
591
State : types .StateFailed ,
594
592
}
@@ -600,29 +598,25 @@ func TestSetupInfra(t *testing.T) {
600
598
},
601
599
},
602
600
}
603
- config := & types.InstallationConfig {
604
- AdminConsolePort : 8000 ,
605
- }
606
601
mock .InOrder (
607
602
pm .On ("GetHostPreflightStatus" , t .Context ()).Return (preflightStatus , nil ),
608
603
pm .On ("GetHostPreflightOutput" , t .Context ()).Return (preflightOutput , nil ),
609
604
r .On ("ReportPreflightsFailed" , t .Context (), preflightOutput ).Return (nil ),
610
- im .On ("GetConfig" ).Return (config , nil ),
611
- fm .On ("Install" , t .Context (), config ).Return (nil ),
605
+ fm .On ("Install" , t .Context (), rc ).Return (nil ),
612
606
)
613
607
},
614
608
expectedErr : false ,
615
609
},
616
610
{
617
611
name : "preflight status error" ,
618
- setupMocks : func (pm * preflight.MockHostPreflightManager , im * installation.MockInstallationManager , fm * infra.MockInfraManager , r * metrics.MockReporter ) {
612
+ setupMocks : func (rc runtimeconfig. RuntimeConfig , pm * preflight.MockHostPreflightManager , im * installation.MockInstallationManager , fm * infra.MockInfraManager , r * metrics.MockReporter ) {
619
613
pm .On ("GetHostPreflightStatus" , t .Context ()).Return (nil , errors .New ("get preflight status error" ))
620
614
},
621
615
expectedErr : true ,
622
616
},
623
617
{
624
618
name : "preflight not completed" ,
625
- setupMocks : func (pm * preflight.MockHostPreflightManager , im * installation.MockInstallationManager , fm * infra.MockInfraManager , r * metrics.MockReporter ) {
619
+ setupMocks : func (rc runtimeconfig. RuntimeConfig , pm * preflight.MockHostPreflightManager , im * installation.MockInstallationManager , fm * infra.MockInfraManager , r * metrics.MockReporter ) {
626
620
preflightStatus := & types.Status {
627
621
State : types .StateRunning ,
628
622
}
@@ -632,7 +626,7 @@ func TestSetupInfra(t *testing.T) {
632
626
},
633
627
{
634
628
name : "preflight output error" ,
635
- setupMocks : func (pm * preflight.MockHostPreflightManager , im * installation.MockInstallationManager , fm * infra.MockInfraManager , r * metrics.MockReporter ) {
629
+ setupMocks : func (rc runtimeconfig. RuntimeConfig , pm * preflight.MockHostPreflightManager , im * installation.MockInstallationManager , fm * infra.MockInfraManager , r * metrics.MockReporter ) {
636
630
preflightStatus := & types.Status {
637
631
State : types .StateFailed ,
638
632
}
@@ -643,32 +637,15 @@ func TestSetupInfra(t *testing.T) {
643
637
},
644
638
expectedErr : true ,
645
639
},
646
- {
647
- name : "get config error" ,
648
- setupMocks : func (pm * preflight.MockHostPreflightManager , im * installation.MockInstallationManager , fm * infra.MockInfraManager , r * metrics.MockReporter ) {
649
- preflightStatus := & types.Status {
650
- State : types .StateSucceeded ,
651
- }
652
- mock .InOrder (
653
- pm .On ("GetHostPreflightStatus" , t .Context ()).Return (preflightStatus , nil ),
654
- im .On ("GetConfig" ).Return (nil , errors .New ("get config error" )),
655
- )
656
- },
657
- expectedErr : true ,
658
- },
659
640
{
660
641
name : "install infra error" ,
661
- setupMocks : func (pm * preflight.MockHostPreflightManager , im * installation.MockInstallationManager , fm * infra.MockInfraManager , r * metrics.MockReporter ) {
642
+ setupMocks : func (rc runtimeconfig. RuntimeConfig , pm * preflight.MockHostPreflightManager , im * installation.MockInstallationManager , fm * infra.MockInfraManager , r * metrics.MockReporter ) {
662
643
preflightStatus := & types.Status {
663
644
State : types .StateSucceeded ,
664
645
}
665
- config := & types.InstallationConfig {
666
- AdminConsolePort : 8000 ,
667
- }
668
646
mock .InOrder (
669
647
pm .On ("GetHostPreflightStatus" , t .Context ()).Return (preflightStatus , nil ),
670
- im .On ("GetConfig" ).Return (config , nil ),
671
- fm .On ("Install" , t .Context (), config ).Return (errors .New ("install error" )),
648
+ fm .On ("Install" , t .Context (), rc ).Return (errors .New ("install error" )),
672
649
)
673
650
},
674
651
expectedErr : true ,
@@ -677,13 +654,18 @@ func TestSetupInfra(t *testing.T) {
677
654
678
655
for _ , tt := range tests {
679
656
t .Run (tt .name , func (t * testing.T ) {
657
+ rc := runtimeconfig .New (nil )
658
+ rc .SetDataDir (t .TempDir ())
659
+ rc .SetManagerPort (9001 )
660
+
680
661
mockPreflightManager := & preflight.MockHostPreflightManager {}
681
662
mockInstallationManager := & installation.MockInstallationManager {}
682
663
mockInfraManager := & infra.MockInfraManager {}
683
664
mockMetricsReporter := & metrics.MockReporter {}
684
- tt .setupMocks (mockPreflightManager , mockInstallationManager , mockInfraManager , mockMetricsReporter )
665
+ tt .setupMocks (rc , mockPreflightManager , mockInstallationManager , mockInfraManager , mockMetricsReporter )
685
666
686
667
controller , err := NewInstallController (
668
+ WithRuntimeConfig (rc ),
687
669
WithHostPreflightManager (mockPreflightManager ),
688
670
WithInstallationManager (mockInstallationManager ),
689
671
WithInfraManager (mockInfraManager ),
0 commit comments