diff --git a/tests/ci/cmd_test.go b/tests/ci/cmd_test.go index 77803975..ea76e6de 100644 --- a/tests/ci/cmd_test.go +++ b/tests/ci/cmd_test.go @@ -1,3 +1,85 @@ package ci -// TODO +import ( + "testing" + "time" + + "github.com/fatedier/frp/tests/consts" + "github.com/fatedier/frp/tests/util" + + "github.com/stretchr/testify/assert" +) + +func TestCmdTcp(t *testing.T) { + assert := assert.New(t) + + var err error + s := util.NewProcess(consts.FRPS_BIN_PATH, []string{"-t", "123", "-p", "20000"}) + err = s.Start() + if assert.NoError(err) { + defer s.Stop() + } + time.Sleep(100 * time.Millisecond) + + c := util.NewProcess(consts.FRPC_BIN_PATH, []string{"tcp", "-s", "127.0.0.1:20000", "-t", "123", "-u", "test", + "-l", "10701", "-r", "20801", "-n", "tcp_test"}) + err = c.Start() + if assert.NoError(err) { + defer c.Stop() + } + time.Sleep(250 * time.Millisecond) + + res, err := util.SendTcpMsg("127.0.0.1:20801", consts.TEST_TCP_ECHO_STR) + assert.NoError(err) + assert.Equal(consts.TEST_TCP_ECHO_STR, res) +} + +func TestCmdUdp(t *testing.T) { + assert := assert.New(t) + + var err error + s := util.NewProcess(consts.FRPS_BIN_PATH, []string{"-t", "123", "-p", "20000"}) + err = s.Start() + if assert.NoError(err) { + defer s.Stop() + } + time.Sleep(100 * time.Millisecond) + + c := util.NewProcess(consts.FRPC_BIN_PATH, []string{"udp", "-s", "127.0.0.1:20000", "-t", "123", "-u", "test", + "-l", "10702", "-r", "20802", "-n", "udp_test"}) + err = c.Start() + if assert.NoError(err) { + defer c.Stop() + } + time.Sleep(250 * time.Millisecond) + + res, err := util.SendUdpMsg("127.0.0.1:20802", consts.TEST_UDP_ECHO_STR) + assert.NoError(err) + assert.Equal(consts.TEST_UDP_ECHO_STR, res) +} + +func TestCmdHttp(t *testing.T) { + assert := assert.New(t) + + var err error + s := util.NewProcess(consts.FRPS_BIN_PATH, []string{"-t", "123", "-p", "20000", "--vhost_http_port", "20001"}) + err = s.Start() + if assert.NoError(err) { + defer s.Stop() + } + time.Sleep(100 * time.Millisecond) + + c := util.NewProcess(consts.FRPC_BIN_PATH, []string{"http", "-s", "127.0.0.1:20000", "-t", "123", "-u", "test", + "-n", "udp_test", "-l", "10704", "--custom_domain", "127.0.0.1"}) + err = c.Start() + if assert.NoError(err) { + defer c.Stop() + } + time.Sleep(250 * time.Millisecond) + + code, body, _, err := util.SendHttpMsg("GET", "http://127.0.0.1:20001", "", nil, "") + if assert.NoError(err) { + assert.Equal(200, code) + assert.Equal(consts.TEST_HTTP_NORMAL_STR, body) + } +} diff --git a/tests/ci/reconnect_test.go b/tests/ci/reconnect_test.go index 2378a080..7974c2c7 100644 --- a/tests/ci/reconnect_test.go +++ b/tests/ci/reconnect_test.go @@ -58,7 +58,7 @@ func TestReconnect(t *testing.T) { defer frpsProcess.Stop() } - time.Sleep(200 * time.Millisecond) + time.Sleep(100 * time.Millisecond) frpcProcess := util.NewProcess(consts.FRPC_BIN_PATH, []string{"-c", frpcCfgPath}) err = frpcProcess.Start() diff --git a/tests/ci/reload_test.go b/tests/ci/reload_test.go index 5ba358a3..9811db95 100644 --- a/tests/ci/reload_test.go +++ b/tests/ci/reload_test.go @@ -93,7 +93,7 @@ func TestReload(t *testing.T) { defer frpsProcess.Stop() } - time.Sleep(200 * time.Millisecond) + time.Sleep(100 * time.Millisecond) frpcProcess := util.NewProcess(consts.FRPC_BIN_PATH, []string{"-c", frpcCfgPath}) err = frpcProcess.Start()