mirror of
https://github.com/fatedier/frp.git
synced 2024-11-23 18:49:24 +08:00
test: update
This commit is contained in:
parent
307b74cc13
commit
f83a2a73ab
38
Makefile
38
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 ./...
|
||||
|
@ -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
|
@ -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))
|
||||
}
|
@ -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}
|
@ -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
tests/conf/auto_test_frps.ini
Normal file
7
tests/conf/auto_test_frps.ini
Normal file
@ -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
|
@ -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
|
@ -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
tests/http_server.go
Normal file
15
tests/http_server.go
Normal file
@ -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))
|
||||
}
|
@ -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])
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
4
vendor/github.com/stretchr/testify/assert/assertions.go
generated
vendored
4
vendor/github.com/stretchr/testify/assert/assertions.go
generated
vendored
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user