mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-24 02:51:33 +00:00
Update unit test.
This commit is contained in:
parent
174b6d0e2f
commit
1eb721248b
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
package kubelet
|
package kubelet
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@ -2095,7 +2094,7 @@ func (f *fakeReadWriteCloser) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExec(t *testing.T) {
|
func TestGetExec(t *testing.T) {
|
||||||
const (
|
const (
|
||||||
podName = "podFoo"
|
podName = "podFoo"
|
||||||
podNamespace = "nsFoo"
|
podNamespace = "nsFoo"
|
||||||
@ -2106,9 +2105,6 @@ func TestExec(t *testing.T) {
|
|||||||
var (
|
var (
|
||||||
podFullName = kubecontainer.GetPodFullName(podWithUIDNameNs(podUID, podName, podNamespace))
|
podFullName = kubecontainer.GetPodFullName(podWithUIDNameNs(podUID, podName, podNamespace))
|
||||||
command = []string{"ls"}
|
command = []string{"ls"}
|
||||||
stdin = &bytes.Buffer{}
|
|
||||||
stdout = &fakeReadWriteCloser{}
|
|
||||||
stderr = &fakeReadWriteCloser{}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
testcases := []struct {
|
testcases := []struct {
|
||||||
@ -2161,22 +2157,16 @@ func TestExec(t *testing.T) {
|
|||||||
assert.NoError(t, err, description)
|
assert.NoError(t, err, description)
|
||||||
assert.Equal(t, containertest.FakeHost, redirect.Host, description+": redirect")
|
assert.Equal(t, containertest.FakeHost, redirect.Host, description+": redirect")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = kubelet.ExecInContainer(tc.podFullName, podUID, tc.container, command, stdin, stdout, stderr, tty, nil, 0)
|
|
||||||
assert.Error(t, err, description)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPortForward(t *testing.T) {
|
func TestGetPortForward(t *testing.T) {
|
||||||
const (
|
const (
|
||||||
podName = "podFoo"
|
podName = "podFoo"
|
||||||
podNamespace = "nsFoo"
|
podNamespace = "nsFoo"
|
||||||
podUID types.UID = "12345678"
|
podUID types.UID = "12345678"
|
||||||
port int32 = 5000
|
port int32 = 5000
|
||||||
)
|
)
|
||||||
var (
|
|
||||||
stream = &fakeReadWriteCloser{}
|
|
||||||
)
|
|
||||||
|
|
||||||
testcases := []struct {
|
testcases := []struct {
|
||||||
description string
|
description string
|
||||||
@ -2208,7 +2198,6 @@ func TestPortForward(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
}
|
}
|
||||||
|
|
||||||
podFullName := kubecontainer.GetPodFullName(podWithUIDNameNs(podUID, tc.podName, podNamespace))
|
|
||||||
description := "streaming - " + tc.description
|
description := "streaming - " + tc.description
|
||||||
fakeRuntime := &containertest.FakeStreamingRuntime{FakeRuntime: testKubelet.fakeRuntime}
|
fakeRuntime := &containertest.FakeStreamingRuntime{FakeRuntime: testKubelet.fakeRuntime}
|
||||||
kubelet.containerRuntime = fakeRuntime
|
kubelet.containerRuntime = fakeRuntime
|
||||||
@ -2221,9 +2210,6 @@ func TestPortForward(t *testing.T) {
|
|||||||
assert.NoError(t, err, description)
|
assert.NoError(t, err, description)
|
||||||
assert.Equal(t, containertest.FakeHost, redirect.Host, description+": redirect")
|
assert.Equal(t, containertest.FakeHost, redirect.Host, description+": redirect")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = kubelet.PortForward(podFullName, podUID, port, stream)
|
|
||||||
assert.Error(t, err, description)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -23,11 +23,13 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
"golang.org/x/net/websocket"
|
"golang.org/x/net/websocket"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
|
"k8s.io/kubernetes/pkg/kubelet/server/portforward"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -36,152 +38,114 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestServeWSPortForward(t *testing.T) {
|
func TestServeWSPortForward(t *testing.T) {
|
||||||
tests := []struct {
|
tests := map[string]struct {
|
||||||
port string
|
port string
|
||||||
uid bool
|
uid bool
|
||||||
clientData string
|
clientData string
|
||||||
containerData string
|
containerData string
|
||||||
shouldError bool
|
shouldError bool
|
||||||
}{
|
}{
|
||||||
{port: "", shouldError: true},
|
"no port": {port: "", shouldError: true},
|
||||||
{port: "abc", shouldError: true},
|
"none number port": {port: "abc", shouldError: true},
|
||||||
{port: "-1", shouldError: true},
|
"negative port": {port: "-1", shouldError: true},
|
||||||
{port: "65536", shouldError: true},
|
"too large port": {port: "65536", shouldError: true},
|
||||||
{port: "0", shouldError: true},
|
"0 port": {port: "0", shouldError: true},
|
||||||
{port: "1", shouldError: false},
|
"min port": {port: "1", shouldError: false},
|
||||||
{port: "8000", shouldError: false},
|
"normal port": {port: "8000", shouldError: false},
|
||||||
{port: "8000", clientData: "client data", containerData: "container data", shouldError: false},
|
"normal port with data forward": {port: "8000", clientData: "client data", containerData: "container data", shouldError: false},
|
||||||
{port: "65535", shouldError: false},
|
"max port": {port: "65535", shouldError: false},
|
||||||
{port: "65535", uid: true, shouldError: false},
|
"normal port with uid": {port: "8000", uid: true, shouldError: false},
|
||||||
}
|
}
|
||||||
|
|
||||||
podNamespace := "other"
|
podNamespace := "other"
|
||||||
podName := "foo"
|
podName := "foo"
|
||||||
expectedPodName := getPodName(podName, podNamespace)
|
|
||||||
expectedUid := "9b01b80f-8fb4-11e4-95ab-4200af06647"
|
|
||||||
|
|
||||||
for i, test := range tests {
|
for desc, test := range tests {
|
||||||
fw := newServerTest()
|
test := test
|
||||||
defer fw.testHTTPServer.Close()
|
t.Run(desc, func(t *testing.T) {
|
||||||
|
ss, err := newTestStreamingServer(0)
|
||||||
|
require.NoError(t, err)
|
||||||
|
defer ss.testHTTPServer.Close()
|
||||||
|
fw := newServerTestWithDebug(true, false, ss)
|
||||||
|
defer fw.testHTTPServer.Close()
|
||||||
|
|
||||||
fw.fakeKubelet.streamingConnectionIdleTimeoutFunc = func() time.Duration {
|
portForwardFuncDone := make(chan struct{})
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
portForwardFuncDone := make(chan struct{})
|
fw.fakeKubelet.getPortForwardCheck = func(name, namespace string, uid types.UID, opts portforward.V4Options) {
|
||||||
|
assert.Equal(t, podName, name, "pod name")
|
||||||
fw.fakeKubelet.portForwardFunc = func(name string, uid types.UID, port int32, stream io.ReadWriteCloser) error {
|
assert.Equal(t, podNamespace, namespace, "pod namespace")
|
||||||
defer close(portForwardFuncDone)
|
if test.uid {
|
||||||
|
assert.Equal(t, testUID, string(uid), "uid")
|
||||||
if e, a := expectedPodName, name; e != a {
|
}
|
||||||
t.Fatalf("%d: pod name: expected '%v', got '%v'", i, e, a)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if e, a := expectedUid, uid; test.uid && e != string(a) {
|
ss.fakeRuntime.portForwardFunc = func(podSandboxID string, port int32, stream io.ReadWriteCloser) error {
|
||||||
t.Fatalf("%d: uid: expected '%v', got '%v'", i, e, a)
|
defer close(portForwardFuncDone)
|
||||||
|
assert.Equal(t, testPodSandboxID, podSandboxID, "pod sandbox id")
|
||||||
|
// The port should be valid if it reaches here.
|
||||||
|
testPort, err := strconv.ParseInt(test.port, 10, 32)
|
||||||
|
require.NoError(t, err, "parse port")
|
||||||
|
assert.Equal(t, int32(testPort), port, "port")
|
||||||
|
|
||||||
|
if test.clientData != "" {
|
||||||
|
fromClient := make([]byte, 32)
|
||||||
|
n, err := stream.Read(fromClient)
|
||||||
|
assert.NoError(t, err, "reading client data")
|
||||||
|
assert.Equal(t, test.clientData, string(fromClient[0:n]), "client data")
|
||||||
|
}
|
||||||
|
|
||||||
|
if test.containerData != "" {
|
||||||
|
_, err := stream.Write([]byte(test.containerData))
|
||||||
|
assert.NoError(t, err, "writing container data")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
p, err := strconv.ParseInt(test.port, 10, 32)
|
var url string
|
||||||
if err != nil {
|
if test.uid {
|
||||||
t.Fatalf("%d: error parsing port string '%s': %v", i, test.port, err)
|
url = fmt.Sprintf("ws://%s/portForward/%s/%s/%s?port=%s", fw.testHTTPServer.Listener.Addr().String(), podNamespace, podName, testUID, test.port)
|
||||||
|
} else {
|
||||||
|
url = fmt.Sprintf("ws://%s/portForward/%s/%s?port=%s", fw.testHTTPServer.Listener.Addr().String(), podNamespace, podName, test.port)
|
||||||
}
|
}
|
||||||
if e, a := int32(p), port; e != a {
|
|
||||||
t.Fatalf("%d: port: expected '%v', got '%v'", i, e, a)
|
ws, err := websocket.Dial(url, "", "http://127.0.0.1/")
|
||||||
|
assert.Equal(t, test.shouldError, err != nil, "websocket dial")
|
||||||
|
if test.shouldError {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
defer ws.Close()
|
||||||
|
|
||||||
|
p, err := strconv.ParseUint(test.port, 10, 16)
|
||||||
|
require.NoError(t, err, "parse port")
|
||||||
|
p16 := uint16(p)
|
||||||
|
|
||||||
|
channel, data, err := wsRead(ws)
|
||||||
|
require.NoError(t, err, "read")
|
||||||
|
assert.Equal(t, dataChannel, int(channel), "channel")
|
||||||
|
assert.Len(t, data, binary.Size(p16), "data size")
|
||||||
|
assert.Equal(t, p16, binary.LittleEndian.Uint16(data), "data")
|
||||||
|
|
||||||
|
channel, data, err = wsRead(ws)
|
||||||
|
assert.NoError(t, err, "read")
|
||||||
|
assert.Equal(t, errorChannel, int(channel), "channel")
|
||||||
|
assert.Len(t, data, binary.Size(p16), "data size")
|
||||||
|
assert.Equal(t, p16, binary.LittleEndian.Uint16(data), "data")
|
||||||
|
|
||||||
if test.clientData != "" {
|
if test.clientData != "" {
|
||||||
fromClient := make([]byte, 32)
|
println("writing the client data")
|
||||||
n, err := stream.Read(fromClient)
|
err := wsWrite(ws, dataChannel, []byte(test.clientData))
|
||||||
if err != nil {
|
assert.NoError(t, err, "writing client data")
|
||||||
t.Fatalf("%d: error reading client data: %v", i, err)
|
|
||||||
}
|
|
||||||
if e, a := test.clientData, string(fromClient[0:n]); e != a {
|
|
||||||
t.Fatalf("%d: client data: expected to receive '%v', got '%v'", i, e, a)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if test.containerData != "" {
|
if test.containerData != "" {
|
||||||
_, err := stream.Write([]byte(test.containerData))
|
_, data, err = wsRead(ws)
|
||||||
if err != nil {
|
assert.NoError(t, err, "reading container data")
|
||||||
t.Fatalf("%d: error writing container data: %v", i, err)
|
assert.Equal(t, test.containerData, string(data), "container data")
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
<-portForwardFuncDone
|
||||||
}
|
})
|
||||||
|
|
||||||
var url string
|
|
||||||
if test.uid {
|
|
||||||
url = fmt.Sprintf("ws://%s/portForward/%s/%s/%s?port=%s", fw.testHTTPServer.Listener.Addr().String(), podNamespace, podName, expectedUid, test.port)
|
|
||||||
} else {
|
|
||||||
url = fmt.Sprintf("ws://%s/portForward/%s/%s?port=%s", fw.testHTTPServer.Listener.Addr().String(), podNamespace, podName, test.port)
|
|
||||||
}
|
|
||||||
|
|
||||||
ws, err := websocket.Dial(url, "", "http://127.0.0.1/")
|
|
||||||
if test.shouldError {
|
|
||||||
if err == nil {
|
|
||||||
t.Fatalf("%d: websocket dial expected err", i)
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
} else if err != nil {
|
|
||||||
t.Fatalf("%d: websocket dial unexpected err: %v", i, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer ws.Close()
|
|
||||||
|
|
||||||
p, err := strconv.ParseUint(test.port, 10, 16)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("%d: error parsing port string '%s': %v", i, test.port, err)
|
|
||||||
}
|
|
||||||
p16 := uint16(p)
|
|
||||||
|
|
||||||
channel, data, err := wsRead(ws)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("%d: read failed: expected no error: got %v", i, err)
|
|
||||||
}
|
|
||||||
if channel != dataChannel {
|
|
||||||
t.Fatalf("%d: wrong channel: got %q: expected %q", i, channel, dataChannel)
|
|
||||||
}
|
|
||||||
if len(data) != binary.Size(p16) {
|
|
||||||
t.Fatalf("%d: wrong data size: got %q: expected %d", i, data, binary.Size(p16))
|
|
||||||
}
|
|
||||||
if e, a := p16, binary.LittleEndian.Uint16(data); e != a {
|
|
||||||
t.Fatalf("%d: wrong data: got %q: expected %s", i, data, test.port)
|
|
||||||
}
|
|
||||||
|
|
||||||
channel, data, err = wsRead(ws)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("%d: read succeeded: expected no error: got %v", i, err)
|
|
||||||
}
|
|
||||||
if channel != errorChannel {
|
|
||||||
t.Fatalf("%d: wrong channel: got %q: expected %q", i, channel, errorChannel)
|
|
||||||
}
|
|
||||||
if len(data) != binary.Size(p16) {
|
|
||||||
t.Fatalf("%d: wrong data size: got %q: expected %d", i, data, binary.Size(p16))
|
|
||||||
}
|
|
||||||
if e, a := p16, binary.LittleEndian.Uint16(data); e != a {
|
|
||||||
t.Fatalf("%d: wrong data: got %q: expected %s", i, data, test.port)
|
|
||||||
}
|
|
||||||
|
|
||||||
if test.clientData != "" {
|
|
||||||
println("writing the client data")
|
|
||||||
err := wsWrite(ws, dataChannel, []byte(test.clientData))
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("%d: unexpected error writing client data: %v", i, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if test.containerData != "" {
|
|
||||||
_, data, err = wsRead(ws)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("%d: unexpected error reading container data: %v", i, err)
|
|
||||||
}
|
|
||||||
if e, a := test.containerData, string(data); e != a {
|
|
||||||
t.Fatalf("%d: expected to receive '%v' from container, got '%v'", i, e, a)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
<-portForwardFuncDone
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,27 +154,27 @@ func TestServeWSMultiplePortForward(t *testing.T) {
|
|||||||
ports := []uint16{7000, 8000, 9000}
|
ports := []uint16{7000, 8000, 9000}
|
||||||
podNamespace := "other"
|
podNamespace := "other"
|
||||||
podName := "foo"
|
podName := "foo"
|
||||||
expectedPodName := getPodName(podName, podNamespace)
|
|
||||||
|
|
||||||
fw := newServerTest()
|
ss, err := newTestStreamingServer(0)
|
||||||
|
require.NoError(t, err)
|
||||||
|
defer ss.testHTTPServer.Close()
|
||||||
|
fw := newServerTestWithDebug(true, false, ss)
|
||||||
defer fw.testHTTPServer.Close()
|
defer fw.testHTTPServer.Close()
|
||||||
|
|
||||||
fw.fakeKubelet.streamingConnectionIdleTimeoutFunc = func() time.Duration {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
portForwardWG := sync.WaitGroup{}
|
portForwardWG := sync.WaitGroup{}
|
||||||
portForwardWG.Add(len(ports))
|
portForwardWG.Add(len(ports))
|
||||||
|
|
||||||
portsMutex := sync.Mutex{}
|
portsMutex := sync.Mutex{}
|
||||||
portsForwarded := map[int32]struct{}{}
|
portsForwarded := map[int32]struct{}{}
|
||||||
|
|
||||||
fw.fakeKubelet.portForwardFunc = func(name string, uid types.UID, port int32, stream io.ReadWriteCloser) error {
|
fw.fakeKubelet.getPortForwardCheck = func(name, namespace string, uid types.UID, opts portforward.V4Options) {
|
||||||
defer portForwardWG.Done()
|
assert.Equal(t, podName, name, "pod name")
|
||||||
|
assert.Equal(t, podNamespace, namespace, "pod namespace")
|
||||||
|
}
|
||||||
|
|
||||||
if e, a := expectedPodName, name; e != a {
|
ss.fakeRuntime.portForwardFunc = func(podSandboxID string, port int32, stream io.ReadWriteCloser) error {
|
||||||
t.Fatalf("%d: pod name: expected '%v', got '%v'", port, e, a)
|
defer portForwardWG.Done()
|
||||||
}
|
assert.Equal(t, testPodSandboxID, podSandboxID, "pod sandbox id")
|
||||||
|
|
||||||
portsMutex.Lock()
|
portsMutex.Lock()
|
||||||
portsForwarded[port] = struct{}{}
|
portsForwarded[port] = struct{}{}
|
||||||
@ -218,17 +182,11 @@ func TestServeWSMultiplePortForward(t *testing.T) {
|
|||||||
|
|
||||||
fromClient := make([]byte, 32)
|
fromClient := make([]byte, 32)
|
||||||
n, err := stream.Read(fromClient)
|
n, err := stream.Read(fromClient)
|
||||||
if err != nil {
|
assert.NoError(t, err, "reading client data")
|
||||||
t.Fatalf("%d: error reading client data: %v", port, err)
|
assert.Equal(t, fmt.Sprintf("client data on port %d", port), string(fromClient[0:n]), "client data")
|
||||||
}
|
|
||||||
if e, a := fmt.Sprintf("client data on port %d", port), string(fromClient[0:n]); e != a {
|
|
||||||
t.Fatalf("%d: client data: expected to receive '%v', got '%v'", port, e, a)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = stream.Write([]byte(fmt.Sprintf("container data on port %d", port)))
|
_, err = stream.Write([]byte(fmt.Sprintf("container data on port %d", port)))
|
||||||
if err != nil {
|
assert.NoError(t, err, "writing container data")
|
||||||
t.Fatalf("%d: error writing container data: %v", port, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -239,70 +197,42 @@ func TestServeWSMultiplePortForward(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ws, err := websocket.Dial(url, "", "http://127.0.0.1/")
|
ws, err := websocket.Dial(url, "", "http://127.0.0.1/")
|
||||||
if err != nil {
|
require.NoError(t, err, "websocket dial")
|
||||||
t.Fatalf("websocket dial unexpected err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer ws.Close()
|
defer ws.Close()
|
||||||
|
|
||||||
for i, port := range ports {
|
for i, port := range ports {
|
||||||
channel, data, err := wsRead(ws)
|
channel, data, err := wsRead(ws)
|
||||||
if err != nil {
|
assert.NoError(t, err, "port %d read", port)
|
||||||
t.Fatalf("%d: read failed: expected no error: got %v", i, err)
|
assert.Equal(t, i*2+dataChannel, int(channel), "port %d channel", port)
|
||||||
}
|
assert.Len(t, data, binary.Size(port), "port %d data size", port)
|
||||||
if int(channel) != i*2+dataChannel {
|
assert.Equal(t, binary.LittleEndian.Uint16(data), port, "port %d data", port)
|
||||||
t.Fatalf("%d: wrong channel: got %q: expected %q", i, channel, i*2+dataChannel)
|
|
||||||
}
|
|
||||||
if len(data) != binary.Size(port) {
|
|
||||||
t.Fatalf("%d: wrong data size: got %q: expected %d", i, data, binary.Size(port))
|
|
||||||
}
|
|
||||||
if e, a := port, binary.LittleEndian.Uint16(data); e != a {
|
|
||||||
t.Fatalf("%d: wrong data: got %q: expected %d", i, data, port)
|
|
||||||
}
|
|
||||||
|
|
||||||
channel, data, err = wsRead(ws)
|
channel, data, err = wsRead(ws)
|
||||||
if err != nil {
|
assert.NoError(t, err, "port %d read", port)
|
||||||
t.Fatalf("%d: read succeeded: expected no error: got %v", i, err)
|
assert.Equal(t, i*2+errorChannel, int(channel), "port %d channel", port)
|
||||||
}
|
assert.Len(t, data, binary.Size(port), "port %d data size", port)
|
||||||
if int(channel) != i*2+errorChannel {
|
assert.Equal(t, binary.LittleEndian.Uint16(data), port, "port %d data", port)
|
||||||
t.Fatalf("%d: wrong channel: got %q: expected %q", i, channel, i*2+errorChannel)
|
|
||||||
}
|
|
||||||
if len(data) != binary.Size(port) {
|
|
||||||
t.Fatalf("%d: wrong data size: got %q: expected %d", i, data, binary.Size(port))
|
|
||||||
}
|
|
||||||
if e, a := port, binary.LittleEndian.Uint16(data); e != a {
|
|
||||||
t.Fatalf("%d: wrong data: got %q: expected %d", i, data, port)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, port := range ports {
|
for i, port := range ports {
|
||||||
println("writing the client data", port)
|
t.Logf("port %d writing the client data", port)
|
||||||
err := wsWrite(ws, byte(i*2+dataChannel), []byte(fmt.Sprintf("client data on port %d", port)))
|
err := wsWrite(ws, byte(i*2+dataChannel), []byte(fmt.Sprintf("client data on port %d", port)))
|
||||||
if err != nil {
|
assert.NoError(t, err, "port %d write client data", port)
|
||||||
t.Fatalf("%d: unexpected error writing client data: %v", i, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
channel, data, err := wsRead(ws)
|
channel, data, err := wsRead(ws)
|
||||||
if err != nil {
|
assert.NoError(t, err, "port %d read container data", port)
|
||||||
t.Fatalf("%d: unexpected error reading container data: %v", i, err)
|
assert.Equal(t, i*2+dataChannel, int(channel), "port %d channel", port)
|
||||||
}
|
assert.Equal(t, fmt.Sprintf("container data on port %d", port), string(data), "port %d container data", port)
|
||||||
|
|
||||||
if int(channel) != i*2+dataChannel {
|
|
||||||
t.Fatalf("%d: wrong channel: got %q: expected %q", port, channel, i*2+dataChannel)
|
|
||||||
}
|
|
||||||
if e, a := fmt.Sprintf("container data on port %d", port), string(data); e != a {
|
|
||||||
t.Fatalf("%d: expected to receive '%v' from container, got '%v'", i, e, a)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
portForwardWG.Wait()
|
portForwardWG.Wait()
|
||||||
|
|
||||||
portsMutex.Lock()
|
portsMutex.Lock()
|
||||||
defer portsMutex.Unlock()
|
defer portsMutex.Unlock()
|
||||||
if len(ports) != len(portsForwarded) {
|
assert.Len(t, portsForwarded, len(ports), "all ports forwarded")
|
||||||
t.Fatalf("expected to forward %d ports; got %v", len(ports), portsForwarded)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func wsWrite(conn *websocket.Conn, channel byte, data []byte) error {
|
func wsWrite(conn *websocket.Conn, channel byte, data []byte) error {
|
||||||
frame := make([]byte, len(data)+1)
|
frame := make([]byte, len(data)+1)
|
||||||
frame[0] = channel
|
frame[0] = channel
|
||||||
|
Loading…
Reference in New Issue
Block a user