@@ -9,6 +9,14 @@ import (
9
9
"github.com/ovn-org/libovsdb/model"
10
10
"github.com/ovn-org/libovsdb/ovsdb"
11
11
"github.com/stretchr/testify/assert"
12
+ "github.com/stretchr/testify/require"
13
+ )
14
+
15
+ var (
16
+ trueVal = true
17
+ falseVal = false
18
+ one = 1
19
+ six = 6
12
20
)
13
21
14
22
func TestAPIListSimple (t * testing.T ) {
@@ -222,25 +230,25 @@ func TestAPIListFields(t *testing.T) {
222
230
UUID : aUUID0 ,
223
231
Name : "lsp0" ,
224
232
ExternalIds : map [string ]string {"foo" : "bar" },
225
- Enabled : [] bool { true } ,
233
+ Enabled : & trueVal ,
226
234
},
227
235
& testLogicalSwitchPort {
228
236
UUID : aUUID1 ,
229
237
Name : "magiclsp1" ,
230
238
ExternalIds : map [string ]string {"foo" : "baz" },
231
- Enabled : [] bool { false } ,
239
+ Enabled : & falseVal ,
232
240
},
233
241
& testLogicalSwitchPort {
234
242
UUID : aUUID2 ,
235
243
Name : "lsp2" ,
236
244
ExternalIds : map [string ]string {"unique" : "id" },
237
- Enabled : [] bool { false } ,
245
+ Enabled : & falseVal ,
238
246
},
239
247
& testLogicalSwitchPort {
240
248
UUID : aUUID3 ,
241
249
Name : "magiclsp2" ,
242
250
ExternalIds : map [string ]string {"foo" : "baz" },
243
- Enabled : [] bool { true } ,
251
+ Enabled : & trueVal ,
244
252
},
245
253
}
246
254
lspcache := map [string ]model.Model {}
@@ -624,22 +632,22 @@ func TestAPIMutate(t *testing.T) {
624
632
Name : "lsp0" ,
625
633
Type : "someType" ,
626
634
ExternalIds : map [string ]string {"foo" : "bar" },
627
- Enabled : [] bool { true } ,
628
- Tag : [] int { 1 } ,
635
+ Enabled : & trueVal ,
636
+ Tag : & one ,
629
637
},
630
638
aUUID1 : & testLogicalSwitchPort {
631
639
UUID : aUUID1 ,
632
640
Name : "lsp1" ,
633
641
Type : "someType" ,
634
642
ExternalIds : map [string ]string {"foo" : "baz" },
635
- Tag : [] int { 1 } ,
643
+ Tag : & one ,
636
644
},
637
645
aUUID2 : & testLogicalSwitchPort {
638
646
UUID : aUUID2 ,
639
647
Name : "lsp2" ,
640
648
Type : "someOtherType" ,
641
649
ExternalIds : map [string ]string {"foo" : "baz" },
642
- Tag : [] int { 1 } ,
650
+ Tag : & one ,
643
651
},
644
652
}
645
653
testData := cache.Data {
@@ -648,7 +656,6 @@ func TestAPIMutate(t *testing.T) {
648
656
tcache := apiTestCache (t , testData )
649
657
650
658
testObj := testLogicalSwitchPort {}
651
-
652
659
test := []struct {
653
660
name string
654
661
condition func (API ) ConditionalAPI
@@ -667,16 +674,16 @@ func TestAPIMutate(t *testing.T) {
667
674
},
668
675
mutations : []model.Mutation {
669
676
{
670
- Field : & testObj .Tag ,
677
+ Field : & testObj .Addresses ,
671
678
Mutator : ovsdb .MutateOperationInsert ,
672
- Value : []int { 5 },
679
+ Value : []string { "1.1.1.1" },
673
680
},
674
681
},
675
682
result : []ovsdb.Operation {
676
683
{
677
684
Op : ovsdb .OperationMutate ,
678
685
Table : "Logical_Switch_Port" ,
679
- Mutations : []ovsdb.Mutation {{Column : "tag " , Mutator : ovsdb .MutateOperationInsert , Value : testOvsSet (t , []int { 5 })}},
686
+ Mutations : []ovsdb.Mutation {{Column : "addresses " , Mutator : ovsdb .MutateOperationInsert , Value : testOvsSet (t , []string { "1.1.1.1" })}},
680
687
Where : []ovsdb.Condition {{Column : "_uuid" , Function : ovsdb .ConditionEqual , Value : ovsdb.UUID {GoUUID : aUUID0 }}},
681
688
},
682
689
},
@@ -777,9 +784,9 @@ func TestAPIMutate(t *testing.T) {
777
784
cond := tt .condition (api )
778
785
ops , err := cond .Mutate (& testObj , tt .mutations ... )
779
786
if tt .err {
780
- assert . NotNil (t , err )
787
+ require . Error (t , err )
781
788
} else {
782
- assert .Nil (t , err )
789
+ require .Nil (t , err )
783
790
assert .ElementsMatchf (t , tt .result , ops , "ovsdb.Operations should match" )
784
791
}
785
792
})
@@ -793,23 +800,23 @@ func TestAPIUpdate(t *testing.T) {
793
800
Name : "lsp0" ,
794
801
Type : "someType" ,
795
802
ExternalIds : map [string ]string {"foo" : "bar" },
796
- Enabled : [] bool { true } ,
797
- Tag : [] int { 1 } ,
803
+ Enabled : & trueVal ,
804
+ Tag : & one ,
798
805
},
799
806
aUUID1 : & testLogicalSwitchPort {
800
807
UUID : aUUID1 ,
801
808
Name : "lsp1" ,
802
809
Type : "someType" ,
803
810
ExternalIds : map [string ]string {"foo" : "baz" },
804
- Tag : [] int { 1 } ,
805
- Enabled : [] bool { true } ,
811
+ Tag : & one ,
812
+ Enabled : & trueVal ,
806
813
},
807
814
aUUID2 : & testLogicalSwitchPort {
808
815
UUID : aUUID2 ,
809
816
Name : "lsp2" ,
810
817
Type : "someOtherType" ,
811
818
ExternalIds : map [string ]string {"foo" : "baz" },
812
- Tag : [] int { 1 } ,
819
+ Tag : & one ,
813
820
},
814
821
}
815
822
testData := cache.Data {
@@ -836,7 +843,7 @@ func TestAPIUpdate(t *testing.T) {
836
843
},
837
844
prepare : func (t * testLogicalSwitchPort ) {
838
845
t .Type = "somethingElse"
839
- t .Tag = [] int { 6 }
846
+ t .Tag = & six
840
847
},
841
848
result : []ovsdb.Operation {
842
849
{
@@ -857,7 +864,7 @@ func TestAPIUpdate(t *testing.T) {
857
864
},
858
865
prepare : func (t * testLogicalSwitchPort ) {
859
866
t .Type = "somethingElse"
860
- t .Tag = [] int { 6 }
867
+ t .Tag = & six
861
868
},
862
869
result : []ovsdb.Operation {
863
870
{
@@ -874,7 +881,7 @@ func TestAPIUpdate(t *testing.T) {
874
881
condition : func (a API ) ConditionalAPI {
875
882
t := testLogicalSwitchPort {
876
883
Type : "sometype" ,
877
- Enabled : [] bool { true } ,
884
+ Enabled : & trueVal ,
878
885
}
879
886
return a .Where (& t , model.Condition {
880
887
Field : & t .Type ,
@@ -883,7 +890,7 @@ func TestAPIUpdate(t *testing.T) {
883
890
})
884
891
},
885
892
prepare : func (t * testLogicalSwitchPort ) {
886
- t .Tag = [] int { 6 }
893
+ t .Tag = & six
887
894
},
888
895
result : []ovsdb.Operation {
889
896
{
@@ -908,11 +915,11 @@ func TestAPIUpdate(t *testing.T) {
908
915
model.Condition {
909
916
Field : & t .Enabled ,
910
917
Function : ovsdb .ConditionIncludes ,
911
- Value : [] bool { true } ,
918
+ Value : & trueVal ,
912
919
})
913
920
},
914
921
prepare : func (t * testLogicalSwitchPort ) {
915
- t .Tag = [] int { 6 }
922
+ t .Tag = & six
916
923
},
917
924
result : []ovsdb.Operation {
918
925
{
@@ -925,7 +932,7 @@ func TestAPIUpdate(t *testing.T) {
925
932
Op : ovsdb .OperationUpdate ,
926
933
Table : "Logical_Switch_Port" ,
927
934
Row : tagRow ,
928
- Where : []ovsdb.Condition {{Column : "enabled" , Function : ovsdb .ConditionIncludes , Value : testOvsSet (t , [] bool { true } )}},
935
+ Where : []ovsdb.Condition {{Column : "enabled" , Function : ovsdb .ConditionIncludes , Value : testOvsSet (t , & trueVal )}},
929
936
},
930
937
},
931
938
err : false ,
@@ -943,11 +950,11 @@ func TestAPIUpdate(t *testing.T) {
943
950
model.Condition {
944
951
Field : & t .Enabled ,
945
952
Function : ovsdb .ConditionIncludes ,
946
- Value : [] bool { true } ,
953
+ Value : & trueVal ,
947
954
})
948
955
},
949
956
prepare : func (t * testLogicalSwitchPort ) {
950
- t .Tag = [] int { 6 }
957
+ t .Tag = & six
951
958
},
952
959
result : []ovsdb.Operation {
953
960
{
@@ -956,7 +963,7 @@ func TestAPIUpdate(t *testing.T) {
956
963
Row : tagRow ,
957
964
Where : []ovsdb.Condition {
958
965
{Column : "type" , Function : ovsdb .ConditionEqual , Value : "sometype" },
959
- {Column : "enabled" , Function : ovsdb .ConditionIncludes , Value : testOvsSet (t , [] bool { true } )},
966
+ {Column : "enabled" , Function : ovsdb .ConditionIncludes , Value : testOvsSet (t , & trueVal )},
960
967
},
961
968
},
962
969
},
@@ -967,7 +974,7 @@ func TestAPIUpdate(t *testing.T) {
967
974
condition : func (a API ) ConditionalAPI {
968
975
t := testLogicalSwitchPort {
969
976
Type : "sometype" ,
970
- Enabled : [] bool { true } ,
977
+ Enabled : & trueVal ,
971
978
}
972
979
return a .Where (& t , model.Condition {
973
980
Field : & t .Type ,
@@ -976,7 +983,7 @@ func TestAPIUpdate(t *testing.T) {
976
983
})
977
984
},
978
985
prepare : func (t * testLogicalSwitchPort ) {
979
- t .Tag = [] int { 6 }
986
+ t .Tag = & six
980
987
},
981
988
result : []ovsdb.Operation {
982
989
{
@@ -992,12 +999,12 @@ func TestAPIUpdate(t *testing.T) {
992
999
name : "select multiple by predicate change multiple field" ,
993
1000
condition : func (a API ) ConditionalAPI {
994
1001
return a .WhereCache (func (t * testLogicalSwitchPort ) bool {
995
- return t .Enabled != nil && t .Enabled [ 0 ] == true
1002
+ return t .Enabled != nil && * t .Enabled == true
996
1003
})
997
1004
},
998
1005
prepare : func (t * testLogicalSwitchPort ) {
999
1006
t .Type = "somethingElse"
1000
- t .Tag = [] int { 6 }
1007
+ t .Tag = & six
1001
1008
},
1002
1009
result : []ovsdb.Operation {
1003
1010
{
@@ -1041,23 +1048,23 @@ func TestAPIDelete(t *testing.T) {
1041
1048
Name : "lsp0" ,
1042
1049
Type : "someType" ,
1043
1050
ExternalIds : map [string ]string {"foo" : "bar" },
1044
- Enabled : [] bool { true } ,
1045
- Tag : [] int { 1 } ,
1051
+ Enabled : & trueVal ,
1052
+ Tag : & one ,
1046
1053
},
1047
1054
aUUID1 : & testLogicalSwitchPort {
1048
1055
UUID : aUUID1 ,
1049
1056
Name : "lsp1" ,
1050
1057
Type : "someType" ,
1051
1058
ExternalIds : map [string ]string {"foo" : "baz" },
1052
- Tag : [] int { 1 } ,
1053
- Enabled : [] bool { true } ,
1059
+ Tag : & one ,
1060
+ Enabled : & trueVal ,
1054
1061
},
1055
1062
aUUID2 : & testLogicalSwitchPort {
1056
1063
UUID : aUUID2 ,
1057
1064
Name : "lsp2" ,
1058
1065
Type : "someOtherType" ,
1059
1066
ExternalIds : map [string ]string {"foo" : "baz" },
1060
- Tag : [] int { 1 } ,
1067
+ Tag : & one ,
1061
1068
},
1062
1069
}
1063
1070
testData := cache.Data {
@@ -1107,7 +1114,7 @@ func TestAPIDelete(t *testing.T) {
1107
1114
name : "select by field equality" ,
1108
1115
condition : func (a API ) ConditionalAPI {
1109
1116
t := testLogicalSwitchPort {
1110
- Enabled : [] bool { true } ,
1117
+ Enabled : & trueVal ,
1111
1118
}
1112
1119
return a .Where (& t , model.Condition {
1113
1120
Field : & t .Type ,
@@ -1128,7 +1135,7 @@ func TestAPIDelete(t *testing.T) {
1128
1135
name : "select any by field " ,
1129
1136
condition : func (a API ) ConditionalAPI {
1130
1137
t := testLogicalSwitchPort {
1131
- Enabled : [] bool { true } ,
1138
+ Enabled : & trueVal ,
1132
1139
}
1133
1140
return a .Where (& t ,
1134
1141
model.Condition {
@@ -1159,7 +1166,7 @@ func TestAPIDelete(t *testing.T) {
1159
1166
name : "select all by field " ,
1160
1167
condition : func (a API ) ConditionalAPI {
1161
1168
t := testLogicalSwitchPort {
1162
- Enabled : [] bool { true } ,
1169
+ Enabled : & trueVal ,
1163
1170
}
1164
1171
return a .WhereAll (& t ,
1165
1172
model.Condition {
@@ -1188,7 +1195,7 @@ func TestAPIDelete(t *testing.T) {
1188
1195
name : "select multiple by predicate" ,
1189
1196
condition : func (a API ) ConditionalAPI {
1190
1197
return a .WhereCache (func (t * testLogicalSwitchPort ) bool {
1191
- return t .Enabled != nil && t .Enabled [ 0 ] == true
1198
+ return t .Enabled != nil && * t .Enabled == true
1192
1199
})
1193
1200
},
1194
1201
result : []ovsdb.Operation {
0 commit comments