@@ -89,7 +89,7 @@ func TestFunctional(t *testing.T) {
89
89
{"LogsCmd" , validateLogsCmd },
90
90
{"MountCmd" , validateMountCmd },
91
91
{"ProfileCmd" , validateProfileCmd },
92
- {"ServicesCmd " , validateServicesCmd },
92
+ {"ServiceCmd " , validateServiceCmd },
93
93
{"AddonsCmd" , validateAddonsCmd },
94
94
{"PersistentVolumeClaim" , validatePersistentVolumeClaim },
95
95
{"TunnelCmd" , validateTunnelCmd },
@@ -397,13 +397,77 @@ func validateProfileCmd(ctx context.Context, t *testing.T, profile string) {
397
397
}
398
398
399
399
// validateServiceCmd asserts basic "service" command functionality
400
- func validateServicesCmd (ctx context.Context , t * testing.T , profile string ) {
401
- rr , err := Run (t , exec .CommandContext (ctx , Target (), "-p" , profile , "service" , "list" ))
400
+ func validateServiceCmd (ctx context.Context , t * testing.T , profile string ) {
401
+ rr , err := Run (t , exec .CommandContext (ctx , "kubectl" , "--context" , profile , "create" , "deployment" , "hello-node" , "--image=gcr.io/hello-minikube-zero-install/hello-node" ))
402
+ if err != nil {
403
+ t .Logf ("%s failed: %v (may not be an error)" , rr .Args , err )
404
+ }
405
+ rr , err = Run (t , exec .CommandContext (ctx , "kubectl" , "--context" , profile , "expose" , "deployment" , "hello-node" , "--type=NodePort" , "--port=8080" ))
406
+ if err != nil {
407
+ t .Logf ("%s failed: %v (may not be an error)" , rr .Args , err )
408
+ }
409
+
410
+ if _ , err := PodWait (ctx , t , profile , "default" , "app=hello-node" , 4 * time .Minute ); err != nil {
411
+ t .Fatalf ("wait: %v" , err )
412
+ }
413
+
414
+ rr , err = Run (t , exec .CommandContext (ctx , Target (), "-p" , profile , "service" , "list" ))
402
415
if err != nil {
403
416
t .Errorf ("%s failed: %v" , rr .Args , err )
404
417
}
405
- if ! strings .Contains (rr .Stdout .String (), "kubernetes" ) {
406
- t .Errorf ("service list got %q, wanted *kubernetes*" , rr .Stdout .String ())
418
+ if ! strings .Contains (rr .Stdout .String (), "hello-node" ) {
419
+ t .Errorf ("service list got %q, wanted *hello-node*" , rr .Stdout .String ())
420
+ }
421
+
422
+ // Test --https --url mode
423
+ rr , err = Run (t , exec .CommandContext (ctx , Target (), "-p" , profile , "service" , "--namespace=default" , "--https" , "--url" , "hello-node" ))
424
+ if err != nil {
425
+ t .Fatalf ("%s failed: %v" , rr .Args , err )
426
+ }
427
+ if rr .Stderr .String () != "" {
428
+ t .Errorf ("unexpected stderr output: %s" , rr .Stderr )
429
+ }
430
+
431
+ endpoint := strings .TrimSpace (rr .Stdout .String ())
432
+ u , err := url .Parse (endpoint )
433
+ if err != nil {
434
+ t .Fatalf ("failed to parse %q: %v" , endpoint , err )
435
+ }
436
+ if u .Scheme != "https" {
437
+ t .Errorf ("got scheme: %q, expected: %q" , u .Scheme , "https" )
438
+ }
439
+
440
+ // Test --format=IP
441
+ rr , err = Run (t , exec .CommandContext (ctx , Target (), "-p" , profile , "service" , "hello-node" , "--url" , "--format={{.IP}}" ))
442
+ if err != nil {
443
+ t .Errorf ("%s failed: %v" , rr .Args , err )
444
+ }
445
+ if strings .TrimSpace (rr .Stdout .String ()) != u .Hostname () {
446
+ t .Errorf ("%s = %q, wanted %q" , rr .Args , rr .Stdout .String (), u .Hostname ())
447
+ }
448
+
449
+ // Test a regular URLminikube
450
+ rr , err = Run (t , exec .CommandContext (ctx , Target (), "-p" , profile , "service" , "hello-node" , "--url" ))
451
+ if err != nil {
452
+ t .Errorf ("%s failed: %v" , rr .Args , err )
453
+ }
454
+
455
+ endpoint = strings .TrimSpace (rr .Stdout .String ())
456
+ u , err = url .Parse (endpoint )
457
+ if err != nil {
458
+ t .Fatalf ("failed to parse %q: %v" , endpoint , err )
459
+ }
460
+ if u .Scheme != "http" {
461
+ t .Fatalf ("got scheme: %q, expected: %q" , u .Scheme , "http" )
462
+ }
463
+
464
+ t .Logf ("url: %s" , endpoint )
465
+ resp , err := retryablehttp .Get (endpoint )
466
+ if err != nil {
467
+ t .Fatalf ("get failed: %v\n resp: %v" , err , resp )
468
+ }
469
+ if resp .StatusCode != http .StatusOK {
470
+ t .Fatalf ("%s = status code %d, want %d" , u , resp .StatusCode , http .StatusOK )
407
471
}
408
472
}
409
473
0 commit comments