diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..691d930 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,8 @@ +os: + - linux + - osx +language: go +go: + - "1.11.x" +install: + - go get "github.com/pkg/errors" \ No newline at end of file diff --git a/README.md b/README.md index 13b2408..2b3b69d 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [![Go Report Card](https://goreportcard.com/badge/github.com/tevino/tcp-shaker)](https://goreportcard.com/report/github.com/tevino/tcp-shaker) [![GoDoc](https://godoc.org/github.com/tevino/tcp-shaker?status.svg)](https://godoc.org/github.com/tevino/tcp-shaker) +[![Build Status](https://travis-ci.org/tevino/tcp-shaker.svg?branch=master)](https://travis-ci.org/tevino/tcp-shaker) This package is used to perform TCP handshake without ACK, which useful for TCP health checking. diff --git a/check_linux_test.go b/check_linux_test.go index 66fd75a..eb32ad3 100644 --- a/check_linux_test.go +++ b/check_linux_test.go @@ -58,11 +58,6 @@ func TestStopNStartChecker(t *testing.T) { _testChecker(t, c) } -const ( - AddrDead = "127.0.0.1:1" - AddrTimeout = "10.0.0.0:1" -) - func _startTestServer() (string, context.CancelFunc) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})) addr := ts.Listener.Addr().String() diff --git a/checker_test.go b/checker_test.go index 359ee07..97eb310 100644 --- a/checker_test.go +++ b/checker_test.go @@ -11,6 +11,11 @@ import ( "time" ) +const ( + AddrDead = "127.0.0.1:1" + AddrTimeout = "10.255.255.1:80" +) + // assert calls t.Fatal if the result is false func assert(t *testing.T, result bool) { if !result { @@ -59,7 +64,7 @@ func TestCheckAddr(t *testing.T) { timeout := time.Second * 2 // Check dead server - err = c.CheckAddr("127.0.0.1:1", timeout) + err = c.CheckAddr(AddrDead, timeout) if runtime.GOOS == "linux" { _, ok := err.(*ErrConnect) assert(t, ok) @@ -73,8 +78,11 @@ func TestCheckAddr(t *testing.T) { assert(t, err == nil) ts.Close() // Check non-routable address, thus timeout - err = c.CheckAddr("10.0.0.0:1", timeout) - assert(t, err == ErrTimeout) + err = c.CheckAddr(AddrTimeout, timeout) + if err != ErrTimeout { + t.Log("expected ErrTimeout, got ", err) + t.FailNow() + } } func TestCheckAddrConcurrently(t *testing.T) { @@ -87,7 +95,7 @@ func TestCheckAddrConcurrently(t *testing.T) { var wg sync.WaitGroup check := func() { - if err := c.CheckAddr("10.0.0.0:1", time.Millisecond*50); err == nil { + if err := c.CheckAddr(AddrTimeout, time.Millisecond*50); err == nil { t.Fatal("Concurrent testing failed") } wg.Done()