add more cmd test

This commit is contained in:
fatedier 2018-07-12 16:49:16 +08:00
parent 57417c83ae
commit cc6486addb
3 changed files with 85 additions and 3 deletions

View File

@ -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)
}
}

View File

@ -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()

View File

@ -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()