diff --git a/cache/cache_test.go b/cache/cache_test.go index 1b56e14d..d87344fc 100644 --- a/cache/cache_test.go +++ b/cache/cache_test.go @@ -24,7 +24,7 @@ type testModel struct { Datapath *string `ovsdb:"datapath"` } -func (t *testModel) Table() string { +func (t *testModel) GetTableName() string { return "Open_vSwitch" } @@ -379,7 +379,7 @@ type testModel1 struct { Bar map[string]string `ovsdb:"bar"` } -func (t *testModel1) Table() string { +func (t *testModel1) GetTableName() string { return "Open_vSwitch" } @@ -807,7 +807,7 @@ type testModel2 struct { Baz string `ovsdb:"baz"` } -func (t *testModel2) Table() string { +func (t *testModel2) GetTableName() string { return "Open_vSwitch" } @@ -1058,7 +1058,7 @@ type testModel3 struct { Bar map[string]string `ovsdb:"bar"` } -func (t *testModel3) Table() string { +func (t *testModel3) GetTableName() string { return "Open_vSwitch" } @@ -1922,7 +1922,7 @@ type badModel struct { Baz string `ovsdb:"baz"` } -func (b *badModel) Table() string { +func (b *badModel) GetTableName() string { return "bad" } @@ -2156,7 +2156,7 @@ type testModel4 struct { Baz map[string]string `ovsdb:"baz"` } -func (t *testModel4) Table() string { +func (t *testModel4) GetTableName() string { return "Open_vSwitch" } @@ -2331,7 +2331,7 @@ type rowsByConditionTestModel struct { Empty string `ovsdb:"empty"` } -func (r *rowsByConditionTestModel) Table() string { +func (r *rowsByConditionTestModel) GetTableName() string { return "Open_vSwitch" } @@ -2747,7 +2747,7 @@ type testDBModel struct { Set []string `ovsdb:"set"` } -func (t *testDBModel) Table() string { +func (t *testDBModel) GetTableName() string { return "Open_vSwitch" } diff --git a/client/api.go b/client/api.go index 15de0aea..1dd3b775 100644 --- a/client/api.go +++ b/client/api.go @@ -549,7 +549,7 @@ func (a api) Wait(untilConFun ovsdb.WaitCondition, timeout *int, model model.Mod // getTableFromModel returns the table name from a Model object after performing // type verifications on the model func (a api) getTableFromModel(m model.Model) (string, error) { - table := m.Table() + table := m.GetTableName() if table == "" { return "", &ErrWrongType{reflect.TypeOf(m), "Model not found in Database Model"} } diff --git a/client/api_test_model.go b/client/api_test_model.go index 36ea476e..677761e6 100644 --- a/client/api_test_model.go +++ b/client/api_test_model.go @@ -123,12 +123,12 @@ type testLogicalSwitch struct { Acls []string `ovsdb:"acls"` } -// Table returns the table name. It's part of the Model interface -func (*testLogicalSwitch) Table() string { +// GetTableName returns the table name. It's part of the Model interface +func (*testLogicalSwitch) GetTableName() string { return "Logical_Switch" } -//LogicalSwitchPort struct defines an object in Logical_Switch_Port table +// LogicalSwitchPort struct defines an object in Logical_Switch_Port table type testLogicalSwitchPort struct { UUID string `ovsdb:"_uuid"` Up *bool `ovsdb:"up"` @@ -148,8 +148,8 @@ type testLogicalSwitchPort struct { ParentName *string `ovsdb:"parent_name"` } -// Table returns the table name. It's part of the Model interface -func (*testLogicalSwitchPort) Table() string { +// GetTableName returns the table name. It's part of the Model interface +func (*testLogicalSwitchPort) GetTableName() string { return "Logical_Switch_Port" } diff --git a/client/client_test.go b/client/client_test.go index 23ac2da9..9eeec738 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -81,7 +81,7 @@ type Bridge struct { STPEnable bool `ovsdb:"stp_enable"` } -func (b *Bridge) Table() string { +func (b *Bridge) GetTableName() string { return "Bridge" } @@ -107,7 +107,7 @@ type OpenvSwitch struct { SystemVersion *string `ovsdb:"system_version"` } -func (o *OpenvSwitch) Table() string { +func (o *OpenvSwitch) GetTableName() string { return "Open_vSwitch" } diff --git a/cmd/stress/stress.go b/cmd/stress/stress.go index e333be0e..c2948b73 100644 --- a/cmd/stress/stress.go +++ b/cmd/stress/stress.go @@ -29,7 +29,7 @@ type bridgeType struct { Status map[string]string `ovsdb:"status"` } -func (b *bridgeType) Table() string { +func (b *bridgeType) GetTableName() string { return "Bridge" } @@ -39,7 +39,7 @@ type ovsType struct { Bridges []string `ovsdb:"bridges"` } -func (o *ovsType) Table() string { +func (o *ovsType) GetTableName() string { return "Open_vSwitch" } diff --git a/model/model.go b/model/model.go index 57eb9db5..cfe5fb05 100644 --- a/model/model.go +++ b/model/model.go @@ -24,7 +24,7 @@ import ( // LoadBalancers []string `ovsdb:"load_balancer"` // } type Model interface { - Table() string + GetTableName() string } type CloneableModel interface { diff --git a/model/model_test.go b/model/model_test.go index 2e40daf8..390d4144 100644 --- a/model/model_test.go +++ b/model/model_test.go @@ -14,7 +14,7 @@ type modelA struct { UUID string `ovsdb:"_uuid"` } -func (m *modelA) Table() string { +func (m *modelA) GetTableName() string { return "A" } @@ -24,7 +24,7 @@ type modelB struct { Bar string `ovsdb:"baz"` } -func (m *modelB) Table() string { +func (m *modelB) GetTableName() string { return "B" } @@ -32,7 +32,7 @@ type modelInvalid struct { Foo string } -func (m *modelInvalid) Table() string { +func (m *modelInvalid) GetTableName() string { return "Invalid" } @@ -107,7 +107,7 @@ type testTable struct { AMap map[string]string `ovsdb:"aMap"` } -func (t *testTable) Table() string { +func (t *testTable) GetTableName() string { return "TestTable" } @@ -454,3 +454,12 @@ func TestEqualViaComparable(t *testing.T) { a.UID = "baz" assert.False(t, Equal(a, b)) } + +func TestGetTableName(t *testing.T) { + a := &testTable{} + func(a interface{}) { + m, ok := a.(Model) + assert.True(t, ok, "is not a model") + assert.Equal(t, m.GetTableName(), "TestTable") + }(a) +} diff --git a/modelgen/table.go b/modelgen/table.go index a7cc1854..3b9c7f94 100644 --- a/modelgen/table.go +++ b/modelgen/table.go @@ -246,7 +246,7 @@ type {{ index . "StructName" }} struct { {{ end }} {{ template "extraFields" . }} } -func (a *{{ index . "StructName" }}) Table() string { +func (a *{{ index . "StructName" }}) GetTableName() string { return {{ index . "StructName" }}Table } {{ template "postStructDefinitions" . }} diff --git a/modelgen/table_test.go b/modelgen/table_test.go index b3e38111..028235f3 100644 --- a/modelgen/table_test.go +++ b/modelgen/table_test.go @@ -81,7 +81,7 @@ type AtomicTable struct { Str string ` + "`" + `ovsdb:"str"` + "`" + ` } -func (a *AtomicTable) Table() string { +func (a *AtomicTable) GetTableName() string { return AtomicTableTable } `, @@ -108,7 +108,7 @@ type AtomicTable struct { Str string ` + "`" + `ovsdb:"str"` + "`" + ` } -func (a *AtomicTable) Table() string { +func (a *AtomicTable) GetTableName() string { return AtomicTableTable } `, @@ -160,7 +160,7 @@ type AtomicTable struct { OtherStr string } -func (a *AtomicTable) Table() string { +func (a *AtomicTable) GetTableName() string { return AtomicTableTable } `, @@ -201,7 +201,7 @@ type AtomicTable struct { Str string ` + "`" + `ovsdb:"str"` + "`" + ` } -func (a *AtomicTable) Table() string { +func (a *AtomicTable) GetTableName() string { return AtomicTableTable } @@ -370,7 +370,7 @@ type AtomicTable struct { OtherStr string } -func (a *AtomicTable) Table() string { +func (a *AtomicTable) GetTableName() string { return AtomicTableTable } @@ -503,7 +503,7 @@ type AtomicTable struct { Str string ` + "`" + `ovsdb:"str"` + "`" + ` } -func (a *AtomicTable) Table() string { +func (a *AtomicTable) GetTableName() string { return AtomicTableTable } @@ -630,7 +630,7 @@ type AtomicTable struct { Str string ` + "`" + `ovsdb:"str"` + "`" + ` } -func (a *AtomicTable) Table() string { +func (a *AtomicTable) GetTableName() string { return AtomicTableTable } @@ -1020,3 +1020,12 @@ func BenchmarkDeepEqual(b *testing.B) { }) } } + +func TestGetTableName(t *testing.T) { + bridge := &vswitchd.Bridge{} + func(bridge interface{}) { + b, ok := bridge.(model.Model) + assert.True(t, ok, "is not a model") + assert.Equal(t, b.GetTableName(), "Bridge") + }(bridge) +} diff --git a/ovsdb/serverdb/database.go b/ovsdb/serverdb/database.go index 8d6f4ad7..52b948c5 100644 --- a/ovsdb/serverdb/database.go +++ b/ovsdb/serverdb/database.go @@ -30,7 +30,7 @@ type Database struct { Sid *string `ovsdb:"sid"` } -func (a *Database) Table() string { +func (a *Database) GetTableName() string { return DatabaseTable } diff --git a/test/ovs/ovs_integration_test.go b/test/ovs/ovs_integration_test.go index a3621a3d..b74869ce 100644 --- a/test/ovs/ovs_integration_test.go +++ b/test/ovs/ovs_integration_test.go @@ -166,7 +166,7 @@ type bridgeType struct { DatapathID *string `ovsdb:"datapath_id"` } -func (b *bridgeType) Table() string { +func (b *bridgeType) GetTableName() string { return "Bridge" } @@ -192,7 +192,7 @@ type ovsType struct { SystemVersion *string `ovsdb:"system_version"` } -func (o *ovsType) Table() string { +func (o *ovsType) GetTableName() string { return "Open_vSwitch" } @@ -202,7 +202,7 @@ type ipfixType struct { Targets []string `ovsdb:"targets"` } -func (i *ipfixType) Table() string { +func (i *ipfixType) GetTableName() string { return "IPFIX" } @@ -212,7 +212,7 @@ type queueType struct { DSCP *int `ovsdb:"dscp"` } -func (q *queueType) Table() string { +func (q *queueType) GetTableName() string { return "Queue" } diff --git a/test/test_data.go b/test/test_data.go index 55a8b105..857d0d5e 100644 --- a/test/test_data.go +++ b/test/test_data.go @@ -144,7 +144,7 @@ type BridgeType struct { Status map[string]string `ovsdb:"status"` } -func (b *BridgeType) Table() string { +func (b *BridgeType) GetTableName() string { return "Bridge" } @@ -154,7 +154,7 @@ type OvsType struct { Bridges []string `ovsdb:"bridges"` } -func (o *OvsType) Table() string { +func (o *OvsType) GetTableName() string { return "Open_vSwitch" } @@ -166,7 +166,7 @@ type FlowSampleCollectorSetType struct { IPFIX *string // `ovsdb:"ipfix"` } -func (f *FlowSampleCollectorSetType) Table() string { +func (f *FlowSampleCollectorSetType) GetTableName() string { return "FlowSampleCollectorSet" }