Skip to content

Commit

Permalink
Added testcased for ovsclient.go
Browse files Browse the repository at this point in the history
Signed-off-by: Zhenfang Wei <kopkop@gmail.com>
  • Loading branch information
kopwei committed Mar 31, 2016
1 parent 12f0b42 commit 7efe616
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docker/files/runtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

def main():
call(["/bin/bash", "/files/restore_dep.sh"])
call(["/usr/local/go/bin/go", "test", "github.com/kopwei/goovs"])
call(["/usr/local/go/bin/go", "test", "github.com/kopwei/goovs" , "-v", "-cover"])


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion ovsbridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

func TestBridgeExists(t *testing.T) {
brname := "nonexistentbr"
//brname := "nonexistentbr"
}

func TestCreateBridge(t *testing.T) {
Expand Down
68 changes: 59 additions & 9 deletions ovsclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,91 @@ package goovs

import (
"testing"

"github.com/kopwei/libovsdb"
)

func preparingEnv() OvsClient {
func preparingEnv() *ovsClient {
client, _ := GetOVSClient("tcp", "ovs:6640")
return client
return client.(*ovsClient)
}

func tearDown(client OvsClient) {
client.Disconnect()
}

func TestGetOVSClient(t *testing.T) {
// TODO
client, _ := GetOVSClient("tcp", "ovs:6640")
if client == nil {
t.Fatal("Get ovs client test failed")
}
}

func TestDisconnect(t *testing.T) {
// TODO
client := preparingEnv()
client.Disconnect()
}

func TestTransact(t *testing.T) {
// TODO
client := preparingEnv()
defer tearDown(client)
// Empty transaction
operations := []libovsdb.Operation{}
err := client.transact(operations, "")
if err != nil {
t.Fatal(err)
}
}

func TestUpdateOvsObjCacheByRow(t *testing.T) {
// TODO
//client := preparingEnv()
//defer tearDown(client)
err := client.updateOvsObjCacheByRow("Bridge", "abcde12345", &libovsdb.Row{})
if err != nil {
t.Fatal(err)
}
err = client.updateOvsObjCacheByRow("Port", "abcde12345", &libovsdb.Row{})
if err != nil {
t.Fatal(err)
}
err = client.updateOvsObjCacheByRow("Interface", "abcde12345", &libovsdb.Row{})
if err != nil {
t.Fatal(err)
}
}

func TestRemoveOvsObjCacheByRow(t *testing.T) {
// TODO
//client := preparingEnv()
//defer tearDown(client)
client.updateOvsObjCacheByRow("Bridge", "abcde12345", &libovsdb.Row{})
client.updateOvsObjCacheByRow("Port", "abcde12345", &libovsdb.Row{})
client.updateOvsObjCacheByRow("Interface", "abcde12345", &libovsdb.Row{})
err := client.removeOvsObjCacheByRow("Bridge", "abcde12345")
if err != nil {
t.Fatal(err)
}
err = client.removeOvsObjCacheByRow("Port", "abcde12345")
if err != nil {
t.Fatal(err)
}
err = client.removeOvsObjCacheByRow("Interface", "abcde12345")
if err != nil {
t.Fatal(err)
}
}

func TestPopulateCache(t *testing.T) {
// TODO
//updates := libovsdb.TableUpdates{}
}

func TestGetRootUUID(t *testing.T) {
// TODO
tmpCache := cache
cache = make(map[string]map[string]libovsdb.Row, 0)
cache[defaultOvsDB] = make(map[string]libovsdb.Row)
cache[defaultOvsDB]["abcdef12345"] = libovsdb.Row{}
uuid := getRootUUID()
if uuid != "abcdef12345" {
t.Fatalf("The uuid %s is incorrect", uuid)
}
cache = tmpCache
}

0 comments on commit 7efe616

Please sign in to comment.