@@ -29,6 +29,8 @@ import (
29
29
"strings"
30
30
"testing"
31
31
32
+ "reflect"
33
+
32
34
"k8s.io/apiserver/pkg/server"
33
35
"k8s.io/apiserver/pkg/server/options"
34
36
utilfeature "k8s.io/apiserver/pkg/util/feature"
@@ -352,15 +354,24 @@ users:
352
354
anonymous bool // to use the token or not
353
355
wantErr bool
354
356
wantSecureCode * int
357
+ wantPaths []string
355
358
}{
356
- {"serving /statusz" , []string {
357
- "--authentication-skip-lookup" , // to survive inaccessible extensions-apiserver-authentication configmap
358
- "--authentication-kubeconfig" , apiserverConfig .Name (),
359
- "--authorization-kubeconfig" , apiserverConfig .Name (),
360
- "--authorization-always-allow-paths" , "/statusz" ,
361
- "--kubeconfig" , apiserverConfig .Name (),
362
- "--leader-elect=false" ,
363
- }, "/statusz" , false , false , ptr .To (http .StatusOK )},
359
+ {
360
+ name : "serving /statusz" ,
361
+ flags : []string {
362
+ "--authentication-skip-lookup" , // to survive inaccessible extensions-apiserver-authentication configmap
363
+ "--authentication-kubeconfig" , apiserverConfig .Name (),
364
+ "--authorization-kubeconfig" , apiserverConfig .Name (),
365
+ "--authorization-always-allow-paths" , "/statusz" ,
366
+ "--kubeconfig" , apiserverConfig .Name (),
367
+ "--leader-elect=false" ,
368
+ },
369
+ path : "/statusz" ,
370
+ anonymous : false ,
371
+ wantErr : false ,
372
+ wantSecureCode : ptr .To (http .StatusOK ),
373
+ wantPaths : []string {"/configz" , "/healthz" , "/metrics" },
374
+ },
364
375
}
365
376
for _ , tt := range tests {
366
377
t .Run (tt .name , func (t * testing.T ) {
@@ -416,7 +427,8 @@ users:
416
427
t .Fatalf ("failed to GET %s from component: %v" , tt .path , err )
417
428
}
418
429
419
- if _ , err = io .ReadAll (r .Body ); err != nil {
430
+ body , err := io .ReadAll (r .Body )
431
+ if err != nil {
420
432
t .Fatalf ("failed to read response body: %v" , err )
421
433
}
422
434
defer func () {
@@ -428,6 +440,39 @@ users:
428
440
if got , expected := r .StatusCode , * tt .wantSecureCode ; got != expected {
429
441
t .Fatalf ("expected http %d at %s of component, got: %d" , expected , tt .path , got )
430
442
}
443
+
444
+ bodyStr := string (body )
445
+
446
+ if ! strings .Contains (bodyStr , "Paths" ) {
447
+ t .Error ("response does not contain Paths section" )
448
+ }
449
+
450
+ var foundPathsRaw []string
451
+ for _ , line := range strings .Split (bodyStr , "\n " ) {
452
+ if strings .HasPrefix (line , "Paths" ) {
453
+ parts := strings .Fields (line )
454
+ if len (parts ) > 1 {
455
+ foundPathsRaw = parts [1 :] // Skip "Paths" label
456
+ }
457
+ break
458
+ }
459
+ }
460
+
461
+ expectedPaths := tt .wantPaths
462
+
463
+ foundPathsSet := make (map [string ]struct {})
464
+ for _ , p := range foundPathsRaw {
465
+ foundPathsSet [p ] = struct {}{}
466
+ }
467
+
468
+ expectedPathsSet := make (map [string ]struct {})
469
+ for _ , p := range expectedPaths {
470
+ expectedPathsSet [p ] = struct {}{}
471
+ }
472
+
473
+ if ! reflect .DeepEqual (foundPathsSet , expectedPathsSet ) {
474
+ t .Errorf ("path mismatch:\n - want: %v\n - got: %v" , expectedPaths , foundPathsRaw )
475
+ }
431
476
}
432
477
})
433
478
}
0 commit comments