mirror of
https://github.com/kubernetes/client-go.git
synced 2025-06-26 23:17:34 +00:00
fix wrong assertion on tests
Signed-off-by: xin.li <xin.li@daocloud.io> Kubernetes-commit: bc4ae15d77beab23f321bf6547f82c04ba27c3fa
This commit is contained in:
parent
8fa90a0728
commit
d8b34c3ab2
@ -350,7 +350,9 @@ func TestCachedDiscoveryClientUnaggregatedServerGroups(t *testing.T) {
|
||||
return
|
||||
}
|
||||
output, err := json.Marshal(body)
|
||||
require.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
// Content-type is "unaggregated" discovery format -- no resources returned.
|
||||
w.Header().Set("Content-Type", discovery.AcceptV1)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
@ -587,7 +587,9 @@ func TestMemCacheGroupsAndMaybeResources(t *testing.T) {
|
||||
return
|
||||
}
|
||||
output, err := json.Marshal(body)
|
||||
require.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
// Content-type is "unaggregated" discovery format -- no resources returned.
|
||||
w.Header().Set("Content-Type", discovery.AcceptV1)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
@ -1116,7 +1118,9 @@ func TestAggregatedMemCacheGroupsAndMaybeResources(t *testing.T) {
|
||||
return
|
||||
}
|
||||
output, err := json.Marshal(agg)
|
||||
require.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
// Content-type is "aggregated" discovery format.
|
||||
w.Header().Set("Content-Type", discovery.AcceptV2)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
@ -1414,7 +1418,9 @@ func TestMemCacheAggregatedServerGroups(t *testing.T) {
|
||||
return
|
||||
}
|
||||
output, err := json.Marshal(agg)
|
||||
require.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
// Content-type is "aggregated" discovery format.
|
||||
w.Header().Set("Content-Type", discovery.AcceptV2Beta1)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
@ -60,7 +60,9 @@ func TestGetServerVersion(t *testing.T) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, err = w.Write(output)
|
||||
require.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
}))
|
||||
defer server.Close()
|
||||
client := NewDiscoveryClientForConfigOrDie(&restclient.Config{Host: server.URL})
|
||||
@ -107,7 +109,9 @@ func TestGetServerGroupsWithV1Server(t *testing.T) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, err = w.Write(output)
|
||||
require.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
}))
|
||||
defer server.Close()
|
||||
client := NewDiscoveryClientForConfigOrDie(&restclient.Config{Host: server.URL})
|
||||
@ -148,7 +152,9 @@ func TestDiscoveryToleratesMissingCoreGroup(t *testing.T) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, err = w.Write(output)
|
||||
require.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
}))
|
||||
defer server.Close()
|
||||
client := NewDiscoveryClientForConfigOrDie(&restclient.Config{Host: server.URL})
|
||||
@ -185,7 +191,9 @@ func TestDiscoveryFailsWhenNonCoreGroupsMissing(t *testing.T) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, err = w.Write(output)
|
||||
require.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
}))
|
||||
defer server.Close()
|
||||
client := NewDiscoveryClientForConfigOrDie(&restclient.Config{Host: server.URL})
|
||||
@ -386,7 +394,9 @@ func TestGetServerResourcesForGroupVersion(t *testing.T) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, err = w.Write(output)
|
||||
require.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
}))
|
||||
defer server.Close()
|
||||
for _, test := range tests {
|
||||
@ -1313,13 +1323,17 @@ func TestAggregatedServerGroups(t *testing.T) {
|
||||
return
|
||||
}
|
||||
output, err = json.Marshal(agg)
|
||||
require.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
// Content-Type is "aggregated" discovery format. Add extra parameter
|
||||
// to ensure we are resilient to these extra parameters.
|
||||
w.Header().Set("Content-Type", AcceptV2+"; charset=utf-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, err = w.Write(output)
|
||||
require.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
}))
|
||||
defer server.Close()
|
||||
client := NewDiscoveryClientForConfigOrDie(&restclient.Config{Host: server.URL})
|
||||
@ -2383,7 +2397,9 @@ func TestAggregatedServerGroupsAndResources(t *testing.T) {
|
||||
return
|
||||
}
|
||||
output, err = json.Marshal(agg)
|
||||
require.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
} else {
|
||||
var agg *apidiscoveryv2beta1.APIGroupDiscoveryList
|
||||
switch req.URL.Path {
|
||||
@ -2396,14 +2412,18 @@ func TestAggregatedServerGroupsAndResources(t *testing.T) {
|
||||
return
|
||||
}
|
||||
output, err = json.Marshal(&agg)
|
||||
require.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
}
|
||||
// Content-Type is "aggregated" discovery format. Add extra parameter
|
||||
// to ensure we are resilient to these extra parameters.
|
||||
w.Header().Set("Content-Type", accept+"; charset=utf-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, err = w.Write(output)
|
||||
require.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
|
||||
}))
|
||||
defer server.Close()
|
||||
@ -2543,13 +2563,17 @@ func TestAggregatedServerGroupsAndResourcesWithErrors(t *testing.T) {
|
||||
return
|
||||
}
|
||||
output, err = json.Marshal(agg)
|
||||
require.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
// Content-Type is "aggregated" discovery format. Add extra parameter
|
||||
// to ensure we are resilient to these extra parameters.
|
||||
w.Header().Set("Content-Type", AcceptV2+"; charset=utf-8")
|
||||
w.WriteHeader(status)
|
||||
_, err = w.Write(output)
|
||||
require.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
@ -3156,13 +3180,17 @@ func TestAggregatedServerPreferredResources(t *testing.T) {
|
||||
return
|
||||
}
|
||||
output, err = json.Marshal(agg)
|
||||
require.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
// Content-Type is "aggregated" discovery format. Add extra parameter
|
||||
// to ensure we are resilient to these extra parameters.
|
||||
w.Header().Set("Content-Type", AcceptV2+"; charset=utf-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, err = w.Write(output)
|
||||
require.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
}))
|
||||
defer server.Close()
|
||||
client := NewDiscoveryClientForConfigOrDie(&restclient.Config{Host: server.URL})
|
||||
|
@ -51,12 +51,18 @@ func TestTunnelingConnection_ReadWriteClose(t *testing.T) {
|
||||
Subprotocols: []string{constants.WebsocketsSPDYTunnelingPortForwardV1},
|
||||
}
|
||||
conn, err := upgrader.Upgrade(w, req, nil)
|
||||
require.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
defer conn.Close() //nolint:errcheck
|
||||
require.Equal(t, constants.WebsocketsSPDYTunnelingPortForwardV1, conn.Subprotocol())
|
||||
if conn.Subprotocol() != constants.WebsocketsSPDYTunnelingPortForwardV1 {
|
||||
t.Errorf("Not acceptable agreement Subprotocol: %v", conn.Subprotocol())
|
||||
}
|
||||
tunnelingConn := NewTunnelingConnection("server", conn)
|
||||
spdyConn, err := spdy.NewServerConnection(tunnelingConn, justQueueStream(streamChan))
|
||||
require.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
defer spdyConn.Close() //nolint:errcheck
|
||||
<-stopServerChan
|
||||
}))
|
||||
@ -77,9 +83,13 @@ func TestTunnelingConnection_ReadWriteClose(t *testing.T) {
|
||||
var actual []byte
|
||||
go func() {
|
||||
clientStream, err := spdyClient.CreateStream(http.Header{})
|
||||
require.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
_, err = io.Copy(clientStream, strings.NewReader(expected))
|
||||
require.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
clientStream.Close() //nolint:errcheck
|
||||
}()
|
||||
select {
|
||||
@ -102,9 +112,13 @@ func TestTunnelingConnection_LocalRemoteAddress(t *testing.T) {
|
||||
Subprotocols: []string{constants.WebsocketsSPDYTunnelingPortForwardV1},
|
||||
}
|
||||
conn, err := upgrader.Upgrade(w, req, nil)
|
||||
require.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
defer conn.Close() //nolint:errcheck
|
||||
require.Equal(t, constants.WebsocketsSPDYTunnelingPortForwardV1, conn.Subprotocol())
|
||||
if conn.Subprotocol() != constants.WebsocketsSPDYTunnelingPortForwardV1 {
|
||||
t.Errorf("Not acceptable agreement Subprotocol: %v", conn.Subprotocol())
|
||||
}
|
||||
<-stopServerChan
|
||||
}))
|
||||
defer tunnelingServer.Close()
|
||||
@ -134,9 +148,13 @@ func TestTunnelingConnection_ReadWriteDeadlines(t *testing.T) {
|
||||
Subprotocols: []string{constants.WebsocketsSPDYTunnelingPortForwardV1},
|
||||
}
|
||||
conn, err := upgrader.Upgrade(w, req, nil)
|
||||
require.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
defer conn.Close() //nolint:errcheck
|
||||
require.Equal(t, constants.WebsocketsSPDYTunnelingPortForwardV1, conn.Subprotocol())
|
||||
if conn.Subprotocol() != constants.WebsocketsSPDYTunnelingPortForwardV1 {
|
||||
t.Errorf("Not acceptable agreement Subprotocol: %v", conn.Subprotocol())
|
||||
}
|
||||
<-stopServerChan
|
||||
}))
|
||||
defer tunnelingServer.Close()
|
||||
|
@ -49,7 +49,9 @@ func TestFallbackClient_WebSocketPrimarySucceeds(t *testing.T) {
|
||||
defer conns.conn.Close()
|
||||
// Loopback the STDIN stream onto the STDOUT stream.
|
||||
_, err = io.Copy(conns.stdoutStream, conns.stdinStream)
|
||||
require.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
}))
|
||||
defer websocketServer.Close()
|
||||
|
||||
@ -180,7 +182,9 @@ func TestFallbackClient_PrimaryAndSecondaryFail(t *testing.T) {
|
||||
defer conns.conn.Close()
|
||||
// Loopback the STDIN stream onto the STDOUT stream.
|
||||
_, err = io.Copy(conns.stdoutStream, conns.stdinStream)
|
||||
require.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
}))
|
||||
defer websocketServer.Close()
|
||||
|
||||
|
@ -113,12 +113,18 @@ func TestWebSocketRoundTripper_RoundTripperFails(t *testing.T) {
|
||||
}
|
||||
if testCase.status != nil {
|
||||
statusBytes, err := runtime.Encode(encoder, testCase.status)
|
||||
require.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
_, err = w.Write(statusBytes)
|
||||
require.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
} else if len(testCase.body) > 0 {
|
||||
_, err := w.Write([]byte(testCase.body))
|
||||
require.NoError(t, err)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
}
|
||||
}))
|
||||
defer websocketServer.Close()
|
||||
|
Loading…
Reference in New Issue
Block a user