Fix test cases that may potentially cause a panic.

Kubernetes-commit: 9e53371ddaaeab4083fde45e43c803071238e686
This commit is contained in:
novahe 2025-03-11 17:41:37 +08:00 committed by Kubernetes Publisher
parent 6056c27674
commit a2c8b5531e
2 changed files with 8 additions and 0 deletions

View File

@ -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")
}()

View File

@ -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)