Skip to content

Commit

Permalink
rename model.Model interface's Table func name, avoid conflict with sb
Browse files Browse the repository at this point in the history
  • Loading branch information
halfcrazy committed Sep 28, 2023
1 parent 754b46b commit 5e3aade
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 39 deletions.
16 changes: 8 additions & 8 deletions cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type testModel struct {
Datapath *string `ovsdb:"datapath"`
}

func (t *testModel) Table() string {
func (t *testModel) GetTableName() string {
return "Open_vSwitch"
}

Expand Down Expand Up @@ -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"
}

Expand Down Expand Up @@ -807,7 +807,7 @@ type testModel2 struct {
Baz string `ovsdb:"baz"`
}

func (t *testModel2) Table() string {
func (t *testModel2) GetTableName() string {
return "Open_vSwitch"
}

Expand Down Expand Up @@ -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"
}

Expand Down Expand Up @@ -1922,7 +1922,7 @@ type badModel struct {
Baz string `ovsdb:"baz"`
}

func (b *badModel) Table() string {
func (b *badModel) GetTableName() string {
return "bad"
}

Expand Down Expand Up @@ -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"
}

Expand Down Expand Up @@ -2331,7 +2331,7 @@ type rowsByConditionTestModel struct {
Empty string `ovsdb:"empty"`
}

func (r *rowsByConditionTestModel) Table() string {
func (r *rowsByConditionTestModel) GetTableName() string {
return "Open_vSwitch"
}

Expand Down Expand Up @@ -2747,7 +2747,7 @@ type testDBModel struct {
Set []string `ovsdb:"set"`
}

func (t *testDBModel) Table() string {
func (t *testDBModel) GetTableName() string {
return "Open_vSwitch"
}

Expand Down
2 changes: 1 addition & 1 deletion client/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
}
Expand Down
10 changes: 5 additions & 5 deletions client/api_test_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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"
}

Expand Down
4 changes: 2 additions & 2 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type Bridge struct {
STPEnable bool `ovsdb:"stp_enable"`
}

func (b *Bridge) Table() string {
func (b *Bridge) GetTableName() string {
return "Bridge"
}

Expand All @@ -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"
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/stress/stress.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand All @@ -39,7 +39,7 @@ type ovsType struct {
Bridges []string `ovsdb:"bridges"`
}

func (o *ovsType) Table() string {
func (o *ovsType) GetTableName() string {
return "Open_vSwitch"
}

Expand Down
2 changes: 1 addition & 1 deletion model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
// LoadBalancers []string `ovsdb:"load_balancer"`
// }
type Model interface {
Table() string
GetTableName() string
}

type CloneableModel interface {
Expand Down
17 changes: 13 additions & 4 deletions model/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type modelA struct {
UUID string `ovsdb:"_uuid"`
}

func (m *modelA) Table() string {
func (m *modelA) GetTableName() string {
return "A"
}

Expand All @@ -24,15 +24,15 @@ type modelB struct {
Bar string `ovsdb:"baz"`
}

func (m *modelB) Table() string {
func (m *modelB) GetTableName() string {
return "B"
}

type modelInvalid struct {
Foo string
}

func (m *modelInvalid) Table() string {
func (m *modelInvalid) GetTableName() string {
return "Invalid"
}

Expand Down Expand Up @@ -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"
}

Expand Down Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion modelgen/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" . }}
Expand Down
23 changes: 16 additions & 7 deletions modelgen/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type AtomicTable struct {
Str string ` + "`" + `ovsdb:"str"` + "`" + `
}
func (a *AtomicTable) Table() string {
func (a *AtomicTable) GetTableName() string {
return AtomicTableTable
}
`,
Expand All @@ -108,7 +108,7 @@ type AtomicTable struct {
Str string ` + "`" + `ovsdb:"str"` + "`" + `
}
func (a *AtomicTable) Table() string {
func (a *AtomicTable) GetTableName() string {
return AtomicTableTable
}
`,
Expand Down Expand Up @@ -160,7 +160,7 @@ type AtomicTable struct {
OtherStr string
}
func (a *AtomicTable) Table() string {
func (a *AtomicTable) GetTableName() string {
return AtomicTableTable
}
`,
Expand Down Expand Up @@ -201,7 +201,7 @@ type AtomicTable struct {
Str string ` + "`" + `ovsdb:"str"` + "`" + `
}
func (a *AtomicTable) Table() string {
func (a *AtomicTable) GetTableName() string {
return AtomicTableTable
}
Expand Down Expand Up @@ -370,7 +370,7 @@ type AtomicTable struct {
OtherStr string
}
func (a *AtomicTable) Table() string {
func (a *AtomicTable) GetTableName() string {
return AtomicTableTable
}
Expand Down Expand Up @@ -503,7 +503,7 @@ type AtomicTable struct {
Str string ` + "`" + `ovsdb:"str"` + "`" + `
}
func (a *AtomicTable) Table() string {
func (a *AtomicTable) GetTableName() string {
return AtomicTableTable
}
Expand Down Expand Up @@ -630,7 +630,7 @@ type AtomicTable struct {
Str string ` + "`" + `ovsdb:"str"` + "`" + `
}
func (a *AtomicTable) Table() string {
func (a *AtomicTable) GetTableName() string {
return AtomicTableTable
}
Expand Down Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion ovsdb/serverdb/database.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions test/ovs/ovs_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ type bridgeType struct {
DatapathID *string `ovsdb:"datapath_id"`
}

func (b *bridgeType) Table() string {
func (b *bridgeType) GetTableName() string {
return "Bridge"
}

Expand All @@ -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"
}

Expand All @@ -202,7 +202,7 @@ type ipfixType struct {
Targets []string `ovsdb:"targets"`
}

func (i *ipfixType) Table() string {
func (i *ipfixType) GetTableName() string {
return "IPFIX"
}

Expand All @@ -212,7 +212,7 @@ type queueType struct {
DSCP *int `ovsdb:"dscp"`
}

func (q *queueType) Table() string {
func (q *queueType) GetTableName() string {
return "Queue"
}

Expand Down
6 changes: 3 additions & 3 deletions test/test_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand All @@ -154,7 +154,7 @@ type OvsType struct {
Bridges []string `ovsdb:"bridges"`
}

func (o *OvsType) Table() string {
func (o *OvsType) GetTableName() string {
return "Open_vSwitch"
}

Expand All @@ -166,7 +166,7 @@ type FlowSampleCollectorSetType struct {
IPFIX *string // `ovsdb:"ipfix"`
}

func (f *FlowSampleCollectorSetType) Table() string {
func (f *FlowSampleCollectorSetType) GetTableName() string {
return "FlowSampleCollectorSet"
}

Expand Down

0 comments on commit 5e3aade

Please sign in to comment.