Prepare to introduce websockets for exec and portforward
Refactor the code in remotecommand to better represent the structure of what is common between portforward and exec.
This commit is contained in:
@@ -132,7 +132,7 @@ func TestForwardPorts(t *testing.T) {
|
||||
server := httptest.NewServer(fakePortForwardServer(t, testName, test.serverSends, test.clientSends))
|
||||
|
||||
url, _ := url.Parse(server.URL)
|
||||
exec, err := remotecommand.NewExecutor(&restclient.Config{}, "POST", url)
|
||||
exec, err := remotecommand.NewSPDYExecutor(&restclient.Config{}, "POST", url)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -202,7 +202,7 @@ func TestForwardPortsReturnsErrorWhenAllBindsFailed(t *testing.T) {
|
||||
defer server.Close()
|
||||
|
||||
url, _ := url.Parse(server.URL)
|
||||
exec, err := remotecommand.NewExecutor(&restclient.Config{}, "POST", url)
|
||||
exec, err := remotecommand.NewSPDYExecutor(&restclient.Config{}, "POST", url)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@@ -255,7 +255,7 @@ func TestStream(t *testing.T) {
|
||||
conf := &restclient.Config{
|
||||
Host: server.URL,
|
||||
}
|
||||
e, err := remoteclient.NewExecutor(conf, "POST", req.URL())
|
||||
e, err := remoteclient.NewSPDYExecutor(conf, "POST", req.URL())
|
||||
if err != nil {
|
||||
t.Errorf("%s: unexpected error: %v", name, err)
|
||||
continue
|
||||
@@ -352,7 +352,7 @@ func TestDial(t *testing.T) {
|
||||
called = true
|
||||
return rt
|
||||
}
|
||||
exec, err := remoteclient.NewStreamExecutor(upgrader, testFn, "POST", &url.URL{Host: "something.com", Scheme: "https"})
|
||||
exec, err := newStreamExecutor(upgrader, testFn, "POST", &url.URL{Host: "something.com", Scheme: "https"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -368,3 +368,20 @@ func TestDial(t *testing.T) {
|
||||
}
|
||||
_ = protocol
|
||||
}
|
||||
|
||||
// newStreamExecutor upgrades the request so that it supports multiplexed bidirectional
|
||||
// streams. This method takes a stream upgrader and an optional function that is invoked
|
||||
// to wrap the round tripper. This method may be used by clients that are lower level than
|
||||
// Kubernetes clients or need to provide their own upgrade round tripper.
|
||||
func newStreamExecutor(upgrader httpstream.UpgradeRoundTripper, fn func(http.RoundTripper) http.RoundTripper, method string, url *url.URL) (StreamExecutor, error) {
|
||||
rt := http.RoundTripper(upgrader)
|
||||
if fn != nil {
|
||||
rt = fn(rt)
|
||||
}
|
||||
return &streamExecutor{
|
||||
upgrader: upgrader,
|
||||
transport: rt,
|
||||
method: method,
|
||||
url: url,
|
||||
}, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user