Browse Source

test: more case

pull/316/head
fatedier 8 years ago
parent
commit
ab4a53965b
  1. 4
      Makefile
  2. 41
      Makefile.cross-compiles
  3. 6
      tests/conf/auto_test_frpc.ini
  4. 18
      tests/echo_server.go
  5. 33
      tests/func_test.go
  6. 28
      tests/run_test.sh

4
Makefile

@ -33,9 +33,9 @@ gotest:
go test -v ./utils/... go test -v ./utils/...
alltest: gotest alltest: gotest
cd ./test && ./run_test.sh && cd - cd ./tests && ./run_test.sh && cd -
go test -v ./tests/... go test -v ./tests/...
cd ./test && ./clean_test.sh && cd - cd ./tests && ./clean_test.sh && cd -
clean: clean:
rm -f ./bin/frpc rm -f ./bin/frpc

41
Makefile.cross-compiles

@ -1,28 +1,29 @@
export PATH := $(GOPATH)/bin:$(PATH) export PATH := $(GOPATH)/bin:$(PATH)
export GO15VENDOREXPERIMENT := 1 export GO15VENDOREXPERIMENT := 1
LDFLAGS := -s -w
all: build all: build
build: app build: app
app: app:
env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o ./frpc_darwin_amd64 ./cmd/frpc env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o ./frpc_darwin_amd64 ./cmd/frpc
env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o ./frps_darwin_amd64 ./cmd/frps env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o ./frps_darwin_amd64 ./cmd/frps
env CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -o ./frpc_linux_386 ./cmd/frpc env CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -ldflags "$(LDFLAGS)" -o ./frpc_linux_386 ./cmd/frpc
env CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -o ./frps_linux_386 ./cmd/frps env CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -ldflags "$(LDFLAGS)" -o ./frps_linux_386 ./cmd/frps
env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./frpc_linux_amd64 ./cmd/frpc env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o ./frpc_linux_amd64 ./cmd/frpc
env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./frps_linux_amd64 ./cmd/frps env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o ./frps_linux_amd64 ./cmd/frps
env CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -o ./frpc_linux_arm ./cmd/frpc env CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -ldflags "$(LDFLAGS)" -o ./frpc_linux_arm ./cmd/frpc
env CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -o ./frps_linux_arm ./cmd/frps env CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -ldflags "$(LDFLAGS)" -o ./frps_linux_arm ./cmd/frps
env CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -o ./frpc_windows_386.exe ./cmd/frpc env CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -ldflags "$(LDFLAGS)" -o ./frpc_windows_386.exe ./cmd/frpc
env CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -o ./frps_windows_386.exe ./cmd/frps env CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -ldflags "$(LDFLAGS)" -o ./frps_windows_386.exe ./cmd/frps
env CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o ./frpc_windows_amd64.exe ./cmd/frpc env CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o ./frpc_windows_amd64.exe ./cmd/frpc
env CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o ./frps_windows_amd64.exe ./cmd/frps env CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o ./frps_windows_amd64.exe ./cmd/frps
env CGO_ENABLED=0 GOOS=linux GOARCH=mips64 go build -o ./frpc_linux_mips64 ./cmd/frpc env CGO_ENABLED=0 GOOS=linux GOARCH=mips64 go build -ldflags "$(LDFLAGS)" -o ./frpc_linux_mips64 ./cmd/frpc
env CGO_ENABLED=0 GOOS=linux GOARCH=mips64 go build -o ./frps_linux_mips64 ./cmd/frps env CGO_ENABLED=0 GOOS=linux GOARCH=mips64 go build -ldflags "$(LDFLAGS)" -o ./frps_linux_mips64 ./cmd/frps
env CGO_ENABLED=0 GOOS=linux GOARCH=mips64le go build -o ./frpc_linux_mips64le ./cmd/frpc env CGO_ENABLED=0 GOOS=linux GOARCH=mips64le go build -ldflags "$(LDFLAGS)" -o ./frpc_linux_mips64le ./cmd/frpc
env CGO_ENABLED=0 GOOS=linux GOARCH=mips64le go build -o ./frps_linux_mips64le ./cmd/frps env CGO_ENABLED=0 GOOS=linux GOARCH=mips64le go build -ldflags "$(LDFLAGS)" -o ./frps_linux_mips64le ./cmd/frps
env CGO_ENABLED=0 GOOS=linux GOARCH=mips go build -o ./frpc_linux_mips ./cmd/frpc env CGO_ENABLED=0 GOOS=linux GOARCH=mips go build -o -ldflags "$(LDFLAGS)" ./frpc_linux_mips ./cmd/frpc
env CGO_ENABLED=0 GOOS=linux GOARCH=mips go build -o ./frps_linux_mips ./cmd/frps env CGO_ENABLED=0 GOOS=linux GOARCH=mips go build -o -ldflags "$(LDFLAGS)" ./frps_linux_mips ./cmd/frps
env CGO_ENABLED=0 GOOS=linux GOARCH=mipsle go build -o ./frpc_linux_mipsle ./cmd/frpc env CGO_ENABLED=0 GOOS=linux GOARCH=mipsle go build -o -ldflags "$(LDFLAGS)" ./frpc_linux_mipsle ./cmd/frpc
env CGO_ENABLED=0 GOOS=linux GOARCH=mipsle go build -o ./frps_linux_mipsle ./cmd/frps env CGO_ENABLED=0 GOOS=linux GOARCH=mipsle go build -o -ldflags "$(LDFLAGS)" ./frps_linux_mipsle ./cmd/frps

6
tests/conf/auto_test_frpc.ini

@ -21,3 +21,9 @@ local_port = 10702
use_encryption = true use_encryption = true
use_compression = true use_compression = true
custom_domains = 127.0.0.1 custom_domains = 127.0.0.1
[udp]
type = udp
local_ip = 127.0.0.1
local_port = 10703
remote_port = 10712

18
tests/echo_server.go

@ -26,6 +26,24 @@ func StartEchoServer() {
} }
} }
func StartUdpEchoServer() {
l, err := net.ListenUDP("127.0.0.1", 10703)
if err != nil {
fmt.Printf("udp echo server listen error: %v\n", err)
return
}
for {
c, err := l.Accept()
if err != nil {
fmt.Printf("udp echo server accept error: %v\n", err)
return
}
go echoWorker(c)
}
}
func echoWorker(c net.Conn) { func echoWorker(c net.Conn) {
br := bufio.NewReader(c) br := bufio.NewReader(c)
for { for {

33
tests/func_test.go

@ -2,18 +2,21 @@ package tests
import ( import (
"bufio" "bufio"
"bytes"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net"
"net/http" "net/http"
"strings" "strings"
"testing" "testing"
"time" "time"
"github.com/fatedier/frp/utils/net" frpNet "github.com/fatedier/frp/utils/net"
) )
var ( var (
ECHO_PORT int64 = 10711 ECHO_PORT int64 = 10711
UDP_ECHO_PORT int64 = 10712
HTTP_PORT int64 = 10710 HTTP_PORT int64 = 10710
ECHO_TEST_STR string = "Hello World\n" ECHO_TEST_STR string = "Hello World\n"
HTTP_RES_STR string = "Hello World" HTTP_RES_STR string = "Hello World"
@ -21,12 +24,13 @@ var (
func init() { func init() {
go StartEchoServer() go StartEchoServer()
go StartUdpEchoServer()
go StartHttpServer() go StartHttpServer()
time.Sleep(500 * time.Millisecond) time.Sleep(500 * time.Millisecond)
} }
func TestEchoServer(t *testing.T) { func TestEchoServer(t *testing.T) {
c, err := net.ConnectTcpServer(fmt.Sprintf("127.0.0.1:%d", ECHO_PORT)) c, err := frpNet.ConnectTcpServer(fmt.Sprintf("127.0.0.1:%d", ECHO_PORT))
if err != nil { if err != nil {
t.Fatalf("connect to echo server error: %v", err) t.Fatalf("connect to echo server error: %v", err)
} }
@ -66,3 +70,28 @@ func TestHttpServer(t *testing.T) {
t.Fatalf("http code from http server error [%d]", res.StatusCode) t.Fatalf("http code from http server error [%d]", res.StatusCode)
} }
} }
func TestUdpEchoServer(t *testing.T) {
addr, err := net.ResolveUDPAddr("udp", "127.0.0.1:10712")
if err != nil {
t.Fatalf("do udp request error: %v", err)
}
conn, err := net.DialUDP("udp", nil, addr)
if err != nil {
t.Fatalf("dial udp server error: %v", err)
}
defer conn.Close()
_, err = conn.Write([]byte("hello frp\n"))
if err != nil {
t.Fatalf("write to udp server error: %v", err)
}
data := make([]byte, 20)
n, err := conn.Read(data)
if err != nil {
t.Fatalf("read from udp server error: %v", err)
}
if string(bytes.TrimSpace(data[:n])) != "hello frp" {
t.Fatalf("message got from udp server error, get %s", string(data[:n-1]))
}
}

28
tests/run_test.sh

@ -1,34 +1,8 @@
#!/bin/bash #!/bin/bash
./bin/echo_server &
./bin/http_server &
./../bin/frps -c ./conf/auto_test_frps.ini & ./../bin/frps -c ./conf/auto_test_frps.ini &
sleep 1 sleep 1
./../bin/frpc -c ./conf/auto_test_frpc.ini & ./../bin/frpc -c ./conf/auto_test_frpc.ini &
# wait until proxies are connected # wait until proxies are connected
for((i=1; i<15; i++)) sleep 2
do
sleep 1
str=`ss -ant|grep 10700|grep LISTEN`
if [ -z "${str}" ]; then
echo "wait"
continue
fi
str=`ss -ant|grep 10710|grep LISTEN`
if [ -z "${str}" ]; then
echo "wait"
continue
fi
str=`ss -ant|grep 10711|grep LISTEN`
if [ -z "${str}" ]; then
echo "wait"
continue
fi
break
done
sleep 1

Loading…
Cancel
Save