diff --git a/Makefile b/Makefile index c586ac1..8006090 100644 --- a/Makefile +++ b/Makefile @@ -3,9 +3,7 @@ export GO15VENDOREXPERIMENT := 1 all: fmt build -build: frps frpc build_test - -build_test: echo_server http_server +build: frps frpc # compile assets into binary file assets: @@ -15,16 +13,8 @@ assets: go generate ./assets/... fmt: - @go fmt ./assets/... - @go fmt ./cmd/... - @go fmt ./client/... - @go fmt ./server/... - @go fmt ./models/... - @go fmt ./utils/... - @go fmt ./test/echo_server.go - @go fmt ./test/http_server.go - @go fmt ./test/func_test.go - + go fmt ./... + frps: go build -o bin/frps ./cmd/frps @cp -rf ./assets/static ./bin @@ -32,29 +22,25 @@ frps: frpc: go build -o bin/frpc ./cmd/frpc -echo_server: - go build -o test/bin/echo_server ./test/echo_server.go - -http_server: - go build -o test/bin/http_server ./test/http_server.go - test: gotest gotest: - go test -v ./... + go test -v ./assets/... + go test -v ./client/... + go test -v ./cmd/... + go test -v ./models/... + go test -v ./server/... + go test -v ./utils/... -alltest: +alltest: gotest cd ./test && ./run_test.sh && cd - - go test -v ./src/... - go test -v ./test/func_test.go + go test -v ./tests/... cd ./test && ./clean_test.sh && cd - clean: rm -f ./bin/frpc rm -f ./bin/frps - rm -f ./test/bin/echo_server - rm -f ./test/bin/http_server cd ./test && ./clean_test.sh && cd - save: - godep save ./src/... + godep save ./... diff --git a/test/conf/auto_test_frps.ini b/test/conf/auto_test_frps.ini deleted file mode 100644 index 43462e8..0000000 --- a/test/conf/auto_test_frps.ini +++ /dev/null @@ -1,17 +0,0 @@ -[common] -bind_addr = 0.0.0.0 -bind_port = 10700 -vhost_http_port = 10710 -log_file = ./frps.log -log_level = debug - -[echo] -type = tcp -auth_token = 123 -bind_addr = 0.0.0.0 -listen_port = 10711 - -[web] -type = http -auth_token = 123 -custom_domains = 127.0.0.1 diff --git a/test/http_server.go b/test/http_server.go deleted file mode 100644 index cce5c14..0000000 --- a/test/http_server.go +++ /dev/null @@ -1,20 +0,0 @@ -package main - -import ( - "fmt" - "net/http" -) - -var ( - PORT int64 = 10702 - HTTP_RES_STR string = "Hello World" -) - -func main() { - http.HandleFunc("/", request) - http.ListenAndServe(fmt.Sprintf("0.0.0.0:%d", PORT), nil) -} - -func request(w http.ResponseWriter, r *http.Request) { - w.Write([]byte(HTTP_RES_STR)) -} diff --git a/test/clean_test.sh b/tests/clean_test.sh similarity index 58% rename from test/clean_test.sh rename to tests/clean_test.sh index 637c488..6a6ef56 100755 --- a/test/clean_test.sh +++ b/tests/clean_test.sh @@ -1,15 +1,5 @@ #!/bin/bash -pid=`ps aux|grep './bin/echo_server'|grep -v grep|awk {'print $2'}` -if [ -n "${pid}" ]; then - kill ${pid} -fi - -pid=`ps aux|grep './bin/http_server'|grep -v grep|awk {'print $2'}` -if [ -n "${pid}" ]; then - kill ${pid} -fi - pid=`ps aux|grep './../bin/frps -c ./conf/auto_test_frps.ini'|grep -v grep|awk {'print $2'}` if [ -n "${pid}" ]; then kill ${pid} diff --git a/test/conf/auto_test_frpc.ini b/tests/conf/auto_test_frpc.ini similarity index 64% rename from test/conf/auto_test_frpc.ini rename to tests/conf/auto_test_frpc.ini index e46d85b..19e3417 100644 --- a/test/conf/auto_test_frpc.ini +++ b/tests/conf/auto_test_frpc.ini @@ -4,17 +4,20 @@ server_port = 10700 log_file = ./frpc.log # debug, info, warn, error log_level = debug -auth_token = 123 +privilege_token = 123456 [echo] type = tcp local_ip = 127.0.0.1 local_port = 10701 +remote_port = 10711 use_encryption = true -use_gzip = true +use_compression = true [web] type = http local_ip = 127.0.0.1 local_port = 10702 -use_gzip = true +use_encryption = true +use_compression = true +custom_domains = 127.0.0.1 diff --git a/tests/conf/auto_test_frps.ini b/tests/conf/auto_test_frps.ini new file mode 100644 index 0000000..3d93359 --- /dev/null +++ b/tests/conf/auto_test_frps.ini @@ -0,0 +1,7 @@ +[common] +bind_addr = 0.0.0.0 +bind_port = 10700 +vhost_http_port = 10710 +log_file = ./frps.log +log_level = debug +privilege_token = 123456 diff --git a/test/echo_server.go b/tests/echo_server.go similarity index 84% rename from test/echo_server.go rename to tests/echo_server.go index fcbe2ed..3b22c46 100644 --- a/test/echo_server.go +++ b/tests/echo_server.go @@ -1,4 +1,4 @@ -package main +package tests import ( "bufio" @@ -8,12 +8,8 @@ import ( "github.com/fatedier/frp/utils/net" ) -var ( - PORT int64 = 10701 -) - -func main() { - l, err := net.ListenTcp("127.0.0.1", PORT) +func StartEchoServer() { + l, err := net.ListenTcp("127.0.0.1", 10701) if err != nil { fmt.Printf("echo server listen error: %v\n", err) return diff --git a/test/func_test.go b/tests/func_test.go similarity index 90% rename from test/func_test.go rename to tests/func_test.go index 633c9cb..6c1422a 100644 --- a/test/func_test.go +++ b/tests/func_test.go @@ -1,4 +1,4 @@ -package test +package tests import ( "bufio" @@ -19,6 +19,12 @@ var ( HTTP_RES_STR string = "Hello World" ) +func init() { + go StartEchoServer() + go StartHttpServer() + time.Sleep(500 * time.Millisecond) +} + func TestEchoServer(t *testing.T) { c, err := net.ConnectTcpServer(fmt.Sprintf("127.0.0.1:%d", ECHO_PORT)) if err != nil { @@ -27,8 +33,7 @@ func TestEchoServer(t *testing.T) { timer := time.Now().Add(time.Duration(5) * time.Second) c.SetDeadline(timer) - c.Write([]byte(ECHO_TEST_STR)) - c.Write('\n') + c.Write([]byte(ECHO_TEST_STR + "\n")) br := bufio.NewReader(c) buf, err := br.ReadString('\n') diff --git a/tests/http_server.go b/tests/http_server.go new file mode 100644 index 0000000..29eaa4d --- /dev/null +++ b/tests/http_server.go @@ -0,0 +1,15 @@ +package tests + +import ( + "fmt" + "net/http" +) + +func StartHttpServer() { + http.HandleFunc("/", request) + http.ListenAndServe(fmt.Sprintf("0.0.0.0:%d", 10702), nil) +} + +func request(w http.ResponseWriter, r *http.Request) { + w.Write([]byte(HTTP_RES_STR)) +} diff --git a/test/run_test.sh b/tests/run_test.sh similarity index 100% rename from test/run_test.sh rename to tests/run_test.sh diff --git a/utils/net/udp_test.go b/utils/net/udp_test.go deleted file mode 100644 index a7fca5a..0000000 --- a/utils/net/udp_test.go +++ /dev/null @@ -1,27 +0,0 @@ -package net - -import ( - "fmt" - "testing" -) - -func TestA(t *testing.T) { - l, err := ListenUDP("0.0.0.0", 9000) - if err != nil { - fmt.Println(err) - } - for { - c, _ := l.Accept() - go func() { - for { - buf := make([]byte, 1450) - n, err := c.Read(buf) - if err != nil { - fmt.Println(buf[:n]) - } - - c.Write(buf[:n]) - } - }() - } -} diff --git a/vendor/github.com/stretchr/testify/assert/assertions.go b/vendor/github.com/stretchr/testify/assert/assertions.go index d1552e5..b33045d 100644 --- a/vendor/github.com/stretchr/testify/assert/assertions.go +++ b/vendor/github.com/stretchr/testify/assert/assertions.go @@ -181,7 +181,7 @@ func indentMessageLines(message string, longestLabelLen int) string { // no need to align first line because it starts at the correct location (after the label) if i != 0 { // append alignLen+1 spaces to align with "{{longestLabel}}:" before adding tab - outBuf.WriteString("\n\r\t" + strings.Repeat(" ", longestLabelLen +1) + "\t") + outBuf.WriteString("\n\r\t" + strings.Repeat(" ", longestLabelLen+1) + "\t") } outBuf.WriteString(scanner.Text()) } @@ -229,7 +229,7 @@ func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) bool { } type labeledContent struct { - label string + label string content string }