pull/968/head
fatedier 6 years ago
parent 0d02f291e3
commit d74b45be5d

@ -0,0 +1 @@
package ci

@ -1,4 +1,4 @@
package tests package ci
import ( import (
"fmt" "fmt"
@ -42,17 +42,17 @@ func init() {
} }
func runFrps() error { 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() return p.Start()
} }
func runFrpc() error { 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() return p.Start()
} }
func runFrpcVisitor() error { 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() return p.Start()
} }

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

@ -1,9 +1,13 @@
package util package config
import ( import (
"io/ioutil" "io/ioutil"
"os"
"path/filepath"
) )
func GenerateConfigFile(path string, content string) error { func GenerateConfigFile(path string, content string) (realPath string, err error) {
return ioutil.WriteFile(path, []byte(content), 0666) realPath = filepath.Join(os.TempDir(), path)
err = ioutil.WriteFile(realPath, []byte(content), 0666)
return realPath, err
} }

@ -3,8 +3,8 @@ package consts
import "path/filepath" import "path/filepath"
var ( var (
FRPS_BIN_PATH = "../bin/frps" FRPS_BIN_PATH = "../../bin/frps"
FRPC_BIN_PATH = "../bin/frpc" FRPC_BIN_PATH = "../../bin/frpc"
SERVER_ADDR = "127.0.0.1" SERVER_ADDR = "127.0.0.1"
ADMIN_ADDR = "127.0.0.1:10600" ADMIN_ADDR = "127.0.0.1:10600"

Loading…
Cancel
Save