Browse Source

test: update

fatedier 8 years ago
parent
commit
f83a2a73ab

+ 13 - 27
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 ./...
-
-alltest:
+	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: 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 ./...

+ 0 - 17
test/conf/auto_test_frps.ini

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

+ 0 - 20
test/http_server.go

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

+ 0 - 10
test/clean_test.sh → 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}

+ 6 - 3
test/conf/auto_test_frpc.ini → 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

+ 7 - 0
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

+ 3 - 7
test/echo_server.go → 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

+ 8 - 3
test/func_test.go → 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')

+ 15 - 0
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))
+}

+ 0 - 0
test/run_test.sh → tests/run_test.sh


+ 0 - 27
utils/net/udp_test.go

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

+ 2 - 2
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
 }