test: update

This commit is contained in:
fatedier
2017-03-10 00:52:32 +08:00
parent 307b74cc13
commit f83a2a73ab
12 changed files with 53 additions and 115 deletions

View File

@@ -1,24 +0,0 @@
#!/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}
fi
pid=`ps aux|grep './../bin/frpc -c ./conf/auto_test_frpc.ini'|grep -v grep|awk {'print $2'}`
if [ -n "${pid}" ]; then
kill ${pid}
fi
rm -f ./frps.log
rm -f ./frpc.log

View File

@@ -1,20 +0,0 @@
[common]
server_addr = 0.0.0.0
server_port = 10700
log_file = ./frpc.log
# debug, info, warn, error
log_level = debug
auth_token = 123
[echo]
type = tcp
local_ip = 127.0.0.1
local_port = 10701
use_encryption = true
use_gzip = true
[web]
type = http
local_ip = 127.0.0.1
local_port = 10702
use_gzip = true

View File

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

View File

@@ -1,47 +0,0 @@
package main
import (
"bufio"
"fmt"
"io"
"github.com/fatedier/frp/utils/net"
)
var (
PORT int64 = 10701
)
func main() {
l, err := net.ListenTcp("127.0.0.1", PORT)
if err != nil {
fmt.Printf("echo server listen error: %v\n", err)
return
}
for {
c, err := l.Accept()
if err != nil {
fmt.Printf("echo server accept error: %v\n", err)
return
}
go echoWorker(c)
}
}
func echoWorker(c net.Conn) {
br := bufio.NewReader(c)
for {
buf, err := br.ReadString('\n')
if err == io.EOF {
break
}
if err != nil {
fmt.Printf("echo server read error: %v\n", err)
return
}
c.Write([]byte(buf + "\n"))
}
}

View File

@@ -1,63 +0,0 @@
package test
import (
"bufio"
"fmt"
"io/ioutil"
"net/http"
"strings"
"testing"
"time"
"github.com/fatedier/frp/utils/net"
)
var (
ECHO_PORT int64 = 10711
HTTP_PORT int64 = 10710
ECHO_TEST_STR string = "Hello World\n"
HTTP_RES_STR string = "Hello World"
)
func TestEchoServer(t *testing.T) {
c, err := net.ConnectTcpServer(fmt.Sprintf("127.0.0.1:%d", ECHO_PORT))
if err != nil {
t.Fatalf("connect to echo server error: %v", err)
}
timer := time.Now().Add(time.Duration(5) * time.Second)
c.SetDeadline(timer)
c.Write([]byte(ECHO_TEST_STR))
c.Write('\n')
br := bufio.NewReader(c)
buf, err := br.ReadString('\n')
if err != nil {
t.Fatalf("read from echo server error: %v", err)
}
if ECHO_TEST_STR != buf {
t.Fatalf("content error, send [%s], get [%s]", strings.Trim(ECHO_TEST_STR, "\n"), strings.Trim(buf, "\n"))
}
}
func TestHttpServer(t *testing.T) {
client := &http.Client{}
req, _ := http.NewRequest("GET", fmt.Sprintf("http://127.0.0.1:%d", HTTP_PORT), nil)
res, err := client.Do(req)
if err != nil {
t.Fatalf("do http request error: %v", err)
}
if res.StatusCode == 200 {
body, err := ioutil.ReadAll(res.Body)
if err != nil {
t.Fatalf("read from http server error: %v", err)
}
bodystr := string(body)
if bodystr != HTTP_RES_STR {
t.Fatalf("content from http server error [%s], correct string is [%s]", bodystr, HTTP_RES_STR)
}
} else {
t.Fatalf("http code from http server error [%d]", res.StatusCode)
}
}

View File

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

View File

@@ -1,34 +0,0 @@
#!/bin/bash
./bin/echo_server &
./bin/http_server &
./../bin/frps -c ./conf/auto_test_frps.ini &
sleep 1
./../bin/frpc -c ./conf/auto_test_frpc.ini &
# wait until proxies are connected
for((i=1; i<15; i++))
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