frp/tests/ci/cmd_test.go

86 lines
2.2 KiB
Go
Raw Normal View History

2018-07-12 00:31:21 +08:00
package ci
2018-07-12 15:23:34 +08:00
2018-07-12 16:49:16 +08:00
import (
"testing"
"time"
"github.com/fatedier/frp/tests/consts"
"github.com/fatedier/frp/tests/util"
"github.com/stretchr/testify/assert"
)
2020-05-24 17:48:37 +08:00
func TestCmdTCP(t *testing.T) {
2018-07-12 16:49:16 +08:00
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()
}
2019-03-11 17:11:26 +08:00
time.Sleep(200 * time.Millisecond)
2018-07-12 16:49:16 +08:00
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()
}
2019-03-11 17:11:26 +08:00
time.Sleep(500 * time.Millisecond)
2018-07-12 16:49:16 +08:00
2020-05-24 17:48:37 +08:00
res, err := util.SendTCPMsg("127.0.0.1:20801", consts.TEST_TCP_ECHO_STR)
2018-07-12 16:49:16 +08:00
assert.NoError(err)
assert.Equal(consts.TEST_TCP_ECHO_STR, res)
}
2020-05-24 17:48:37 +08:00
func TestCmdUDP(t *testing.T) {
2018-07-12 16:49:16 +08:00
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()
}
2019-03-11 17:11:26 +08:00
time.Sleep(200 * time.Millisecond)
2018-07-12 16:49:16 +08:00
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()
}
2019-03-11 17:11:26 +08:00
time.Sleep(500 * time.Millisecond)
2018-07-12 16:49:16 +08:00
2020-05-24 17:48:37 +08:00
res, err := util.SendUDPMsg("127.0.0.1:20802", consts.TEST_UDP_ECHO_STR)
2018-07-12 16:49:16 +08:00
assert.NoError(err)
assert.Equal(consts.TEST_UDP_ECHO_STR, res)
}
2020-05-24 17:48:37 +08:00
func TestCmdHTTP(t *testing.T) {
2018-07-12 16:49:16 +08:00
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()
}
2019-03-11 17:11:26 +08:00
time.Sleep(200 * time.Millisecond)
2018-07-12 16:49:16 +08:00
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()
}
2019-03-11 17:11:26 +08:00
time.Sleep(500 * time.Millisecond)
2018-07-12 16:49:16 +08:00
2020-05-24 17:48:37 +08:00
code, body, _, err := util.SendHTTPMsg("GET", "http://127.0.0.1:20001", "", nil, "")
2018-07-12 16:49:16 +08:00
if assert.NoError(err) {
assert.Equal(200, code)
assert.Equal(consts.TEST_HTTP_NORMAL_STR, body)
}
}