@@ -37,7 +37,7 @@ func TestGetInstallationConfig(t *testing.T) {
3737 mock .InOrder (
3838 m .On ("GetConfig" ).Return (config , nil ),
3939 m .On ("SetConfigDefaults" , config ).Return (nil ),
40- m .On ("ValidateConfig" , config ).Return (nil ),
40+ m .On ("ValidateConfig" , config , 9001 ).Return (nil ),
4141 )
4242 },
4343 expectedErr : false ,
@@ -73,7 +73,7 @@ func TestGetInstallationConfig(t *testing.T) {
7373 mock .InOrder (
7474 m .On ("GetConfig" ).Return (config , nil ),
7575 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" )),
7777 )
7878 },
7979 expectedErr : true ,
@@ -85,6 +85,7 @@ func TestGetInstallationConfig(t *testing.T) {
8585 t .Run (tt .name , func (t * testing.T ) {
8686 rc := runtimeconfig .New (nil , runtimeconfig .WithEnvSetter (& testEnvSetter {}))
8787 rc .SetDataDir (t .TempDir ())
88+ rc .SetManagerPort (9001 )
8889
8990 mockManager := & installation.MockInstallationManager {}
9091 tt .setupMock (mockManager )
@@ -114,7 +115,7 @@ func TestConfigureInstallation(t *testing.T) {
114115 tests := []struct {
115116 name string
116117 config * types.InstallationConfig
117- setupMock func (* installation.MockInstallationManager , * types.InstallationConfig )
118+ setupMock func (* installation.MockInstallationManager , runtimeconfig. RuntimeConfig , * types.InstallationConfig )
118119 expectedErr bool
119120 }{
120121 {
@@ -123,29 +124,29 @@ func TestConfigureInstallation(t *testing.T) {
123124 LocalArtifactMirrorPort : 9000 ,
124125 DataDirectory : t .TempDir (),
125126 },
126- setupMock : func (m * installation.MockInstallationManager , config * types.InstallationConfig ) {
127+ setupMock : func (m * installation.MockInstallationManager , rc runtimeconfig. RuntimeConfig , config * types.InstallationConfig ) {
127128 mock .InOrder (
128- m .On ("ValidateConfig" , config ).Return (nil ),
129+ m .On ("ValidateConfig" , config , 9001 ).Return (nil ),
129130 m .On ("SetConfig" , * config ).Return (nil ),
130- m .On ("ConfigureHost" , t .Context ()).Return (nil ),
131+ m .On ("ConfigureHost" , t .Context (), rc ).Return (nil ),
131132 )
132133 },
133134 expectedErr : false ,
134135 },
135136 {
136137 name : "validate error" ,
137138 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" ))
140141 },
141142 expectedErr : true ,
142143 },
143144 {
144145 name : "set config error" ,
145146 config : & types.InstallationConfig {},
146- setupMock : func (m * installation.MockInstallationManager , config * types.InstallationConfig ) {
147+ setupMock : func (m * installation.MockInstallationManager , rc runtimeconfig. RuntimeConfig , config * types.InstallationConfig ) {
147148 mock .InOrder (
148- m .On ("ValidateConfig" , config ).Return (nil ),
149+ m .On ("ValidateConfig" , config , 9001 ).Return (nil ),
149150 m .On ("SetConfig" , * config ).Return (errors .New ("set config error" )),
150151 )
151152 },
@@ -157,16 +158,16 @@ func TestConfigureInstallation(t *testing.T) {
157158 GlobalCIDR : "10.0.0.0/16" ,
158159 DataDirectory : t .TempDir (),
159160 },
160- setupMock : func (m * installation.MockInstallationManager , config * types.InstallationConfig ) {
161+ setupMock : func (m * installation.MockInstallationManager , rc runtimeconfig. RuntimeConfig , config * types.InstallationConfig ) {
161162 // Create a copy with expected CIDR values after computation
162163 configWithCIDRs := * config
163164 configWithCIDRs .PodCIDR = "10.0.0.0/17"
164165 configWithCIDRs .ServiceCIDR = "10.0.128.0/17"
165166
166167 mock .InOrder (
167- m .On ("ValidateConfig" , config ).Return (nil ),
168+ m .On ("ValidateConfig" , config , 9001 ).Return (nil ),
168169 m .On ("SetConfig" , configWithCIDRs ).Return (nil ),
169- m .On ("ConfigureHost" , t .Context ()).Return (nil ),
170+ m .On ("ConfigureHost" , t .Context (), rc ).Return (nil ),
170171 )
171172 },
172173 expectedErr : false ,
@@ -177,13 +178,14 @@ func TestConfigureInstallation(t *testing.T) {
177178 t .Run (tt .name , func (t * testing.T ) {
178179 rc := runtimeconfig .New (nil , runtimeconfig .WithEnvSetter (& testEnvSetter {}))
179180 rc .SetDataDir (t .TempDir ())
181+ rc .SetManagerPort (9001 )
180182
181183 mockManager := & installation.MockInstallationManager {}
182184
183185 // Create a copy of the config to avoid modifying the original
184186 configCopy := * tt .config
185187
186- tt .setupMock (mockManager , & configCopy )
188+ tt .setupMock (mockManager , rc , & configCopy )
187189
188190 controller , err := NewInstallController (
189191 WithRuntimeConfig (rc ),
@@ -273,15 +275,15 @@ func TestRunHostPreflights(t *testing.T) {
273275
274276 tests := []struct {
275277 name string
276- setupMocks func (* preflight.MockHostPreflightManager )
278+ setupMocks func (* preflight.MockHostPreflightManager , runtimeconfig. RuntimeConfig )
277279 expectedErr bool
278280 }{
279281 {
280282 name : "successful run preflights" ,
281- setupMocks : func (pm * preflight.MockHostPreflightManager ) {
283+ setupMocks : func (pm * preflight.MockHostPreflightManager , rc runtimeconfig. RuntimeConfig ) {
282284 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 {
285287 return expectedHPF == opts .HostPreflightSpec
286288 })).Return (nil ),
287289 )
@@ -290,19 +292,19 @@ func TestRunHostPreflights(t *testing.T) {
290292 },
291293 {
292294 name : "prepare preflights error" ,
293- setupMocks : func (pm * preflight.MockHostPreflightManager ) {
295+ setupMocks : func (pm * preflight.MockHostPreflightManager , rc runtimeconfig. RuntimeConfig ) {
294296 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" )),
296298 )
297299 },
298300 expectedErr : true ,
299301 },
300302 {
301303 name : "run preflights error" ,
302- setupMocks : func (pm * preflight.MockHostPreflightManager ) {
304+ setupMocks : func (pm * preflight.MockHostPreflightManager , rc runtimeconfig. RuntimeConfig ) {
303305 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 {
306308 return expectedHPF == opts .HostPreflightSpec
307309 })).Return (errors .New ("run preflights error" )),
308310 )
@@ -313,9 +315,6 @@ func TestRunHostPreflights(t *testing.T) {
313315
314316 for _ , tt := range tests {
315317 t .Run (tt .name , func (t * testing.T ) {
316- mockPreflightManager := & preflight.MockHostPreflightManager {}
317- tt .setupMocks (mockPreflightManager )
318-
319318 rc := runtimeconfig .New (nil )
320319 rc .SetDataDir (t .TempDir ())
321320 rc .SetProxySpec (& ecv1beta1.ProxySpec {
@@ -325,6 +324,9 @@ func TestRunHostPreflights(t *testing.T) {
325324 NoProxy : "no-proxy.com" ,
326325 })
327326
327+ mockPreflightManager := & preflight.MockHostPreflightManager {}
328+ tt .setupMocks (mockPreflightManager , rc )
329+
328330 controller , err := NewInstallController (
329331 WithRuntimeConfig (rc ),
330332 WithHostPreflightManager (mockPreflightManager ),
@@ -566,29 +568,25 @@ func TestGetInstallationStatus(t *testing.T) {
566568func TestSetupInfra (t * testing.T ) {
567569 tests := []struct {
568570 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 )
570572 expectedErr bool
571573 }{
572574 {
573575 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 ) {
575577 preflightStatus := & types.Status {
576578 State : types .StateSucceeded ,
577579 }
578- config := & types.InstallationConfig {
579- AdminConsolePort : 8000 ,
580- }
581580 mock .InOrder (
582581 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 ),
585583 )
586584 },
587585 expectedErr : false ,
588586 },
589587 {
590588 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 ) {
592590 preflightStatus := & types.Status {
593591 State : types .StateFailed ,
594592 }
@@ -600,29 +598,25 @@ func TestSetupInfra(t *testing.T) {
600598 },
601599 },
602600 }
603- config := & types.InstallationConfig {
604- AdminConsolePort : 8000 ,
605- }
606601 mock .InOrder (
607602 pm .On ("GetHostPreflightStatus" , t .Context ()).Return (preflightStatus , nil ),
608603 pm .On ("GetHostPreflightOutput" , t .Context ()).Return (preflightOutput , nil ),
609604 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 ),
612606 )
613607 },
614608 expectedErr : false ,
615609 },
616610 {
617611 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 ) {
619613 pm .On ("GetHostPreflightStatus" , t .Context ()).Return (nil , errors .New ("get preflight status error" ))
620614 },
621615 expectedErr : true ,
622616 },
623617 {
624618 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 ) {
626620 preflightStatus := & types.Status {
627621 State : types .StateRunning ,
628622 }
@@ -632,7 +626,7 @@ func TestSetupInfra(t *testing.T) {
632626 },
633627 {
634628 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 ) {
636630 preflightStatus := & types.Status {
637631 State : types .StateFailed ,
638632 }
@@ -643,32 +637,15 @@ func TestSetupInfra(t *testing.T) {
643637 },
644638 expectedErr : true ,
645639 },
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- },
659640 {
660641 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 ) {
662643 preflightStatus := & types.Status {
663644 State : types .StateSucceeded ,
664645 }
665- config := & types.InstallationConfig {
666- AdminConsolePort : 8000 ,
667- }
668646 mock .InOrder (
669647 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" )),
672649 )
673650 },
674651 expectedErr : true ,
@@ -677,13 +654,18 @@ func TestSetupInfra(t *testing.T) {
677654
678655 for _ , tt := range tests {
679656 t .Run (tt .name , func (t * testing.T ) {
657+ rc := runtimeconfig .New (nil )
658+ rc .SetDataDir (t .TempDir ())
659+ rc .SetManagerPort (9001 )
660+
680661 mockPreflightManager := & preflight.MockHostPreflightManager {}
681662 mockInstallationManager := & installation.MockInstallationManager {}
682663 mockInfraManager := & infra.MockInfraManager {}
683664 mockMetricsReporter := & metrics.MockReporter {}
684- tt .setupMocks (mockPreflightManager , mockInstallationManager , mockInfraManager , mockMetricsReporter )
665+ tt .setupMocks (rc , mockPreflightManager , mockInstallationManager , mockInfraManager , mockMetricsReporter )
685666
686667 controller , err := NewInstallController (
668+ WithRuntimeConfig (rc ),
687669 WithHostPreflightManager (mockPreflightManager ),
688670 WithInstallationManager (mockInstallationManager ),
689671 WithInfraManager (mockInfraManager ),
0 commit comments