Files
kt-connect/pkg/kt/connect/inbound_test.go
T
2020-03-12 17:01:58 +08:00

58 lines
1.5 KiB
Go

package connect
import (
"os/exec"
"testing"
"github.com/alibaba/kt-connect/pkg/fake/kt/exec/kubectl"
"github.com/alibaba/kt-connect/pkg/fake/kt/exec/ssh"
"github.com/golang/mock/gomock"
"github.com/alibaba/kt-connect/pkg/kt/options"
"github.com/alibaba/kt-connect/pkg/kt/util"
)
func Test_inbound(t *testing.T) {
ctl := gomock.NewController(t)
type args struct {
exposePort string
podName string
remoteIP string
credential *util.SSHCredential
options *options.DaemonOptions
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "shouldRedirectRequestToLocalHost",
args: args{
exposePort: "8080",
podName: "podName",
remoteIP: "127.0.0.1",
credential: &util.SSHCredential{},
options: options.NewDaemonOptions(),
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
kubectl := kubectl.NewMockCliInterface(ctl)
ssh := ssh.NewMockCliInterface(ctl)
kubectl.EXPECT().PortForward(gomock.Any(), gomock.Any(), gomock.Any()).Return(exec.Command("ls", "-al"))
ssh.EXPECT().ForwardRemoteRequestToLocal(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(exec.Command("ls", "-al"))
if err := inbound(tt.args.exposePort, tt.args.podName, tt.args.remoteIP, tt.args.credential, tt.args.options, kubectl, ssh); (err != nil) != tt.wantErr {
t.Errorf("inbound() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}