Skip to content

Commit 0da197c

Browse files
rcohenmaccushing
authored andcommitted
fix for security list set hash function and legacy tests
1 parent 449943e commit 0da197c

File tree

4 files changed

+313
-188
lines changed

4 files changed

+313
-188
lines changed

provider/core_route_table_resource_test.go

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,23 @@ func (s *ResourceCoreRouteTableTestSuite) TestAccResourceCoreRouteTable_basic()
9696
resource.TestCheckResourceAttrSet(s.ResourceName, "vcn_id"),
9797
resource.TestCheckResourceAttrSet(s.ResourceName, "compartment_id"),
9898
resource.TestCheckResourceAttr(s.ResourceName, "state", string(core.RouteTableLifecycleStateAvailable)),
99-
resource.TestCheckResourceAttrSet(s.ResourceName, "route_rules.0.network_entity_id"),
10099
resource.TestCheckResourceAttr(s.ResourceName, "route_rules.#", "1"),
101-
resource.TestCheckResourceAttr(s.ResourceName, "route_rules.0.cidr_block", "0.0.0.0/0"),
100+
CheckResourceSetContainsElementWithProperties(s.ResourceName, "route_rules", map[string]string{
101+
"cidr_block": "0.0.0.0/0",
102+
},
103+
[]string{
104+
"network_entity_id",
105+
}),
102106
resource.TestCheckResourceAttrSet(s.DefaultResourceName, "manage_default_resource_id"),
103107
resource.TestCheckResourceAttr(s.DefaultResourceName, "state", string(core.RouteTableLifecycleStateAvailable)),
104108
resource.TestCheckResourceAttrSet(s.DefaultResourceName, "display_name"),
105-
resource.TestCheckResourceAttrSet(s.DefaultResourceName, "route_rules.0.network_entity_id"),
106109
resource.TestCheckResourceAttr(s.DefaultResourceName, "route_rules.#", "1"),
107-
resource.TestCheckResourceAttr(s.DefaultResourceName, "route_rules.0.cidr_block", "0.0.0.0/0"),
110+
CheckResourceSetContainsElementWithProperties(s.DefaultResourceName, "route_rules", map[string]string{
111+
"cidr_block": "0.0.0.0/0",
112+
},
113+
[]string{
114+
"network_entity_id",
115+
}),
108116
),
109117
},
110118
// verify update
@@ -141,14 +149,34 @@ func (s *ResourceCoreRouteTableTestSuite) TestAccResourceCoreRouteTable_basic()
141149
resource.TestCheckResourceAttrSet(s.ResourceName, "vcn_id"),
142150
resource.TestCheckResourceAttrSet(s.ResourceName, "compartment_id"),
143151
resource.TestCheckResourceAttr(s.ResourceName, "route_rules.#", "2"),
144-
resource.TestCheckResourceAttr(s.ResourceName, "route_rules.0.cidr_block", "0.0.0.0/0"),
145-
resource.TestCheckResourceAttr(s.ResourceName, "route_rules.1.cidr_block", "10.0.0.0/8"),
152+
CheckResourceSetContainsElementWithProperties(s.ResourceName, "route_rules", map[string]string{
153+
"cidr_block": "0.0.0.0/0",
154+
},
155+
[]string{
156+
"network_entity_id",
157+
}),
158+
CheckResourceSetContainsElementWithProperties(s.ResourceName, "route_rules", map[string]string{
159+
"cidr_block": "10.0.0.0/8",
160+
},
161+
[]string{
162+
"network_entity_id",
163+
}),
146164
resource.TestCheckResourceAttr(s.ResourceName, "state", string(core.RouteTableLifecycleStateAvailable)),
147165
resource.TestCheckResourceAttrSet(s.DefaultResourceName, "manage_default_resource_id"),
148166
resource.TestCheckResourceAttr(s.DefaultResourceName, "display_name", "default-tf-route-table"),
149167
resource.TestCheckResourceAttr(s.DefaultResourceName, "route_rules.#", "2"),
150-
resource.TestCheckResourceAttr(s.DefaultResourceName, "route_rules.0.cidr_block", "0.0.0.0/0"),
151-
resource.TestCheckResourceAttr(s.DefaultResourceName, "route_rules.1.cidr_block", "10.0.0.0/8"),
168+
CheckResourceSetContainsElementWithProperties(s.DefaultResourceName, "route_rules", map[string]string{
169+
"cidr_block": "0.0.0.0/0",
170+
},
171+
[]string{
172+
"network_entity_id",
173+
}),
174+
CheckResourceSetContainsElementWithProperties(s.DefaultResourceName, "route_rules", map[string]string{
175+
"cidr_block": "10.0.0.0/8",
176+
},
177+
[]string{
178+
"network_entity_id",
179+
}),
152180
resource.TestCheckResourceAttr(s.DefaultResourceName, "state", string(core.RouteTableLifecycleStateAvailable)),
153181
),
154182
},
@@ -163,9 +191,13 @@ func (s *ResourceCoreRouteTableTestSuite) TestAccResourceCoreRouteTable_basic()
163191
Check: resource.ComposeAggregateTestCheckFunc(
164192
resource.TestCheckResourceAttrSet(s.DefaultResourceName, "manage_default_resource_id"),
165193
resource.TestCheckResourceAttrSet(s.DefaultResourceName, "display_name"),
166-
resource.TestCheckResourceAttrSet(s.DefaultResourceName, "route_rules.0.network_entity_id"),
167194
resource.TestCheckResourceAttr(s.DefaultResourceName, "route_rules.#", "1"),
168-
resource.TestCheckResourceAttr(s.DefaultResourceName, "route_rules.0.cidr_block", "0.0.0.0/0"),
195+
CheckResourceSetContainsElementWithProperties(s.DefaultResourceName, "route_rules", map[string]string{
196+
"cidr_block": "0.0.0.0/0",
197+
},
198+
[]string{
199+
"network_entity_id",
200+
}),
169201
resource.TestCheckResourceAttr(s.DefaultResourceName, "state", string(core.RouteTableLifecycleStateAvailable)),
170202
),
171203
},

provider/core_security_list_resource.go

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -976,10 +976,10 @@ func UdpOptionsToMap(obj *oci_core.UdpOptions) map[string]interface{} {
976976
func egressRuleHashCodeForSets(v interface{}) int {
977977
var buf bytes.Buffer
978978
m := v.(map[string]interface{})
979-
buf.WriteString(fmt.Sprintf("%v-", m["protocol"].(string)))
980-
buf.WriteString(fmt.Sprintf("%v-", m["destination"].(string)))
979+
buf.WriteString(fmt.Sprintf("%v-", m["protocol"]))
980+
buf.WriteString(fmt.Sprintf("%v-", m["destination"]))
981981
if destinationType, destinationTypePresent := m["destination_type"]; destinationTypePresent && destinationType != "" {
982-
buf.WriteString(fmt.Sprintf("%v-", destinationType.(string)))
982+
buf.WriteString(fmt.Sprintf("%v-", destinationType))
983983
} else {
984984
buf.WriteString(fmt.Sprintf("%v-", oci_core.EgressSecurityRuleDestinationTypeCidrBlock))
985985
}
@@ -996,29 +996,29 @@ func egressRuleHashCodeForSets(v interface{}) int {
996996
}
997997
}
998998
if stateless, statelessPresent := m["stateless"]; statelessPresent && stateless != "" {
999-
buf.WriteString(fmt.Sprintf("%v-", stateless.(bool)))
999+
buf.WriteString(fmt.Sprintf("%v-", stateless))
10001000
} else {
10011001
buf.WriteString(fmt.Sprintf("%v-", "false"))
10021002
}
10031003
if tcpOptions, ok := m["tcp_options"]; ok {
10041004
if tmpList := tcpOptions.([]interface{}); len(tmpList) > 0 {
10051005
buf.WriteString("tcp_options-")
10061006
tcpOptionsRaw := tmpList[0].(map[string]interface{})
1007-
if tcpOptionsRaw["max"].(int) != 0 {
1008-
buf.WriteString(fmt.Sprintf("%v-", tcpOptionsRaw["max"].(int)))
1007+
if max, ok := tcpOptionsRaw["max"]; ok {
1008+
buf.WriteString(fmt.Sprintf("%v-", max))
10091009
}
1010-
if tcpOptionsRaw["min"].(int) != 0 {
1011-
buf.WriteString(fmt.Sprintf("%v-", tcpOptionsRaw["min"].(int)))
1010+
if min, ok := tcpOptionsRaw["min"]; ok {
1011+
buf.WriteString(fmt.Sprintf("%v-", min))
10121012
}
10131013

10141014
if sourcePortRange, ok := tcpOptionsRaw["source_port_range"]; ok {
10151015
if tmpList := sourcePortRange.([]interface{}); len(tmpList) > 0 {
10161016
sourcePortRangeRaw := tmpList[0].(map[string]interface{})
1017-
if sourcePortRangeRaw["max"].(int) != 0 {
1018-
buf.WriteString(fmt.Sprintf("%v-", sourcePortRangeRaw["max"].(int)))
1017+
if max, ok := sourcePortRangeRaw["max"]; ok {
1018+
buf.WriteString(fmt.Sprintf("%v-", max))
10191019
}
1020-
if sourcePortRangeRaw["min"].(int) != 0 {
1021-
buf.WriteString(fmt.Sprintf("%v-", sourcePortRangeRaw["min"].(int)))
1020+
if min, ok := sourcePortRangeRaw["min"]; ok {
1021+
buf.WriteString(fmt.Sprintf("%v-", min))
10221022
}
10231023
}
10241024
}
@@ -1028,21 +1028,21 @@ func egressRuleHashCodeForSets(v interface{}) int {
10281028
if tmpList := udpOptions.([]interface{}); len(tmpList) > 0 {
10291029
buf.WriteString("udp_options-")
10301030
udpOptionsRaw := tmpList[0].(map[string]interface{})
1031-
if udpOptionsRaw["max"].(int) != 0 {
1032-
buf.WriteString(fmt.Sprintf("%v-", udpOptionsRaw["max"].(int)))
1031+
if max, ok := udpOptionsRaw["max"]; ok && max != 0 {
1032+
buf.WriteString(fmt.Sprintf("%v-", max))
10331033
}
1034-
if udpOptionsRaw["min"].(int) != 0 {
1035-
buf.WriteString(fmt.Sprintf("%v-", udpOptionsRaw["min"].(int)))
1034+
if min, ok := udpOptionsRaw["min"]; ok && min != 0 {
1035+
buf.WriteString(fmt.Sprintf("%v-", min))
10361036
}
10371037

10381038
if sourcePortRange, ok := udpOptionsRaw["source_port_range"]; ok {
10391039
if tmpList := sourcePortRange.([]interface{}); len(tmpList) > 0 {
10401040
sourcePortRangeRaw := tmpList[0].(map[string]interface{})
1041-
if sourcePortRangeRaw["max"].(int) != 0 {
1042-
buf.WriteString(fmt.Sprintf("%v-", sourcePortRangeRaw["max"].(int)))
1041+
if max, ok := sourcePortRangeRaw["max"]; ok {
1042+
buf.WriteString(fmt.Sprintf("%v-", max))
10431043
}
1044-
if sourcePortRangeRaw["min"].(int) != 0 {
1045-
buf.WriteString(fmt.Sprintf("%v-", sourcePortRangeRaw["min"].(int)))
1044+
if min, ok := sourcePortRangeRaw["min"]; ok {
1045+
buf.WriteString(fmt.Sprintf("%v-", min))
10461046
}
10471047
}
10481048
}
@@ -1066,37 +1066,37 @@ func ingressRuleHashCodeForSets(v interface{}) int {
10661066
}
10671067
}
10681068
}
1069-
buf.WriteString(fmt.Sprintf("%v-", m["protocol"].(string)))
1070-
buf.WriteString(fmt.Sprintf("%v-", m["source"].(string)))
1069+
buf.WriteString(fmt.Sprintf("%v-", m["protocol"]))
1070+
buf.WriteString(fmt.Sprintf("%v-", m["source"]))
10711071
if sourceType, sourceTypePresent := m["source_type"]; sourceTypePresent && sourceType != "" {
1072-
buf.WriteString(fmt.Sprintf("%v-", sourceType.(string)))
1072+
buf.WriteString(fmt.Sprintf("%v-", sourceType))
10731073
} else {
10741074
buf.WriteString(fmt.Sprintf("%v-", oci_core.IngressSecurityRuleSourceTypeCidrBlock))
10751075
}
10761076
if stateless, statelessPresent := m["stateless"]; statelessPresent && stateless != "" {
1077-
buf.WriteString(fmt.Sprintf("%v-", stateless.(bool)))
1077+
buf.WriteString(fmt.Sprintf("%v-", stateless))
10781078
} else {
10791079
buf.WriteString(fmt.Sprintf("%v-", "false"))
10801080
}
10811081
if tcpOptions, ok := m["tcp_options"]; ok {
10821082
if tmpList := tcpOptions.([]interface{}); len(tmpList) > 0 {
10831083
buf.WriteString("tcp_options-")
10841084
tcpOptionsRaw := tmpList[0].(map[string]interface{})
1085-
if tcpOptionsRaw["max"].(int) != 0 {
1086-
buf.WriteString(fmt.Sprintf("%v-", tcpOptionsRaw["max"].(int)))
1085+
if max, ok := tcpOptionsRaw["max"]; ok {
1086+
buf.WriteString(fmt.Sprintf("%v-", max))
10871087
}
1088-
if tcpOptionsRaw["min"].(int) != 0 {
1089-
buf.WriteString(fmt.Sprintf("%v-", tcpOptionsRaw["min"].(int)))
1088+
if min, ok := tcpOptionsRaw["min"]; ok {
1089+
buf.WriteString(fmt.Sprintf("%v-", min))
10901090
}
10911091

10921092
if sourcePortRange, ok := tcpOptionsRaw["source_port_range"]; ok {
10931093
if tmpList := sourcePortRange.([]interface{}); len(tmpList) > 0 {
10941094
sourcePortRangeRaw := tmpList[0].(map[string]interface{})
1095-
if sourcePortRangeRaw["max"].(int) != 0 {
1096-
buf.WriteString(fmt.Sprintf("%v-", sourcePortRangeRaw["max"].(int)))
1095+
if max, ok := sourcePortRangeRaw["max"]; ok {
1096+
buf.WriteString(fmt.Sprintf("%v-", max))
10971097
}
1098-
if sourcePortRangeRaw["min"].(int) != 0 {
1099-
buf.WriteString(fmt.Sprintf("%v-", sourcePortRangeRaw["min"].(int)))
1098+
if min, ok := sourcePortRangeRaw["min"]; ok {
1099+
buf.WriteString(fmt.Sprintf("%v-", min))
11001100
}
11011101
}
11021102
}
@@ -1106,21 +1106,21 @@ func ingressRuleHashCodeForSets(v interface{}) int {
11061106
if tmpList := udpOptions.([]interface{}); len(tmpList) > 0 {
11071107
buf.WriteString("udp_options-")
11081108
udpOptionsRaw := tmpList[0].(map[string]interface{})
1109-
if udpOptionsRaw["max"].(int) != 0 {
1110-
buf.WriteString(fmt.Sprintf("%v-", udpOptionsRaw["max"].(int)))
1109+
if max, ok := udpOptionsRaw["max"]; ok {
1110+
buf.WriteString(fmt.Sprintf("%v-", max))
11111111
}
1112-
if udpOptionsRaw["min"].(int) != 0 {
1113-
buf.WriteString(fmt.Sprintf("%v-", udpOptionsRaw["min"].(int)))
1112+
if min, ok := udpOptionsRaw["min"]; ok {
1113+
buf.WriteString(fmt.Sprintf("%v-", min))
11141114
}
11151115

11161116
if sourcePortRange, ok := udpOptionsRaw["source_port_range"]; ok {
11171117
if tmpList := sourcePortRange.([]interface{}); len(tmpList) > 0 {
11181118
sourcePortRangeRaw := tmpList[0].(map[string]interface{})
1119-
if sourcePortRangeRaw["max"].(int) != 0 {
1120-
buf.WriteString(fmt.Sprintf("%v-", sourcePortRangeRaw["max"].(int)))
1119+
if max, ok := sourcePortRangeRaw["max"]; ok {
1120+
buf.WriteString(fmt.Sprintf("%v-", max))
11211121
}
1122-
if sourcePortRangeRaw["min"].(int) != 0 {
1123-
buf.WriteString(fmt.Sprintf("%v-", sourcePortRangeRaw["min"].(int)))
1122+
if min, ok := sourcePortRangeRaw["min"]; ok {
1123+
buf.WriteString(fmt.Sprintf("%v-", min))
11241124
}
11251125
}
11261126
}

0 commit comments

Comments
 (0)