mirror of
https://github.com/kubernetes/client-go.git
synced 2025-09-08 18:39:16 +00:00
moving for easier cherry-pick
Kubernetes-commit: ae8e580d3a32385797934b4b4d9f190b43f73c40
This commit is contained in:
committed by
Kubernetes Publisher
parent
b6e8438bf5
commit
c594704d12
@@ -815,42 +815,6 @@ func TestWebSocketClient_BadHandshake(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// See (https://github.com/kubernetes/kubernetes/issues/126134).
|
||||
func TestWebSocketClient_HTTPSProxyErrorExpected(t *testing.T) {
|
||||
urlStr := "http://127.0.0.1/never-used" + "?" + "stdin=true" + "&" + "stdout=true"
|
||||
websocketLocation, err := url.Parse(urlStr)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to parse WebSocket server URL: %s", urlStr)
|
||||
}
|
||||
// proxy url with https scheme will trigger websocket dialing error.
|
||||
httpsProxyFunc := func(req *http.Request) (*url.URL, error) { return url.Parse("https://127.0.0.1") }
|
||||
exec, err := NewWebSocketExecutor(&rest.Config{Host: websocketLocation.Host, Proxy: httpsProxyFunc}, "GET", urlStr)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error creating websocket executor: %v", err)
|
||||
}
|
||||
var stdout bytes.Buffer
|
||||
options := &StreamOptions{
|
||||
Stdout: &stdout,
|
||||
}
|
||||
errorChan := make(chan error)
|
||||
go func() {
|
||||
// Start the streaming on the WebSocket "exec" client.
|
||||
errorChan <- exec.StreamWithContext(context.Background(), *options)
|
||||
}()
|
||||
|
||||
select {
|
||||
case <-time.After(wait.ForeverTestTimeout):
|
||||
t.Fatalf("expect stream to be closed after connection is closed.")
|
||||
case err := <-errorChan:
|
||||
if err == nil {
|
||||
t.Errorf("expected error but received none")
|
||||
}
|
||||
if !httpstream.IsHTTPSProxyError(err) {
|
||||
t.Errorf("expected https proxy error, got (%s)", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestWebSocketClient_HeartbeatTimeout tests the heartbeat by forcing a
|
||||
// timeout by setting the ping period greater than the deadline.
|
||||
func TestWebSocketClient_HeartbeatTimeout(t *testing.T) {
|
||||
@@ -1377,3 +1341,39 @@ func createWebSocketStreams(req *http.Request, w http.ResponseWriter, opts *opti
|
||||
|
||||
return wsStreams, nil
|
||||
}
|
||||
|
||||
// See (https://github.com/kubernetes/kubernetes/issues/126134).
|
||||
func TestWebSocketClient_HTTPSProxyErrorExpected(t *testing.T) {
|
||||
urlStr := "http://127.0.0.1/never-used" + "?" + "stdin=true" + "&" + "stdout=true"
|
||||
websocketLocation, err := url.Parse(urlStr)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to parse WebSocket server URL: %s", urlStr)
|
||||
}
|
||||
// proxy url with https scheme will trigger websocket dialing error.
|
||||
httpsProxyFunc := func(req *http.Request) (*url.URL, error) { return url.Parse("https://127.0.0.1") }
|
||||
exec, err := NewWebSocketExecutor(&rest.Config{Host: websocketLocation.Host, Proxy: httpsProxyFunc}, "GET", urlStr)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error creating websocket executor: %v", err)
|
||||
}
|
||||
var stdout bytes.Buffer
|
||||
options := &StreamOptions{
|
||||
Stdout: &stdout,
|
||||
}
|
||||
errorChan := make(chan error)
|
||||
go func() {
|
||||
// Start the streaming on the WebSocket "exec" client.
|
||||
errorChan <- exec.StreamWithContext(context.Background(), *options)
|
||||
}()
|
||||
|
||||
select {
|
||||
case <-time.After(wait.ForeverTestTimeout):
|
||||
t.Fatalf("expect stream to be closed after connection is closed.")
|
||||
case err := <-errorChan:
|
||||
if err == nil {
|
||||
t.Errorf("expected error but received none")
|
||||
}
|
||||
if !httpstream.IsHTTPSProxyError(err) {
|
||||
t.Errorf("expected https proxy error, got (%s)", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user