test: add test coverage file

This commit is contained in:
ICKelin
2021-05-01 07:51:49 +08:00
parent e59425baeb
commit 257bab48cd
5 changed files with 36 additions and 7 deletions

2
.gitignore vendored
View File

@@ -4,3 +4,5 @@ bin
*.prof
*.pprof
*.svg
*.txt
*.out

View File

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

View File

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

View File

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