Skip to content

Commit

Permalink
fixed testing bugs and travis-ci build
Browse files Browse the repository at this point in the history
  • Loading branch information
sio4 committed Sep 14, 2017
1 parent f105298 commit 6ed839f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 18 deletions.
9 changes: 8 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@ env:

before_script:
- go get github.com/mattn/goveralls
- go get github.com/AlekSi/gocoverutil

before_install:
- sudo apt-get -qq update
- sudo apt-get install -y libpcap-dev

go_import_path: github.com/hyeoncheon/goul

script:
- go build -o goul cmd/goul/main.go
- ls -l goul
- goveralls -service=travis-ci
- ./test-gocover.sh
- go test ./... -v
- goveralls -v -service=travis-ci

3 changes: 3 additions & 0 deletions network.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ func NewNetwork(addr string, port int) (*Net, error) {
} else {
n.log("client connected from ", n.conn.RemoteAddr())
}
} else {
n.log("listener closed. return.")
return
}
}
}()
Expand Down
20 changes: 8 additions & 12 deletions network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func Test_Net_10_ClientServerNormal(t *testing.T) {
r := require.New(t)
data := "Test Data"

cmd := make(chan int)
cmd := make(chan int, 10)
in := make(chan goul.Item)
out := make(chan goul.Item)

Expand All @@ -29,21 +29,14 @@ func Test_Net_10_ClientServerNormal(t *testing.T) {
go svr.Writer(in)
time.Sleep(3 * time.Second)

exitcmd := make(chan int)
go func() {
defer func() {
if r := recover(); r != nil {
fmt.Println("panic but recovered")
exitcmd <- 1
}
}()

for {
select {
case <-exitcmd:
return
default:
}
}()
for i := 0; i < 100; i++ {
in <- packet
time.Sleep(200 * time.Millisecond)
}
Expand All @@ -66,14 +59,17 @@ func Test_Net_10_ClientServerNormal(t *testing.T) {
result = <-out
}
cmd <- goul.ComInterrupt

for ok := true; ok; {
result, ok = <-out
}
time.Sleep(1 * time.Second)

r.Equal(false, cli.InLoop())
r.Error(cli.GetError())
r.Equal(goul.ErrPipeInterrupted, cli.GetError().Error())

ok := true
for ok {
for ok := true; ok; {
result, ok = <-out
}

Expand Down
2 changes: 1 addition & 1 deletion test-gocover.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ set -x

app=github.com/hyeoncheon/goul

gocoverutil -coverprofile=cover.out test -covermode=count $app/... && \
gocoverutil -coverprofile=cover.out test -v -covermode=count $app/... && \
go tool cover -html=cover.out -o cover.html

2 changes: 1 addition & 1 deletion test-goveralls.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
#
# repository: https://github.com/mattn/goveralls

goveralls -repotoken $COVERALLS_TOKEN
goveralls -v -repotoken $COVERALLS_TOKEN
18 changes: 15 additions & 3 deletions utils_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
package goul_test

import (
"os/user"
"testing"

"github.com/hyeoncheon/goul"
"github.com/stretchr/testify/require"

"github.com/hyeoncheon/goul"
)

func Test_PrintDevices_1_Normal(t *testing.T) {
user, err := user.Current()
if err != nil {
return
}
isTravis := user.Username == "travis"

r := require.New(t)

err := goul.PrintDevices()
r.NoError(err)
err = goul.PrintDevices()
if isTravis {
r.Error(err)
} else {
r.NoError(err)
}
}

0 comments on commit 6ed839f

Please sign in to comment.