Skip to content

Commit

Permalink
Use the testmain to skip the OVS related testing
Browse files Browse the repository at this point in the history
  • Loading branch information
hwchiu committed Jun 5, 2018
1 parent d26e107 commit a0f6eee
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ clean:

test: pb client server
go clean -testcache
sudo -E env PATH=$$PATH TEST_OVS=1 TEST_VETH go test -v ./...
sudo -E env PATH=$$PATH TEST_OVS=1 TEST_VETH=1 go test -v ./...

.PHONY: server client vet test clean
29 changes: 6 additions & 23 deletions openvswitch/ovs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ var ovsFile = "/usr/bin/ovs-vsctl"
var o *OVSManager

func TestMain(m *testing.M) {
o = New()
retCode := m.Run()
os.Exit(retCode)
if _, ok := os.LookupEnv("TEST_OVS"); ok {
o = New()
retCode := m.Run()
os.Exit(retCode)
}
}

func changeVSCtl(t *testing.T) os.FileMode {
Expand All @@ -32,10 +34,6 @@ func resetVSCtl(mode os.FileMode) {
}

func TestBridgeOperations(t *testing.T) {
if _, ok := os.LookupEnv("TEST_OVS"); !ok {
t.SkipNow()
}

bridges, err := o.ListBridges()
assert.NoError(t, err)
assert.Equal(t, 0, len(bridges))
Expand All @@ -57,10 +55,6 @@ func TestBridgeOperations(t *testing.T) {
}

func TestBridgeOperationsFail(t *testing.T) {
if _, ok := os.LookupEnv("TEST_OVS"); !ok {
t.SkipNow()
}

mode := changeVSCtl(t)
defer resetVSCtl(mode)

Expand All @@ -79,10 +73,6 @@ func TestBridgeOperationsFail(t *testing.T) {
}

func TestAddDelPort(t *testing.T) {
if _, ok := os.LookupEnv("TEST_OVS"); !ok {
t.SkipNow()
}

bridgeName := "br0"
err := o.CreateBridge(bridgeName)
defer o.DeleteBridge(bridgeName)
Expand All @@ -108,10 +98,6 @@ func TestAddDelPort(t *testing.T) {
}

func TestListPortsFail(t *testing.T) {
if _, ok := os.LookupEnv("TEST_OVS"); !ok {
t.SkipNow()
}

bridgeName := "br0"
ports, err := o.ListPorts(bridgeName)
assert.Error(t, err)
Expand All @@ -133,10 +119,6 @@ func TestAddDelPortFail(t *testing.T) {
}

func TestFlowOperation(t *testing.T) {
if _, ok := os.LookupEnv("TEST_OVS"); !ok {
t.SkipNow()
}

bridgeName := "br0"
err := o.CreateBridge(bridgeName)
defer o.DeleteBridge(bridgeName)
Expand All @@ -159,6 +141,7 @@ func TestFlowOperation(t *testing.T) {
}

func TestFlowOperationsFail(t *testing.T) {

bridgeName := "br0"
err := o.AddFlow(bridgeName, "")
assert.Error(t, err)
Expand Down

0 comments on commit a0f6eee

Please sign in to comment.