@@ -211,9 +211,16 @@ func TestLinuxSetupInfra(t *testing.T) {
211
211
assert .Equal (t , "application/json" , r .Header .Get ("Content-Type" ))
212
212
assert .Equal (t , "Bearer test-token" , r .Header .Get ("Authorization" ))
213
213
214
+ // Decode request body
215
+ var config types.LinuxInfraSetupRequest
216
+ err := json .NewDecoder (r .Body ).Decode (& config )
217
+ require .NoError (t , err , "Failed to decode request body" )
218
+
219
+ assert .True (t , config .IgnoreHostPreflights )
220
+
214
221
// Return successful response
215
222
w .WriteHeader (http .StatusOK )
216
- json .NewEncoder (w ).Encode (types.LinuxInfra {
223
+ json .NewEncoder (w ).Encode (types.Infra {
217
224
Status : types.Status {
218
225
State : types .StateRunning ,
219
226
Description : "Installing infra" ,
@@ -224,7 +231,7 @@ func TestLinuxSetupInfra(t *testing.T) {
224
231
225
232
// Test successful setup
226
233
c := New (server .URL , WithToken ("test-token" ))
227
- infra , err := c .SetupLinuxInfra ()
234
+ infra , err := c .SetupLinuxInfra (true )
228
235
assert .NoError (t , err )
229
236
assert .Equal (t , types .StateRunning , infra .Status .State )
230
237
assert .Equal (t , "Installing infra" , infra .Status .Description )
@@ -240,9 +247,9 @@ func TestLinuxSetupInfra(t *testing.T) {
240
247
defer errorServer .Close ()
241
248
242
249
c = New (errorServer .URL , WithToken ("test-token" ))
243
- infra , err = c .SetupLinuxInfra ()
250
+ infra , err = c .SetupLinuxInfra (true )
244
251
assert .Error (t , err )
245
- assert .Equal (t , types.LinuxInfra {}, infra )
252
+ assert .Equal (t , types.Infra {}, infra )
246
253
247
254
apiErr , ok := err .(* types.APIError )
248
255
require .True (t , ok , "Expected err to be of type *types.APIError" )
@@ -261,7 +268,7 @@ func TestLinuxGetInfraStatus(t *testing.T) {
261
268
262
269
// Return successful response
263
270
w .WriteHeader (http .StatusOK )
264
- json .NewEncoder (w ).Encode (types.LinuxInfra {
271
+ json .NewEncoder (w ).Encode (types.Infra {
265
272
Status : types.Status {
266
273
State : types .StateSucceeded ,
267
274
Description : "Installation successful" ,
@@ -290,7 +297,7 @@ func TestLinuxGetInfraStatus(t *testing.T) {
290
297
c = New (errorServer .URL , WithToken ("test-token" ))
291
298
infra , err = c .GetLinuxInfraStatus ()
292
299
assert .Error (t , err )
293
- assert .Equal (t , types.LinuxInfra {}, infra )
300
+ assert .Equal (t , types.Infra {}, infra )
294
301
295
302
apiErr , ok := err .(* types.APIError )
296
303
require .True (t , ok , "Expected err to be of type *types.APIError" )
@@ -453,6 +460,102 @@ func TestKubernetesGetInstallationStatus(t *testing.T) {
453
460
assert .Equal (t , "Internal Server Error" , apiErr .Message )
454
461
}
455
462
463
+ func TestKubernetesSetupInfra (t * testing.T ) {
464
+ // Create a test server
465
+ server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
466
+ assert .Equal (t , "POST" , r .Method )
467
+ assert .Equal (t , "/api/kubernetes/install/infra/setup" , r .URL .Path )
468
+
469
+ assert .Equal (t , "application/json" , r .Header .Get ("Content-Type" ))
470
+ assert .Equal (t , "Bearer test-token" , r .Header .Get ("Authorization" ))
471
+
472
+ // Return successful response
473
+ w .WriteHeader (http .StatusOK )
474
+ json .NewEncoder (w ).Encode (types.Infra {
475
+ Status : types.Status {
476
+ State : types .StateRunning ,
477
+ Description : "Installing infra" ,
478
+ },
479
+ })
480
+ }))
481
+ defer server .Close ()
482
+
483
+ // Test successful setup
484
+ c := New (server .URL , WithToken ("test-token" ))
485
+ infra , err := c .SetupKubernetesInfra ()
486
+ assert .NoError (t , err )
487
+ assert .Equal (t , types .StateRunning , infra .Status .State )
488
+ assert .Equal (t , "Installing infra" , infra .Status .Description )
489
+
490
+ // Test error response
491
+ errorServer := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
492
+ w .WriteHeader (http .StatusInternalServerError )
493
+ json .NewEncoder (w ).Encode (types.APIError {
494
+ StatusCode : http .StatusInternalServerError ,
495
+ Message : "Internal Server Error" ,
496
+ })
497
+ }))
498
+ defer errorServer .Close ()
499
+
500
+ c = New (errorServer .URL , WithToken ("test-token" ))
501
+ infra , err = c .SetupKubernetesInfra ()
502
+ assert .Error (t , err )
503
+ assert .Equal (t , types.Infra {}, infra )
504
+
505
+ apiErr , ok := err .(* types.APIError )
506
+ require .True (t , ok , "Expected err to be of type *types.APIError" )
507
+ assert .Equal (t , http .StatusInternalServerError , apiErr .StatusCode )
508
+ assert .Equal (t , "Internal Server Error" , apiErr .Message )
509
+ }
510
+
511
+ func TestKubernetesGetInfraStatus (t * testing.T ) {
512
+ // Create a test server
513
+ server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
514
+ assert .Equal (t , "GET" , r .Method )
515
+ assert .Equal (t , "/api/kubernetes/install/infra/status" , r .URL .Path )
516
+
517
+ assert .Equal (t , "application/json" , r .Header .Get ("Content-Type" ))
518
+ assert .Equal (t , "Bearer test-token" , r .Header .Get ("Authorization" ))
519
+
520
+ // Return successful response
521
+ w .WriteHeader (http .StatusOK )
522
+ json .NewEncoder (w ).Encode (types.Infra {
523
+ Status : types.Status {
524
+ State : types .StateSucceeded ,
525
+ Description : "Installation successful" ,
526
+ },
527
+ })
528
+ }))
529
+ defer server .Close ()
530
+
531
+ // Test successful get
532
+ c := New (server .URL , WithToken ("test-token" ))
533
+ infra , err := c .GetKubernetesInfraStatus ()
534
+ assert .NoError (t , err )
535
+ assert .Equal (t , types .StateSucceeded , infra .Status .State )
536
+ assert .Equal (t , "Installation successful" , infra .Status .Description )
537
+
538
+ // Test error response
539
+ errorServer := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
540
+ w .WriteHeader (http .StatusInternalServerError )
541
+ json .NewEncoder (w ).Encode (types.APIError {
542
+ StatusCode : http .StatusInternalServerError ,
543
+ Message : "Internal Server Error" ,
544
+ })
545
+ }))
546
+ defer errorServer .Close ()
547
+
548
+ c = New (errorServer .URL , WithToken ("test-token" ))
549
+ infra , err = c .GetKubernetesInfraStatus ()
550
+ assert .Error (t , err )
551
+ assert .Equal (t , types.Infra {}, infra )
552
+
553
+ apiErr , ok := err .(* types.APIError )
554
+ require .True (t , ok , "Expected err to be of type *types.APIError" )
555
+ assert .Equal (t , http .StatusInternalServerError , apiErr .StatusCode )
556
+ assert .Equal (t , "Internal Server Error" , apiErr .Message )
557
+ }
558
+
456
559
func TestErrorFromResponse (t * testing.T ) {
457
560
// Create a response with an error
458
561
resp := & http.Response {
0 commit comments