@@ -36,65 +36,66 @@ import (
3636func TestCanaryRoute (t * testing.T ) {
3737 kubeConfig , err := config .GetConfig ()
3838 if err != nil {
39- t .Fatalf ("failed to get kube config: %v" , err )
39+ t .Fatalf ("Failed to get kube config: %v" , err )
4040 }
4141
4242 client , err := kubernetes .NewForConfig (kubeConfig )
4343 if err != nil {
44- t .Fatalf ("failed to create kube client: %v" , err )
44+ t .Fatalf ("Failed to create kube client: %v" , err )
4545 }
4646
47- // check that the default ingress controller is ready.
47+ t . Log ( "Checking that the default ingresscontroller is ready..." )
4848 def := & operatorv1.IngressController {}
4949 if err := waitForIngressControllerCondition (t , kclient , 5 * time .Minute , defaultName , defaultAvailableConditions ... ); err != nil {
50- t .Fatalf ("failed to observe expected conditions: %v" , err )
50+ t .Fatalf ("Failed to observe expected conditions: %v" , err )
5151 }
5252
5353 if err := kclient .Get (context .TODO (), defaultName , def ); err != nil {
54- t .Fatalf ("failed to get default ingresscontroller: %v" , err )
54+ t .Fatalf ("Failed to get the default ingresscontroller: %v" , err )
5555 }
5656
57- // Get default ingress controller deployment.
57+ t . Log ( "Getting the default ingresscontroller deployment..." )
5858 deployment := & appsv1.Deployment {}
5959 if err := kclient .Get (context .TODO (), controller .RouterDeploymentName (def ), deployment ); err != nil {
60- t .Fatalf ("failed to get ingresscontroller deployment: %v" , err )
60+ t .Fatalf ("Failed to get the router deployment: %v" , err )
6161 }
6262
63- // Get canary route.
63+ t . Log ( "Getting the canary route..." )
6464 canaryRoute := & routev1.Route {}
6565 name := controller .CanaryRouteName ()
6666 err = wait .PollImmediate (1 * time .Second , 1 * time .Minute , func () (bool , error ) {
6767 if err := kclient .Get (context .TODO (), name , canaryRoute ); err != nil {
68- t .Logf ("failed to get canary route %s: %v" , name , err )
68+ t .Logf ("Failed to get route %s: %v" , name , err )
6969 return false , nil
7070 }
7171
7272 return true , nil
7373 })
7474 if err != nil {
75- t .Fatalf ("failed to observe canary route: %v" , err )
75+ t .Fatalf ("Failed to observe canary route: %v" , err )
7676 }
7777
7878 canaryRouteHost := getRouteHost (canaryRoute , defaultName .Name )
7979 if canaryRouteHost == "" {
80- t .Fatalf ("failed to find host name for the %q router in route %s/%s : %# v" , defaultName .Name , name . Namespace , name . Name , canaryRoute )
80+ t .Fatalf ("Failed to find host name for the %q router in route %s: %+ v" , defaultName .Name , name , canaryRoute )
8181 }
8282
8383 image := deployment .Spec .Template .Spec .Containers [0 ].Image
8484 clientPod := buildCanaryCurlPod ("canary-route-check" , canaryRoute .Namespace , image , canaryRouteHost )
8585 if err := kclient .Create (context .TODO (), clientPod ); err != nil {
86- t .Fatalf ("failed to create pod %s/%s: %v" , clientPod .Namespace , clientPod .Name , err )
86+ t .Fatalf ("Failed to create pod %s/%s: %v" , clientPod .Namespace , clientPod .Name , err )
8787 }
8888 t .Cleanup (func () {
8989 if err := kclient .Delete (context .TODO (), clientPod ); err != nil {
9090 if errors .IsNotFound (err ) {
9191 return
9292 }
93- t .Errorf ("failed to delete pod %s/%s: %v" , clientPod .Namespace , clientPod .Name , err )
93+ t .Errorf ("Failed to delete pod %s/%s: %v" , clientPod .Namespace , clientPod .Name , err )
9494 }
9595 })
9696
97- // Test canary route and verify that the hello-openshift echo pod is running properly.
97+ t .Log ("Curl the canary route and verify that it sends the expected response..." )
98+ var lines []string
9899 err = wait .PollImmediate (1 * time .Second , 5 * time .Minute , func () (bool , error ) {
99100 readCloser , err := client .CoreV1 ().Pods (clientPod .Namespace ).GetLogs (clientPod .Name , & corev1.PodLogOptions {
100101 Container : "curl" ,
@@ -103,14 +104,17 @@ func TestCanaryRoute(t *testing.T) {
103104 if err != nil {
104105 return false , nil
105106 }
107+
106108 scanner := bufio .NewScanner (readCloser )
107- t . Cleanup ( func () {
109+ defer func () {
108110 if err := readCloser .Close (); err != nil {
109- t .Errorf ("failed to close reader for pod %s: %v" , clientPod .Name , err )
111+ t .Errorf ("Failed to close reader for logs from pod %s/%s : %v" , clientPod . Namespace , clientPod .Name , err )
110112 }
111- })
113+ }()
114+
112115 foundBody := false
113116 foundRequestPortHeader := false
117+ lines = []string {}
114118 for scanner .Scan () {
115119 line := scanner .Text ()
116120 if strings .Contains (line , canarycontroller .CanaryHealthcheckResponse ) {
@@ -119,14 +123,19 @@ func TestCanaryRoute(t *testing.T) {
119123 if strings .Contains (strings .ToLower (line ), "x-request-port:" ) {
120124 foundRequestPortHeader = true
121125 }
122- if foundBody && foundRequestPortHeader {
123- return true , nil
124- }
126+ lines = append (lines , line )
125127 }
128+
129+ if foundBody && foundRequestPortHeader {
130+ return true , nil
131+ }
132+
126133 return false , nil
127134 })
128135 if err != nil {
129- t .Fatalf ("failed to observe the expected canary response body: %v" , err )
136+ t .Logf ("Got pods logs:\n %s" , strings .Join (lines , "\n " ))
137+
138+ t .Fatalf ("Failed to observe the expected canary response body: %v" , err )
130139 }
131140}
132141
0 commit comments