Skip to content

Commit 0bd0c94

Browse files
Make multiple fields nullable (nilable) in networking interface (#451)
* Make multiple fields nullable (nilable) in networking interface * Update test fixtures
1 parent 84a6d48 commit 0bd0c94

9 files changed

+994
-817
lines changed

instance_config_interfaces.go

+6-12
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ type InstanceConfigInterface struct {
1616
Active bool `json:"active"`
1717
VPCID *int `json:"vpc_id"`
1818
SubnetID *int `json:"subnet_id"`
19-
IPv4 VPCIPv4 `json:"ipv4"`
19+
IPv4 *VPCIPv4 `json:"ipv4"`
2020
IPRanges []string `json:"ip_ranges"`
2121
}
2222

2323
type VPCIPv4 struct {
24-
VPC string `json:"vpc,omitempty"`
25-
NAT1To1 string `json:"nat_1_1,omitempty"`
24+
VPC string `json:"vpc,omitempty"`
25+
NAT1To1 *string `json:"nat_1_1,omitempty"`
2626
}
2727

2828
type InstanceConfigInterfaceCreateOptions struct {
@@ -67,20 +67,14 @@ func (i InstanceConfigInterface) GetCreateOptions() InstanceConfigInterfaceCreat
6767
opts.IPRanges = i.IPRanges
6868
}
6969

70-
if i.Purpose == InterfacePurposeVPC &&
71-
i.IPv4.NAT1To1 != "" && i.IPv4.VPC != "" {
70+
if i.Purpose == InterfacePurposeVPC && i.IPv4 != nil {
7271
opts.IPv4 = &VPCIPv4{
7372
VPC: i.IPv4.VPC,
7473
NAT1To1: i.IPv4.NAT1To1,
7574
}
7675
}
7776

78-
// workaround for API issue
79-
if i.IPAMAddress == "222" {
80-
opts.IPAMAddress = ""
81-
} else {
82-
opts.IPAMAddress = i.IPAMAddress
83-
}
77+
opts.IPAMAddress = i.IPAMAddress
8478

8579
return opts
8680
}
@@ -90,7 +84,7 @@ func (i InstanceConfigInterface) GetUpdateOptions() InstanceConfigInterfaceUpdat
9084
Primary: i.Primary,
9185
}
9286

93-
if i.Purpose == InterfacePurposeVPC {
87+
if i.Purpose == InterfacePurposeVPC && i.IPv4 != nil {
9488
opts.IPv4 = &VPCIPv4{
9589
VPC: i.IPv4.VPC,
9690
NAT1To1: i.IPv4.NAT1To1,

test/integration/fixtures/TestInstance_ConfigInterface_Update.yaml

+147-119
Large diffs are not rendered by default.

test/integration/fixtures/TestInstance_ConfigInterfaces_AppendDelete.yaml

+149-121
Large diffs are not rendered by default.

test/integration/fixtures/TestInstance_ConfigInterfaces_List.yaml

+147-122
Large diffs are not rendered by default.

test/integration/fixtures/TestInstance_ConfigInterfaces_Reorder.yaml

+156-127
Large diffs are not rendered by default.

test/integration/fixtures/TestInstance_ConfigInterfaces_Update.yaml

+165-135
Large diffs are not rendered by default.

test/integration/fixtures/TestInstance_Config_Update.yaml

+109-89
Large diffs are not rendered by default.

test/integration/fixtures/TestInstance_Configs_List.yaml

+108-89
Large diffs are not rendered by default.

test/integration/instance_config_test.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ func setupInstanceWith3Interfaces(t *testing.T, fixturesYaml string) (
7878
}
7979

8080
updateConfigOpts := config.GetUpdateOptions()
81+
NAT1To1Any := "any"
8182
updateConfigOpts.Interfaces = []InstanceConfigInterfaceCreateOptions{
8283
{
8384
Purpose: InterfacePurposePublic,
@@ -90,7 +91,7 @@ func setupInstanceWith3Interfaces(t *testing.T, fixturesYaml string) (
9091
Purpose: InterfacePurposeVPC,
9192
SubnetID: &vpcSubnet.ID,
9293
IPv4: &VPCIPv4{
93-
NAT1To1: "any",
94+
NAT1To1: &NAT1To1Any,
9495
},
9596
},
9697
}
@@ -282,6 +283,9 @@ func TestInstance_ConfigInterfaces_Update(t *testing.T) {
282283
{
283284
Purpose: InterfacePurposeVPC,
284285
SubnetID: &vpcSubnet.ID,
286+
IPv4: &VPCIPv4{
287+
VPC: "192.168.0.87",
288+
},
285289
},
286290
}
287291

@@ -370,10 +374,10 @@ func TestInstance_ConfigInterface_Update(t *testing.T) {
370374
if !(updatedIntfc.Primary == updateOpts.Primary) {
371375
t.Errorf("updating interface %v didn't succeed", intfc.ID)
372376
}
373-
377+
NAT1To1Any := "any"
374378
updateOpts.IPv4 = &VPCIPv4{
375379
VPC: "192.168.0.10",
376-
NAT1To1: "any",
380+
NAT1To1: &NAT1To1Any,
377381
}
378382

379383
updatedIntfc, err = client.UpdateInstanceConfigInterface(

0 commit comments

Comments
 (0)