diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..5d70bb5 --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,31 @@ +name: GoCast + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + + build: + name: Build and unit test + runs-on: ubuntu-latest + env: + - CI: 1 + steps: + + - name: Set up Go 1.x + uses: actions/setup-go@v2 + with: + go-version: ^1.14 + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + + - name: Build + run: make + + - name: Test + run: make test diff --git a/controller/bgp_test.go b/controller/bgp_test.go index 25ad279..425d0e6 100644 --- a/controller/bgp_test.go +++ b/controller/bgp_test.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "net" + "os" "testing" "github.com/golang/protobuf/ptypes" @@ -18,8 +19,6 @@ type BgpListener struct { recvdPaths chan string } -var listener *BgpListener - // NewBgpListener starts a local BGP server for testing purposes func NewBgpListener(localAS int) (*BgpListener, error) { s := gobgp.NewBgpServer() @@ -71,6 +70,14 @@ func (l *BgpListener) Shutdown() error { // if the test timeouts are very small. It also needs to be run as // root (sudo) func TestBgpNew(t *testing.T) { + if os.Getenv("CI") != "" { + t.Skip("Skipping testing in CI environment") + } + listener, err := NewBgpListener(22222) + if err != nil { + panic(err) + } + defer listener.Shutdown() a := assert.New(t) c := config.BgpConfig{ LocalAS: 11111, diff --git a/controller/system_test.go b/controller/system_test.go index d0f10ef..44b2219 100644 --- a/controller/system_test.go +++ b/controller/system_test.go @@ -54,17 +54,10 @@ func TestMain(m *testing.M) { case "test_add_fail": os.Exit(1) default: - fmt.Println("success") + break } if os.Getenv("test_name") != "" { return } - var err error - listener, err = NewBgpListener(22222) - if err != nil { - panic(err) - } - code := m.Run() - listener.Shutdown() - os.Exit(code) + os.Exit(m.Run()) }