Skip to content

Commit

Permalink
#94 rename OvsSet to OvsDataSet
Browse files Browse the repository at this point in the history
  • Loading branch information
kodsurfer committed Jul 12, 2024
1 parent 95e9dd2 commit 3a8a8dd
Show file tree
Hide file tree
Showing 22 changed files with 167 additions and 167 deletions.
2 changes: 1 addition & 1 deletion cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2037,7 +2037,7 @@ func BenchmarkPopulate2UpdateArray(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
for i := 0; i < numRows; i++ {
updatedRow := ovsdb.Row(map[string]interface{}{"array": ovsdb.OvsSet{GoSet: updateSet}})
updatedRow := ovsdb.Row(map[string]interface{}{"array": ovsdb.OvsDataSet{GoSet: updateSet}})
err := tc.Populate2(ovsdb.TableUpdates2{
"Open_vSwitch": {
"foo": &ovsdb.RowUpdate2{
Expand Down
2 changes: 1 addition & 1 deletion client/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1944,7 +1944,7 @@ func TestAPIWait(t *testing.T) {
{
Column: "up",
Function: ovsdb.ConditionNotEqual,
Value: ovsdb.OvsSet{GoSet: []interface{}{true}},
Value: ovsdb.OvsDataSet{GoSet: []interface{}{true}},
},
},
Until: string(ovsdb.WaitConditionNotEqual),
Expand Down
2 changes: 1 addition & 1 deletion client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ var schema = `{
}
}`

func testOvsSet(t *testing.T, set interface{}) ovsdb.OvsSet {
func testOvsSet(t *testing.T, set interface{}) ovsdb.OvsDataSet {
oSet, err := ovsdb.NewOvsSet(set)
assert.Nil(t, err)
return oSet
Expand Down
16 changes: 8 additions & 8 deletions database/inmemory/inmemory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ func TestMultipleOps(t *testing.T) {
ovsdb.NewCondition("_uuid", ovsdb.ConditionEqual, ovsdb.UUID{GoUUID: bridgeUUID}),
},
Row: ovsdb.Row{
"ports": ovsdb.OvsSet{GoSet: []interface{}{ovsdb.UUID{GoUUID: "port1"}, ovsdb.UUID{GoUUID: "port10"}}},
"ports": ovsdb.OvsDataSet{GoSet: []interface{}{ovsdb.UUID{GoUUID: "port1"}, ovsdb.UUID{GoUUID: "port10"}}},
"external_ids": ovsdb.OvsMap{GoMap: map[interface{}]interface{}{"key1": "value1", "key10": "value10"}},
},
}
Expand All @@ -612,7 +612,7 @@ func TestMultipleOps(t *testing.T) {
Op: ovsdb.OperationMutate,
Mutations: []ovsdb.Mutation{
*ovsdb.NewMutation("external_ids", ovsdb.MutateOperationInsert, ovsdb.OvsMap{GoMap: map[interface{}]interface{}{"keyA": "valueA"}}),
*ovsdb.NewMutation("ports", ovsdb.MutateOperationDelete, ovsdb.OvsSet{GoSet: []interface{}{ovsdb.UUID{GoUUID: "port1"}, ovsdb.UUID{GoUUID: "port10"}}}),
*ovsdb.NewMutation("ports", ovsdb.MutateOperationDelete, ovsdb.OvsDataSet{GoSet: []interface{}{ovsdb.UUID{GoUUID: "port1"}, ovsdb.UUID{GoUUID: "port10"}}}),
},
}
ops = append(ops, op)
Expand All @@ -625,7 +625,7 @@ func TestMultipleOps(t *testing.T) {
Op: ovsdb.OperationMutate,
Mutations: []ovsdb.Mutation{
*ovsdb.NewMutation("external_ids", ovsdb.MutateOperationDelete, ovsdb.OvsMap{GoMap: map[interface{}]interface{}{"key10": "value10"}}),
*ovsdb.NewMutation("ports", ovsdb.MutateOperationInsert, ovsdb.OvsSet{GoSet: []interface{}{ovsdb.UUID{GoUUID: "port1"}}}),
*ovsdb.NewMutation("ports", ovsdb.MutateOperationInsert, ovsdb.OvsDataSet{GoSet: []interface{}{ovsdb.UUID{GoUUID: "port1"}}}),
},
}
ops = append(ops, op2)
Expand All @@ -642,19 +642,19 @@ func TestMultipleOps(t *testing.T) {
bridgeUUID: &ovsdb.RowUpdate2{
Modify: &ovsdb.Row{
"external_ids": ovsdb.OvsMap{GoMap: map[interface{}]interface{}{"keyA": "valueA", "key10": "value10"}},
"ports": ovsdb.OvsSet{GoSet: []interface{}{ovsdb.UUID{GoUUID: "port10"}}},
"ports": ovsdb.OvsDataSet{GoSet: []interface{}{ovsdb.UUID{GoUUID: "port10"}}},
},
Old: &ovsdb.Row{
"_uuid": ovsdb.UUID{GoUUID: bridgeUUID},
"name": "a_bridge_to_nowhere",
"external_ids": ovsdb.OvsMap{GoMap: map[interface{}]interface{}{"key1": "value1", "key10": "value10"}},
"ports": ovsdb.OvsSet{GoSet: []interface{}{ovsdb.UUID{GoUUID: "port1"}, ovsdb.UUID{GoUUID: "port10"}}},
"ports": ovsdb.OvsDataSet{GoSet: []interface{}{ovsdb.UUID{GoUUID: "port1"}, ovsdb.UUID{GoUUID: "port10"}}},
},
New: &ovsdb.Row{
"_uuid": ovsdb.UUID{GoUUID: bridgeUUID},
"name": "a_bridge_to_nowhere",
"external_ids": ovsdb.OvsMap{GoMap: map[interface{}]interface{}{"key1": "value1", "keyA": "valueA"}},
"ports": ovsdb.OvsSet{GoSet: []interface{}{ovsdb.UUID{GoUUID: "port1"}}},
"ports": ovsdb.OvsDataSet{GoSet: []interface{}{ovsdb.UUID{GoUUID: "port1"}}},
},
},
},
Expand Down Expand Up @@ -941,7 +941,7 @@ func TestCheckIndexesWithReferentialIntegrity(t *testing.T) {
Op: ovsdb.OperationInsert,
UUID: ovsUUID,
Row: ovsdb.Row{
"manager_options": ovsdb.OvsSet{GoSet: []interface{}{ovsdb.UUID{GoUUID: managerUUID}}},
"manager_options": ovsdb.OvsDataSet{GoSet: []interface{}{ovsdb.UUID{GoUUID: managerUUID}}},
},
},
{
Expand Down Expand Up @@ -978,7 +978,7 @@ func TestCheckIndexesWithReferentialIntegrity(t *testing.T) {
Table: "Open_vSwitch",
Op: ovsdb.OperationUpdate,
Row: ovsdb.Row{
"manager_options": ovsdb.OvsSet{GoSet: []interface{}{ovsdb.UUID{GoUUID: managerUUID2}}},
"manager_options": ovsdb.OvsDataSet{GoSet: []interface{}{ovsdb.UUID{GoUUID: managerUUID2}}},
},
Where: []ovsdb.Condition{
ovsdb.NewCondition("_uuid", ovsdb.ConditionEqual, ovsdb.UUID{GoUUID: ovsUUID}),
Expand Down
2 changes: 1 addition & 1 deletion mapper/mapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ func TestMapperMutation(t *testing.T) {
}
}

func testOvsSet(t *testing.T, set interface{}) ovsdb.OvsSet {
func testOvsSet(t *testing.T, set interface{}) ovsdb.OvsDataSet {
oSet, err := ovsdb.NewOvsSet(set)
assert.Nil(t, err)
return oSet
Expand Down
8 changes: 4 additions & 4 deletions ovsdb/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func OvsToNativeSlice(baseType string, ovsElem interface{}) (interface{}, error)
naType := NativeTypeFromAtomic(baseType)
var nativeSet reflect.Value
switch ovsSet := ovsElem.(type) {
case OvsSet:
case OvsDataSet:
nativeSet = reflect.MakeSlice(reflect.SliceOf(naType), 0, len(ovsSet.GoSet))
for _, v := range ovsSet.GoSet {
nv, err := OvsToNativeAtomic(baseType, v)
Expand Down Expand Up @@ -152,7 +152,7 @@ func OvsToNative(column *ColumnSchema, ovsElem interface{}) (interface{}, error)
switch naType.Kind() {
case reflect.Ptr:
switch ovsSet := ovsElem.(type) {
case OvsSet:
case OvsDataSet:
if len(ovsSet.GoSet) > 1 {
return nil, fmt.Errorf("expected a slice of len =< 1, but got a slice with %d elements", len(ovsSet.GoSet))
}
Expand Down Expand Up @@ -233,7 +233,7 @@ func NativeToOvs(column *ColumnSchema, rawElem interface{}) (interface{}, error)
case TypeUUID:
return UUID{GoUUID: rawElem.(string)}, nil
case TypeSet:
var ovsSet OvsSet
var ovsSet OvsDataSet
if column.TypeObj.Key.Type == TypeUUID {
ovsSlice := []interface{}{}
if _, ok := rawElem.([]string); ok {
Expand All @@ -250,7 +250,7 @@ func NativeToOvs(column *ColumnSchema, rawElem interface{}) (interface{}, error)
} else {
return nil, fmt.Errorf("uuid slice was neither []string or *string")
}
ovsSet = OvsSet{GoSet: ovsSlice}
ovsSet = OvsDataSet{GoSet: ovsSlice}

} else {
var err error
Expand Down
4 changes: 2 additions & 2 deletions ovsdb/condition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestConditionMarshalUnmarshalJSON(t *testing.T) {
},
{
"test set",
Condition{"foo", ConditionExcludes, OvsSet{GoSet: []interface{}{"foo", "bar", "baz"}}},
Condition{"foo", ConditionExcludes, OvsDataSet{GoSet: []interface{}{"foo", "bar", "baz"}}},
`[ "foo", "excludes", ["set",["foo", "bar", "baz"]] ]`,
false,
},
Expand All @@ -83,7 +83,7 @@ func TestConditionMarshalUnmarshalJSON(t *testing.T) {
},
{
"test uuid set",
Condition{"foo", ConditionExcludes, OvsSet{GoSet: []interface{}{UUID{GoUUID: "foo"}, UUID{GoUUID: "bar"}}}},
Condition{"foo", ConditionExcludes, OvsDataSet{GoSet: []interface{}{UUID{GoUUID: "foo"}, UUID{GoUUID: "bar"}}}},
`[ "foo", "excludes", ["set",[["named-uuid", "foo"], ["named-uuid", "bar"]]] ]`,
false,
},
Expand Down
2 changes: 1 addition & 1 deletion ovsdb/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func TestSet(t *testing.T) {
assert.Nil(t, err)
assert.JSONEqf(t, tt.expected, string(jsonStr), "they should be equal\n")

var res OvsSet
var res OvsDataSet
err = json.Unmarshal(jsonStr, &res)
assert.Nil(t, err)
assert.Equal(t, set.GoSet, res.GoSet, "they should have the same elements\n")
Expand Down
4 changes: 2 additions & 2 deletions ovsdb/mutation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestMutationMarshalUnmarshalJSON(t *testing.T) {
},
{
"test set",
Mutation{"foo", MutateOperationInsert, OvsSet{GoSet: []interface{}{"foo", "bar", "baz"}}},
Mutation{"foo", MutateOperationInsert, OvsDataSet{GoSet: []interface{}{"foo", "bar", "baz"}}},
`[ "foo", "insert", ["set",["foo", "bar", "baz"]] ]`,
false,
},
Expand All @@ -77,7 +77,7 @@ func TestMutationMarshalUnmarshalJSON(t *testing.T) {
},
{
"test uuid set",
Mutation{"foo", MutateOperationInsert, OvsSet{GoSet: []interface{}{UUID{GoUUID: "foo"}, UUID{GoUUID: "bar"}}}},
Mutation{"foo", MutateOperationInsert, OvsDataSet{GoSet: []interface{}{UUID{GoUUID: "foo"}, UUID{GoUUID: "bar"}}}},
`[ "foo", "insert", ["set",[["named-uuid", "foo"], ["named-uuid", "bar"]]] ]`,
false,
},
Expand Down
2 changes: 1 addition & 1 deletion ovsdb/named_uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func expandNamedUUID(column *ColumnSchema, value interface{}, namedUUIDs map[str
}
}
} else if keyType == TypeUUID {
if ovsSet, ok := value.(OvsSet); ok {
if ovsSet, ok := value.(OvsDataSet); ok {
for i, s := range ovsSet.GoSet {
if newUUID, ok := expandNamedUUIDAtomic(keyType, s, namedUUIDs); ok {
ovsSet.GoSet[i] = newUUID
Expand Down
12 changes: 6 additions & 6 deletions ovsdb/named_uuid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,23 +187,23 @@ func TestStandaloneExpandNamedUUID(t *testing.T) {
"UUID set",
map[string]string{"foo": testUUID},
"uuidset",
OvsSet{GoSet: []interface{}{"foo"}},
OvsSet{GoSet: []interface{}{testUUID}},
OvsDataSet{GoSet: []interface{}{"foo"}},
OvsDataSet{GoSet: []interface{}{testUUID}},
},
// OVS []UUID == Go []UUID
{
"real UUID set",
map[string]string{"foo": testUUID},
"real_uuidset",
OvsSet{GoSet: []interface{}{UUID{GoUUID: "foo"}}},
OvsSet{GoSet: []interface{}{UUID{GoUUID: testUUID}}},
OvsDataSet{GoSet: []interface{}{UUID{GoUUID: "foo"}}},
OvsDataSet{GoSet: []interface{}{UUID{GoUUID: testUUID}}},
},
{
"set multiple",
map[string]string{"foo": testUUID, "bar": testUUID1},
"uuidset",
OvsSet{GoSet: []interface{}{"foo", "bar", "baz"}},
OvsSet{GoSet: []interface{}{testUUID, testUUID1, "baz"}},
OvsDataSet{GoSet: []interface{}{"foo", "bar", "baz"}},
OvsDataSet{GoSet: []interface{}{testUUID, testUUID1, "baz"}},
},
// OVS [UUID]UUID == Go [string]string
{
Expand Down
2 changes: 1 addition & 1 deletion ovsdb/notation.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func ovsSliceToGoNotation(val interface{}) (interface{}, error) {
err = json.Unmarshal(bsliced, &uuid)
return uuid, err
case "set":
var oSet OvsSet
var oSet OvsDataSet
err = json.Unmarshal(bsliced, &oSet)
return oSet, err
case "map":
Expand Down
12 changes: 6 additions & 6 deletions ovsdb/notation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ func TestValidateOvsSet(t *testing.T) {
goSlice := []int{1, 2, 3, 4}
oSet, err := NewOvsSet(goSlice)
if err != nil {
t.Error("Error creating OvsSet ", err)
t.Error("Error creating OvsDataSet ", err)
}
data, err := json.Marshal(oSet)
if err != nil {
t.Error("Error Marshalling OvsSet", err)
t.Error("Error Marshalling OvsDataSet", err)
}
expected := `["set",[1,2,3,4]]`
if string(data) != expected {
Expand All @@ -106,7 +106,7 @@ func TestValidateOvsSet(t *testing.T) {
// Negative condition test
oSet, err = NewOvsSet(struct{ foo string }{})
if err == nil {
t.Error("OvsSet must fail for anything other than Slices and atomic types")
t.Error("OvsDataSet must fail for anything other than Slices and atomic types")
t.Error("Got", oSet)
}
}
Expand Down Expand Up @@ -219,19 +219,19 @@ func TestOvsSliceToGoNotation(t *testing.T) {
{
"empty set",
[]interface{}{"set", []interface{}{}},
OvsSet{GoSet: []interface{}{}},
OvsDataSet{GoSet: []interface{}{}},
false,
},
{
"set",
[]interface{}{"set", []interface{}{"foo", "bar", "baz"}},
OvsSet{GoSet: []interface{}{"foo", "bar", "baz"}},
OvsDataSet{GoSet: []interface{}{"foo", "bar", "baz"}},
false,
},
{
"uuid set",
[]interface{}{"set", []interface{}{[]interface{}{"named-uuid", "foo"}, []interface{}{"named-uuid", "bar"}}},
OvsSet{GoSet: []interface{}{UUID{GoUUID: "foo"}, UUID{GoUUID: "bar"}}},
OvsDataSet{GoSet: []interface{}{UUID{GoUUID: "foo"}, UUID{GoUUID: "bar"}}},
false,
},
{
Expand Down
22 changes: 11 additions & 11 deletions ovsdb/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ func (b *BaseType) UnmarshalJSON(data []byte) error {
// 'enum' is a list or a single element representing a list of exactly one element
switch bt.Enum.(type) {
case []interface{}:
// it's an OvsSet
// it's an OvsDataSet
oSet := bt.Enum.([]interface{})
innerSet := oSet[1].([]interface{})
b.Enum = make([]interface{}, len(innerSet))
Expand All @@ -369,16 +369,16 @@ func (b *BaseType) UnmarshalJSON(data []byte) error {
// MarshalJSON marshals a base type to JSON
func (b BaseType) MarshalJSON() ([]byte, error) {
j := struct {
Type string `json:"type,omitempty"`
Enum *OvsSet `json:"enum,omitempty"`
MinReal *float64 `json:"minReal,omitempty"`
MaxReal *float64 `json:"maxReal,omitempty"`
MinInteger *int `json:"minInteger,omitempty"`
MaxInteger *int `json:"maxInteger,omitempty"`
MinLength *int `json:"minLength,omitempty"`
MaxLength *int `json:"maxLength,omitempty"`
RefTable *string `json:"refTable,omitempty"`
RefType *RefType `json:"refType,omitempty"`
Type string `json:"type,omitempty"`
Enum *OvsDataSet `json:"enum,omitempty"`
MinReal *float64 `json:"minReal,omitempty"`
MaxReal *float64 `json:"maxReal,omitempty"`
MinInteger *int `json:"minInteger,omitempty"`
MaxInteger *int `json:"maxInteger,omitempty"`
MinLength *int `json:"minLength,omitempty"`
MaxLength *int `json:"maxLength,omitempty"`
RefTable *string `json:"refTable,omitempty"`
RefType *RefType `json:"refType,omitempty"`
}{
Type: b.Type,
MinReal: b.minReal,
Expand Down
20 changes: 10 additions & 10 deletions ovsdb/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@ import (
"reflect"
)

// OvsSet is an OVSDB style set
// OvsDataSet is an OVSDB style set
// RFC 7047 has a weird (but understandable) notation for set as described as :
// Either an <atom>, representing a set with exactly one element, or
// a 2-element JSON array that represents a database set value. The
// first element of the array must be the string "set", and the
// second element must be an array of zero or more <atom>s giving the
// values in the set. All of the <atom>s must have the same type.
type OvsSet struct {
type OvsDataSet struct {
GoSet []interface{}
}

// NewOvsSet creates a new OVSDB style set from a Go interface (object)
func NewOvsSet(obj interface{}) (OvsSet, error) {
func NewOvsSet(obj interface{}) (OvsDataSet, error) {
ovsSet := make([]interface{}, 0)
var v reflect.Value
if reflect.TypeOf(obj).Kind() == reflect.Ptr {
v = reflect.ValueOf(obj).Elem()
if v.Kind() == reflect.Invalid {
// must be a nil pointer, so just return an empty set
return OvsSet{ovsSet}, nil
return OvsDataSet{ovsSet}, nil
}
} else {
v = reflect.ValueOf(obj)
Expand All @@ -45,16 +45,16 @@ func NewOvsSet(obj interface{}) (OvsSet, error) {
if v.Type() == reflect.TypeOf(UUID{}) {
ovsSet = append(ovsSet, v.Interface())
} else {
return OvsSet{}, fmt.Errorf("ovsset supports only go slice/string/numbers/uuid or pointers to those types")
return OvsDataSet{}, fmt.Errorf("ovsset supports only go slice/string/numbers/uuid or pointers to those types")
}
default:
return OvsSet{}, fmt.Errorf("ovsset supports only go slice/string/numbers/uuid or pointers to those types")
return OvsDataSet{}, fmt.Errorf("ovsset supports only go slice/string/numbers/uuid or pointers to those types")
}
return OvsSet{ovsSet}, nil
return OvsDataSet{ovsSet}, nil
}

// MarshalJSON wil marshal an OVSDB style Set in to a JSON byte array
func (o OvsSet) MarshalJSON() ([]byte, error) {
func (o OvsDataSet) MarshalJSON() ([]byte, error) {
switch l := len(o.GoSet); {
case l == 1:
return json.Marshal(o.GoSet[0])
Expand All @@ -68,9 +68,9 @@ func (o OvsSet) MarshalJSON() ([]byte, error) {
}

// UnmarshalJSON will unmarshal a JSON byte array to an OVSDB style Set
func (o *OvsSet) UnmarshalJSON(b []byte) (err error) {
func (o *OvsDataSet) UnmarshalJSON(b []byte) (err error) {
o.GoSet = make([]interface{}, 0)
addToSet := func(o *OvsSet, v interface{}) error {
addToSet := func(o *OvsDataSet, v interface{}) error {
goVal, err := ovsSliceToGoNotation(v)
if err == nil {
o.GoSet = append(o.GoSet, goVal)
Expand Down
2 changes: 1 addition & 1 deletion ovsdb/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func BenchmarkSetMarshalJSONUUID8(b *testing.B) {

func benchmarkSetUnmarshalJSON(data []byte, b *testing.B) {
for n := 0; n < b.N; n++ {
var s OvsSet
var s OvsDataSet
err := json.Unmarshal(data, &s)
if err != nil {
b.Fatal(err)
Expand Down
Loading

0 comments on commit 3a8a8dd

Please sign in to comment.