mirror of
https://github.com/ICKelin/opennotr.git
synced 2025-09-26 20:01:13 +08:00
test: add test coverage file
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -4,3 +4,5 @@ bin
|
||||
*.prof
|
||||
*.pprof
|
||||
*.svg
|
||||
*.txt
|
||||
*.out
|
@@ -8,6 +8,10 @@ install:
|
||||
before_script:
|
||||
script:
|
||||
- cd $HOME/gopath/src/github.com/ICKelin/opennotr
|
||||
- chmod +x coverage.sh
|
||||
- ./coverage.sh
|
||||
- chmod +x build_exec.sh
|
||||
- ./build_exec.sh
|
||||
|
||||
after_success:
|
||||
- bash <(curl -s https://codecov.io/bash)
|
@@ -4,6 +4,9 @@
|
||||
|
||||
|
||||
<p align="center">
|
||||
<a href="">
|
||||
<img src="https://img.shields.io/badge/-Go-000?&logo=go">
|
||||
</a>
|
||||
<a href="https://goreportcard.com/report/github.com/ICKelin/opennotr" rel="nofollow">
|
||||
<img src="https://goreportcard.com/badge/github.com/ICKelin/opennotr" alt="go report">
|
||||
</a>
|
||||
|
12
coverage.sh
Executable file
12
coverage.sh
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
echo "" > coverage.txt
|
||||
|
||||
for d in $(go list ./... | grep -v vendor); do
|
||||
go test -race -coverprofile=profile.out -covermode=atomic $d -v
|
||||
if [ -f profile.out ]; then
|
||||
cat profile.out >> coverage.txt
|
||||
rm profile.out
|
||||
fi
|
||||
done
|
@@ -9,6 +9,12 @@ import (
|
||||
_ "github.com/ICKelin/opennotr/opennotrd/plugin/tcpproxy"
|
||||
)
|
||||
|
||||
var listener net.Listener
|
||||
|
||||
func init() {
|
||||
|
||||
}
|
||||
|
||||
func runTCPServer(bufsize int) net.Listener {
|
||||
lis, err := net.Listen("tcp", "127.0.0.1:2345")
|
||||
if err != nil {
|
||||
@@ -37,16 +43,18 @@ func onconn(conn net.Conn, bufsize int) {
|
||||
}
|
||||
|
||||
func runEcho(t *testing.T, bufsize, numconn int) {
|
||||
item := &plugin.ProxyItem{
|
||||
item := &plugin.PluginMeta{
|
||||
Protocol: "tcp",
|
||||
From: "127.0.0.1:1234",
|
||||
To: "127.0.0.1:2345",
|
||||
RecycleSignal: make(chan struct{}),
|
||||
}
|
||||
err := plugin.DefaultStream().AddProxy(item)
|
||||
err := plugin.DefaultPluginManager().AddProxy(item)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
defer plugin.DefaultPluginManager().DelProxy(item)
|
||||
|
||||
lis := runTCPServer(bufsize)
|
||||
|
||||
@@ -68,8 +76,8 @@ func runEcho(t *testing.T, bufsize, numconn int) {
|
||||
}
|
||||
tick := time.NewTicker(time.Second * 60)
|
||||
<-tick.C
|
||||
|
||||
lis.Close()
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
|
||||
func TestTCPEcho128B(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user