From d74b45be5d037b58d18fec3be05064c3ec68e404 Mon Sep 17 00:00:00 2001 From: fatedier Date: Thu, 12 Jul 2018 00:31:21 +0800 Subject: [PATCH] more ci --- tests/{config => ci}/auto_test_frpc.ini | 0 .../{config => ci}/auto_test_frpc_visitor.ini | 0 tests/{config => ci}/auto_test_frps.ini | 0 tests/ci/cmd_test.go | 1 + tests/{func_test.go => ci/normal_test.go} | 8 +- tests/ci/reconnect_test.go | 1 + tests/ci/reload_test.go | 108 ++++++++++++++++++ tests/config/config.go | 10 +- tests/consts/consts.go | 4 +- 9 files changed, 123 insertions(+), 9 deletions(-) rename tests/{config => ci}/auto_test_frpc.ini (100%) rename tests/{config => ci}/auto_test_frpc_visitor.ini (100%) rename tests/{config => ci}/auto_test_frps.ini (100%) create mode 100644 tests/ci/cmd_test.go rename tests/{func_test.go => ci/normal_test.go} (97%) create mode 100644 tests/ci/reconnect_test.go create mode 100644 tests/ci/reload_test.go diff --git a/tests/config/auto_test_frpc.ini b/tests/ci/auto_test_frpc.ini similarity index 100% rename from tests/config/auto_test_frpc.ini rename to tests/ci/auto_test_frpc.ini diff --git a/tests/config/auto_test_frpc_visitor.ini b/tests/ci/auto_test_frpc_visitor.ini similarity index 100% rename from tests/config/auto_test_frpc_visitor.ini rename to tests/ci/auto_test_frpc_visitor.ini diff --git a/tests/config/auto_test_frps.ini b/tests/ci/auto_test_frps.ini similarity index 100% rename from tests/config/auto_test_frps.ini rename to tests/ci/auto_test_frps.ini diff --git a/tests/ci/cmd_test.go b/tests/ci/cmd_test.go new file mode 100644 index 00000000..006e04c2 --- /dev/null +++ b/tests/ci/cmd_test.go @@ -0,0 +1 @@ +package ci diff --git a/tests/func_test.go b/tests/ci/normal_test.go similarity index 97% rename from tests/func_test.go rename to tests/ci/normal_test.go index a83a6dc0..1ee0f58d 100644 --- a/tests/func_test.go +++ b/tests/ci/normal_test.go @@ -1,4 +1,4 @@ -package tests +package ci import ( "fmt" @@ -42,17 +42,17 @@ func init() { } func runFrps() error { - p := util.NewProcess(consts.FRPS_BIN_PATH, []string{"-c", "./config/auto_test_frps.ini"}) + p := util.NewProcess(consts.FRPS_BIN_PATH, []string{"-c", "./auto_test_frps.ini"}) return p.Start() } func runFrpc() error { - p := util.NewProcess(consts.FRPC_BIN_PATH, []string{"-c", "./config/auto_test_frpc.ini"}) + p := util.NewProcess(consts.FRPC_BIN_PATH, []string{"-c", "./auto_test_frpc.ini"}) return p.Start() } func runFrpcVisitor() error { - p := util.NewProcess(consts.FRPC_BIN_PATH, []string{"-c", "./config/auto_test_frpc_visitor.ini"}) + p := util.NewProcess(consts.FRPC_BIN_PATH, []string{"-c", "./auto_test_frpc_visitor.ini"}) return p.Start() } diff --git a/tests/ci/reconnect_test.go b/tests/ci/reconnect_test.go new file mode 100644 index 00000000..006e04c2 --- /dev/null +++ b/tests/ci/reconnect_test.go @@ -0,0 +1 @@ +package ci diff --git a/tests/ci/reload_test.go b/tests/ci/reload_test.go new file mode 100644 index 00000000..0a89f89d --- /dev/null +++ b/tests/ci/reload_test.go @@ -0,0 +1,108 @@ +package ci + +import ( + "os" + "testing" + "time" + + "github.com/stretchr/testify/assert" + + "github.com/fatedier/frp/tests/config" + "github.com/fatedier/frp/tests/consts" + "github.com/fatedier/frp/tests/util" +) + +const FRPS_CONF = ` +[common] +server_addr = 127.0.0.1 +server_port = 10700 +log_file = console +# debug, info, warn, error +log_level = debug +token = 123456 +admin_port = 10600 +admin_user = abc +admin_pwd = abc +` + +const FRPC_CONF_1 = ` +[common] +server_addr = 127.0.0.1 +server_port = 20000 +log_file = console +# debug, info, warn, error +log_level = debug +token = 123456 +admin_port = 21000 +admin_user = abc +admin_pwd = abc + +[tcp] +type = tcp +local_port = 10701 +remote_port = 20801 + +# change remote port +[tcp2] +type = tcp +local_port = 10701 +remote_port = 20802 + +# delete +[tcp3] +type = tcp +local_port = 10701 +remote_port = 20803 +` + +const FRPC_CONF_2 = ` +[common] +server_addr = 127.0.0.1 +server_port = 20000 +log_file = console +# debug, info, warn, error +log_level = debug +token = 123456 +admin_port = 21000 +admin_user = abc +admin_pwd = abc + +[tcp] +type = tcp +local_port = 10701 +remote_port = 20801 + +[tcp2] +type = tcp +local_port = 10701 +remote_port = 20902 +` + +func TestReload(t *testing.T) { + assert := assert.New(t) + frpsCfgPath, err := config.GenerateConfigFile("./auto_test_frps.ini", FRPS_CONF) + if assert.NoError(err) { + defer os.Remove(frpsCfgPath) + } + + frpcCfgPath, err := config.GenerateConfigFile("./auto_test_frpc.ini", FRPC_CONF_1) + if assert.NoError(err) { + defer os.Remove(frpcCfgPath) + } + + frpsProcess := util.NewProcess(consts.FRPS_BIN_PATH, []string{"-c", frpsCfgPath}) + err = frpsProcess.Start() + if assert.NoError(err) { + defer frpsProcess.Stop() + } + + time.Sleep(200 * time.Millisecond) + + frpcProcess := util.NewProcess(consts.FRPC_BIN_PATH, []string{"-c", frpcCfgPath}) + err = frpcProcess.Start() + if assert.NoError(err) { + defer frpcProcess.Stop() + } + + // TODO +} diff --git a/tests/config/config.go b/tests/config/config.go index 80e096b8..ac094467 100644 --- a/tests/config/config.go +++ b/tests/config/config.go @@ -1,9 +1,13 @@ -package util +package config import ( "io/ioutil" + "os" + "path/filepath" ) -func GenerateConfigFile(path string, content string) error { - return ioutil.WriteFile(path, []byte(content), 0666) +func GenerateConfigFile(path string, content string) (realPath string, err error) { + realPath = filepath.Join(os.TempDir(), path) + err = ioutil.WriteFile(realPath, []byte(content), 0666) + return realPath, err } diff --git a/tests/consts/consts.go b/tests/consts/consts.go index 7e70c89b..9deae3a8 100644 --- a/tests/consts/consts.go +++ b/tests/consts/consts.go @@ -3,8 +3,8 @@ package consts import "path/filepath" var ( - FRPS_BIN_PATH = "../bin/frps" - FRPC_BIN_PATH = "../bin/frpc" + FRPS_BIN_PATH = "../../bin/frps" + FRPC_BIN_PATH = "../../bin/frpc" SERVER_ADDR = "127.0.0.1" ADMIN_ADDR = "127.0.0.1:10600"