mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-10-31 02:08:13 +00:00 
			
		
		
		
	Fix test cases that may potentially cause a panic.
This commit is contained in:
		| @@ -124,6 +124,7 @@ func fakeServer(t *testing.T, requestReceived chan struct{}, testName string, ex | ||||
| 		opts, err := remotecommand.NewOptions(req) | ||||
| 		if err != nil { | ||||
| 			t.Errorf("unexpected error %v", err) | ||||
| 			return | ||||
| 		} | ||||
| 		if exec { | ||||
| 			cmd := req.URL.Query()[api.ExecCommandParam] | ||||
|   | ||||
| @@ -202,10 +202,12 @@ func TestWithAuditConcurrency(t *testing.T) { | ||||
| 			mutator, ok := handler.(MutationInterface) | ||||
| 			if !ok { | ||||
| 				t.Error("handler is not an interface of type MutationInterface") | ||||
| 				return | ||||
| 			} | ||||
| 			auditMutator, ok := auditHandler.(MutationInterface) | ||||
| 			if !ok { | ||||
| 				t.Error("handler is not an interface of type MutationInterface") | ||||
| 				return | ||||
| 			} | ||||
| 			assert.Equal(t, mutator.Admit(ctx, a, nil), auditMutator.Admit(ctx, a, nil), "WithAudit decorator should not effect the return value") | ||||
| 		}() | ||||
|   | ||||
| @@ -59,11 +59,13 @@ func TestTunnelingHandler_UpgradeStreamingAndTunneling(t *testing.T) { | ||||
| 		_, err := httpstream.Handshake(req, w, []string{constants.PortForwardV1Name}) | ||||
| 		if err != nil { | ||||
| 			t.Errorf("unexpected error %v", err) | ||||
| 			return | ||||
| 		} | ||||
| 		upgrader := spdy.NewResponseUpgrader() | ||||
| 		conn := upgrader.UpgradeResponse(w, req, justQueueStream(streamChan)) | ||||
| 		if conn == nil { | ||||
| 			t.Error("connect is unexpected nil") | ||||
| 			return | ||||
| 		} | ||||
| 		defer conn.Close() //nolint:errcheck | ||||
| 		<-stopServerChan | ||||
| @@ -103,10 +105,12 @@ func TestTunnelingHandler_UpgradeStreamingAndTunneling(t *testing.T) { | ||||
| 		clientStream, err := spdyClient.CreateStream(http.Header{}) | ||||
| 		if err != nil { | ||||
| 			t.Errorf("unexpected error %v", err) | ||||
| 			return | ||||
| 		} | ||||
| 		_, err = io.Copy(clientStream, bytes.NewReader(randomData)) | ||||
| 		if err != nil { | ||||
| 			t.Errorf("unexpected error %v", err) | ||||
| 			return | ||||
| 		} | ||||
| 		clientStream.Close() //nolint:errcheck | ||||
| 	}() | ||||
| @@ -179,6 +183,7 @@ func TestTunnelingHandler_BadHandshakeError(t *testing.T) { | ||||
| 		_, err := httpstream.Handshake(req, w, []string{constants.PortForwardV1Name}) | ||||
| 		if err == nil { | ||||
| 			t.Errorf("handshake should have returned an error %v", err) | ||||
| 			return | ||||
| 		} | ||||
| 		assert.ErrorContains(t, err, "unable to negotiate protocol") | ||||
| 		w.WriteHeader(http.StatusForbidden) | ||||
| @@ -235,6 +240,7 @@ func TestTunnelingHandler_UpstreamSPDYServerErrorPropagated(t *testing.T) { | ||||
| 			_, err := httpstream.Handshake(req, w, []string{constants.PortForwardV1Name}) | ||||
| 			if err != nil { | ||||
| 				t.Errorf("handshake should have succeeded %v", err) | ||||
| 				return | ||||
| 			} | ||||
| 			// Returned status code should be incremented in metrics. | ||||
| 			w.WriteHeader(statusCode) | ||||
|   | ||||
| @@ -352,6 +352,7 @@ func TestCachedDiscoveryClientUnaggregatedServerGroups(t *testing.T) { | ||||
| 			output, err := json.Marshal(body) | ||||
| 			if err != nil { | ||||
| 				t.Errorf("unexpected error %v", err) | ||||
| 				return | ||||
| 			} | ||||
| 			// Content-type is "unaggregated" discovery format -- no resources returned. | ||||
| 			w.Header().Set("Content-Type", discovery.AcceptV1) | ||||
|   | ||||
| @@ -589,6 +589,7 @@ func TestMemCacheGroupsAndMaybeResources(t *testing.T) { | ||||
| 			output, err := json.Marshal(body) | ||||
| 			if err != nil { | ||||
| 				t.Errorf("unexpected error %v", err) | ||||
| 				return | ||||
| 			} | ||||
| 			// Content-type is "unaggregated" discovery format -- no resources returned. | ||||
| 			w.Header().Set("Content-Type", discovery.AcceptV1) | ||||
| @@ -1120,6 +1121,7 @@ func TestAggregatedMemCacheGroupsAndMaybeResources(t *testing.T) { | ||||
| 			output, err := json.Marshal(agg) | ||||
| 			if err != nil { | ||||
| 				t.Errorf("unexpected error %v", err) | ||||
| 				return | ||||
| 			} | ||||
| 			// Content-type is "aggregated" discovery format. | ||||
| 			w.Header().Set("Content-Type", discovery.AcceptV2) | ||||
| @@ -1420,6 +1422,7 @@ func TestMemCacheAggregatedServerGroups(t *testing.T) { | ||||
| 			output, err := json.Marshal(agg) | ||||
| 			if err != nil { | ||||
| 				t.Errorf("unexpected error %v", err) | ||||
| 				return | ||||
| 			} | ||||
| 			// Content-type is "aggregated" discovery format. | ||||
| 			w.Header().Set("Content-Type", discovery.AcceptV2Beta1) | ||||
|   | ||||
| @@ -1325,6 +1325,7 @@ func TestAggregatedServerGroups(t *testing.T) { | ||||
| 			output, err = json.Marshal(agg) | ||||
| 			if err != nil { | ||||
| 				t.Errorf("unexpected error %v", err) | ||||
| 				return | ||||
| 			} | ||||
| 			// Content-Type is "aggregated" discovery format. Add extra parameter | ||||
| 			// to ensure we are resilient to these extra parameters. | ||||
| @@ -1333,6 +1334,7 @@ func TestAggregatedServerGroups(t *testing.T) { | ||||
| 			_, err = w.Write(output) | ||||
| 			if err != nil { | ||||
| 				t.Errorf("unexpected error %v", err) | ||||
| 				return | ||||
| 			} | ||||
| 		})) | ||||
| 		defer server.Close() | ||||
| @@ -2399,6 +2401,7 @@ func TestAggregatedServerGroupsAndResources(t *testing.T) { | ||||
| 					output, err = json.Marshal(agg) | ||||
| 					if err != nil { | ||||
| 						t.Errorf("unexpected error %v", err) | ||||
| 						return | ||||
| 					} | ||||
| 				} else { | ||||
| 					var agg *apidiscoveryv2beta1.APIGroupDiscoveryList | ||||
| @@ -2414,6 +2417,7 @@ func TestAggregatedServerGroupsAndResources(t *testing.T) { | ||||
| 					output, err = json.Marshal(&agg) | ||||
| 					if err != nil { | ||||
| 						t.Errorf("unexpected error %v", err) | ||||
| 						return | ||||
| 					} | ||||
| 				} | ||||
| 				// Content-Type is "aggregated" discovery format. Add extra parameter | ||||
| @@ -2565,6 +2569,7 @@ func TestAggregatedServerGroupsAndResourcesWithErrors(t *testing.T) { | ||||
| 			output, err = json.Marshal(agg) | ||||
| 			if err != nil { | ||||
| 				t.Errorf("unexpected error %v", err) | ||||
| 				return | ||||
| 			} | ||||
| 			// Content-Type is "aggregated" discovery format. Add extra parameter | ||||
| 			// to ensure we are resilient to these extra parameters. | ||||
| @@ -3182,6 +3187,7 @@ func TestAggregatedServerPreferredResources(t *testing.T) { | ||||
| 			output, err = json.Marshal(agg) | ||||
| 			if err != nil { | ||||
| 				t.Errorf("unexpected error %v", err) | ||||
| 				return | ||||
| 			} | ||||
| 			// Content-Type is "aggregated" discovery format. Add extra parameter | ||||
| 			// to ensure we are resilient to these extra parameters. | ||||
|   | ||||
| @@ -53,15 +53,18 @@ func TestTunnelingConnection_ReadWriteClose(t *testing.T) { | ||||
| 		conn, err := upgrader.Upgrade(w, req, nil) | ||||
| 		if err != nil { | ||||
| 			t.Errorf("unexpected error %v", err) | ||||
| 			return | ||||
| 		} | ||||
| 		defer conn.Close() //nolint:errcheck | ||||
| 		if conn.Subprotocol() != constants.WebsocketsSPDYTunnelingPortForwardV1 { | ||||
| 			t.Errorf("Not acceptable agreement Subprotocol: %v", conn.Subprotocol()) | ||||
| 			return | ||||
| 		} | ||||
| 		tunnelingConn := NewTunnelingConnection("server", conn) | ||||
| 		spdyConn, err := spdy.NewServerConnection(tunnelingConn, justQueueStream(streamChan)) | ||||
| 		if err != nil { | ||||
| 			t.Errorf("unexpected error %v", err) | ||||
| 			return | ||||
| 		} | ||||
| 		defer spdyConn.Close() //nolint:errcheck | ||||
| 		<-stopServerChan | ||||
| @@ -85,10 +88,12 @@ func TestTunnelingConnection_ReadWriteClose(t *testing.T) { | ||||
| 		clientStream, err := spdyClient.CreateStream(http.Header{}) | ||||
| 		if err != nil { | ||||
| 			t.Errorf("unexpected error %v", err) | ||||
| 			return | ||||
| 		} | ||||
| 		_, err = io.Copy(clientStream, strings.NewReader(expected)) | ||||
| 		if err != nil { | ||||
| 			t.Errorf("unexpected error %v", err) | ||||
| 			return | ||||
| 		} | ||||
| 		clientStream.Close() //nolint:errcheck | ||||
| 	}() | ||||
| @@ -114,6 +119,7 @@ func TestTunnelingConnection_LocalRemoteAddress(t *testing.T) { | ||||
| 		conn, err := upgrader.Upgrade(w, req, nil) | ||||
| 		if err != nil { | ||||
| 			t.Errorf("unexpected error %v", err) | ||||
| 			return | ||||
| 		} | ||||
| 		defer conn.Close() //nolint:errcheck | ||||
| 		if conn.Subprotocol() != constants.WebsocketsSPDYTunnelingPortForwardV1 { | ||||
| @@ -150,10 +156,12 @@ func TestTunnelingConnection_ReadWriteDeadlines(t *testing.T) { | ||||
| 		conn, err := upgrader.Upgrade(w, req, nil) | ||||
| 		if err != nil { | ||||
| 			t.Errorf("unexpected error %v", err) | ||||
| 			return | ||||
| 		} | ||||
| 		defer conn.Close() //nolint:errcheck | ||||
| 		if conn.Subprotocol() != constants.WebsocketsSPDYTunnelingPortForwardV1 { | ||||
| 			t.Errorf("Not acceptable agreement Subprotocol: %v", conn.Subprotocol()) | ||||
| 			return | ||||
| 		} | ||||
| 		<-stopServerChan | ||||
| 	})) | ||||
|   | ||||
| @@ -115,15 +115,18 @@ func TestWebSocketRoundTripper_RoundTripperFails(t *testing.T) { | ||||
| 					statusBytes, err := runtime.Encode(encoder, testCase.status) | ||||
| 					if err != nil { | ||||
| 						t.Errorf("unexpected error %v", err) | ||||
| 						return | ||||
| 					} | ||||
| 					_, err = w.Write(statusBytes) | ||||
| 					if err != nil { | ||||
| 						t.Errorf("unexpected error %v", err) | ||||
| 						return | ||||
| 					} | ||||
| 				} else if len(testCase.body) > 0 { | ||||
| 					_, err := w.Write([]byte(testCase.body)) | ||||
| 					if err != nil { | ||||
| 						t.Errorf("unexpected error %v", err) | ||||
| 						return | ||||
| 					} | ||||
| 				} | ||||
| 			})) | ||||
|   | ||||
| @@ -395,16 +395,19 @@ func TestV2Beta1Skew(t *testing.T) { | ||||
| 		err := apidiscoveryv2scheme.Convertv2APIGroupDiscoveryListTov2beta1APIGroupDiscoveryList(&apiGroup, &v2b, nil) | ||||
| 		if err != nil { | ||||
| 			t.Errorf("unexpected error %v", err) | ||||
| 			return | ||||
| 		} | ||||
| 		converted, err := json.Marshal(v2b) | ||||
| 		if err != nil { | ||||
| 			t.Errorf("unexpected error %v", err) | ||||
| 			return | ||||
| 		} | ||||
| 		w.Header().Set("Content-Type", "application/json;"+"g=apidiscovery.k8s.io;v=v2beta1;as=APIGroupDiscoveryList") | ||||
| 		w.WriteHeader(200) | ||||
| 		_, err = w.Write(converted) | ||||
| 		if err != nil { | ||||
| 			t.Errorf("unexpected error %v", err) | ||||
| 			return | ||||
| 		} | ||||
| 	})) | ||||
| 	testCtx, cancel := context.WithCancel(context.Background()) | ||||
|   | ||||
| @@ -350,6 +350,7 @@ func runRemoteCommandTest(t *testing.T, commandType string) { | ||||
| 		exec, err := remotecommand.NewSPDYExecutor(&restclient.Config{}, "POST", reqURL) | ||||
| 		if err != nil { | ||||
| 			t.Errorf("unexpected error %v", err) | ||||
| 			return | ||||
| 		} | ||||
|  | ||||
| 		opts := remotecommand.StreamOptions{ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 novahe
					novahe