mirror of
https://gitee.com/IrisVega/frp.git
synced 2024-11-01 22:31:29 +08:00
test: update
This commit is contained in:
parent
307b74cc13
commit
f83a2a73ab
36
Makefile
36
Makefile
@ -3,9 +3,7 @@ export GO15VENDOREXPERIMENT := 1
|
|||||||
|
|
||||||
all: fmt build
|
all: fmt build
|
||||||
|
|
||||||
build: frps frpc build_test
|
build: frps frpc
|
||||||
|
|
||||||
build_test: echo_server http_server
|
|
||||||
|
|
||||||
# compile assets into binary file
|
# compile assets into binary file
|
||||||
assets:
|
assets:
|
||||||
@ -15,15 +13,7 @@ assets:
|
|||||||
go generate ./assets/...
|
go generate ./assets/...
|
||||||
|
|
||||||
fmt:
|
fmt:
|
||||||
@go fmt ./assets/...
|
go fmt ./...
|
||||||
@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
|
|
||||||
|
|
||||||
frps:
|
frps:
|
||||||
go build -o bin/frps ./cmd/frps
|
go build -o bin/frps ./cmd/frps
|
||||||
@ -32,29 +22,25 @@ frps:
|
|||||||
frpc:
|
frpc:
|
||||||
go build -o bin/frpc ./cmd/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
|
test: gotest
|
||||||
|
|
||||||
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 -
|
cd ./test && ./run_test.sh && cd -
|
||||||
go test -v ./src/...
|
go test -v ./tests/...
|
||||||
go test -v ./test/func_test.go
|
|
||||||
cd ./test && ./clean_test.sh && cd -
|
cd ./test && ./clean_test.sh && cd -
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f ./bin/frpc
|
rm -f ./bin/frpc
|
||||||
rm -f ./bin/frps
|
rm -f ./bin/frps
|
||||||
rm -f ./test/bin/echo_server
|
|
||||||
rm -f ./test/bin/http_server
|
|
||||||
cd ./test && ./clean_test.sh && cd -
|
cd ./test && ./clean_test.sh && cd -
|
||||||
|
|
||||||
save:
|
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
|
#!/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'}`
|
pid=`ps aux|grep './../bin/frps -c ./conf/auto_test_frps.ini'|grep -v grep|awk {'print $2'}`
|
||||||
if [ -n "${pid}" ]; then
|
if [ -n "${pid}" ]; then
|
||||||
kill ${pid}
|
kill ${pid}
|
@ -4,17 +4,20 @@ server_port = 10700
|
|||||||
log_file = ./frpc.log
|
log_file = ./frpc.log
|
||||||
# debug, info, warn, error
|
# debug, info, warn, error
|
||||||
log_level = debug
|
log_level = debug
|
||||||
auth_token = 123
|
privilege_token = 123456
|
||||||
|
|
||||||
[echo]
|
[echo]
|
||||||
type = tcp
|
type = tcp
|
||||||
local_ip = 127.0.0.1
|
local_ip = 127.0.0.1
|
||||||
local_port = 10701
|
local_port = 10701
|
||||||
|
remote_port = 10711
|
||||||
use_encryption = true
|
use_encryption = true
|
||||||
use_gzip = true
|
use_compression = true
|
||||||
|
|
||||||
[web]
|
[web]
|
||||||
type = http
|
type = http
|
||||||
local_ip = 127.0.0.1
|
local_ip = 127.0.0.1
|
||||||
local_port = 10702
|
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 (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
@ -8,12 +8,8 @@ import (
|
|||||||
"github.com/fatedier/frp/utils/net"
|
"github.com/fatedier/frp/utils/net"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
func StartEchoServer() {
|
||||||
PORT int64 = 10701
|
l, err := net.ListenTcp("127.0.0.1", 10701)
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
l, err := net.ListenTcp("127.0.0.1", PORT)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("echo server listen error: %v\n", err)
|
fmt.Printf("echo server listen error: %v\n", err)
|
||||||
return
|
return
|
@ -1,4 +1,4 @@
|
|||||||
package test
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
@ -19,6 +19,12 @@ var (
|
|||||||
HTTP_RES_STR string = "Hello World"
|
HTTP_RES_STR string = "Hello World"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
go StartEchoServer()
|
||||||
|
go StartHttpServer()
|
||||||
|
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 := net.ConnectTcpServer(fmt.Sprintf("127.0.0.1:%d", ECHO_PORT))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -27,8 +33,7 @@ func TestEchoServer(t *testing.T) {
|
|||||||
timer := time.Now().Add(time.Duration(5) * time.Second)
|
timer := time.Now().Add(time.Duration(5) * time.Second)
|
||||||
c.SetDeadline(timer)
|
c.SetDeadline(timer)
|
||||||
|
|
||||||
c.Write([]byte(ECHO_TEST_STR))
|
c.Write([]byte(ECHO_TEST_STR + "\n"))
|
||||||
c.Write('\n')
|
|
||||||
|
|
||||||
br := bufio.NewReader(c)
|
br := bufio.NewReader(c)
|
||||||
buf, err := br.ReadString('\n')
|
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])
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
}
|
|
2
vendor/github.com/stretchr/testify/assert/assertions.go
generated
vendored
2
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)
|
// no need to align first line because it starts at the correct location (after the label)
|
||||||
if i != 0 {
|
if i != 0 {
|
||||||
// append alignLen+1 spaces to align with "{{longestLabel}}:" before adding tab
|
// 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())
|
outBuf.WriteString(scanner.Text())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user