1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
package ovsdb
import (
"encoding/json"
"testing"
)
func TestNewGetSchemaArgs(t *testing.T) {
database := "Open_vSwitch"
args := NewGetSchemaArgs(database)
argString, _ := json.Marshal(args)
expected := `["Open_vSwitch"]`
if string(argString) != expected {
t.Error("Expected: ", expected, " Got: ", string(argString))
}
}
func TestNewWaitTransactArgs(t *testing.T) {
database := "Open_vSwitch"
i := 0
operation := Operation{Op: "wait", Table: "Bridge", Timeout: &i}
args := NewTransactArgs(database, operation)
argString, _ := json.Marshal(args)
expected := `["Open_vSwitch",{"op":"wait","table":"Bridge","timeout":0}]`
if string(argString) != expected {
t.Error("Expected: ", expected, " Got: ", string(argString))
}
}
func TestNewTransactArgs(t *testing.T) {
database := "Open_vSwitch"
operation := Operation{Op: "insert", Table: "Bridge"}
args := NewTransactArgs(database, operation)
argString, _ := json.Marshal(args)
expected := `["Open_vSwitch",{"op":"insert","table":"Bridge"}]`
if string(argString) != expected {
t.Error("Expected: ", expected, " Got: ", string(argString))
}
}
func TestNewMultipleTransactArgs(t *testing.T) {
database := "Open_vSwitch"
operation1 := Operation{Op: "insert", Table: "Bridge"}
operation2 := Operation{Op: "delete", Table: "Bridge"}
args := NewTransactArgs(database, operation1, operation2)
argString, _ := json.Marshal(args)
expected := `["Open_vSwitch",{"op":"insert","table":"Bridge"},{"op":"delete","table":"Bridge"}]`
if string(argString) != expected {
t.Error("Expected: ", expected, " Got: ", string(argString))
}
}
func TestNewCancelArgs(t *testing.T) {
id := 1
args := NewCancelArgs(id)
argString, _ := json.Marshal(args)
expected := `[1]`
if string(argString) != expected {
t.Error("Expected: ", expected, " Got: ", string(argString))
}
}
func TestNewMonitorArgs(t *testing.T) {
database := "Open_vSwitch"
value := 1
r := MonitorRequest{
Columns: []string{"name", "ports", "external_ids"},
Select: NewDefaultMonitorSelect(),
}
requests := make(map[string]MonitorRequest)
requests["Bridge"] = r
args := NewMonitorArgs(database, value, requests)
argString, _ := json.Marshal(args)
expected := `["Open_vSwitch",1,{"Bridge":{"columns":["name","ports","external_ids"],"select":{"initial":true,"insert":true,"delete":true,"modify":true}}}]`
if string(argString) != expected {
t.Error("Expected: ", expected, " Got: ", string(argString))
}
}
func TestNewMonitorCancelArgs(t *testing.T) {
value := 1
args := NewMonitorCancelArgs(value)
argString, _ := json.Marshal(args)
expected := `[1]`
if string(argString) != expected {
t.Error("Expected: ", expected, " Got: ", string(argString))
}
}
func TestNewLockArgs(t *testing.T) {
id := "testId"
args := NewLockArgs(id)
argString, _ := json.Marshal(args)
expected := `["testId"]`
if string(argString) != expected {
t.Error("Expected: ", expected, " Got: ", string(argString))
}
}
|