Skip to content

Commit

Permalink
Make multiple fields nullable (nilable) in networking interface (#451)
Browse files Browse the repository at this point in the history
* Make multiple fields nullable (nilable) in networking interface

* Update test fixtures
  • Loading branch information
zliang-akamai authored Jan 23, 2024
1 parent 84a6d48 commit 0bd0c94
Show file tree
Hide file tree
Showing 9 changed files with 994 additions and 817 deletions.
18 changes: 6 additions & 12 deletions instance_config_interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ type InstanceConfigInterface struct {
Active bool `json:"active"`
VPCID *int `json:"vpc_id"`
SubnetID *int `json:"subnet_id"`
IPv4 VPCIPv4 `json:"ipv4"`
IPv4 *VPCIPv4 `json:"ipv4"`
IPRanges []string `json:"ip_ranges"`
}

type VPCIPv4 struct {
VPC string `json:"vpc,omitempty"`
NAT1To1 string `json:"nat_1_1,omitempty"`
VPC string `json:"vpc,omitempty"`
NAT1To1 *string `json:"nat_1_1,omitempty"`
}

type InstanceConfigInterfaceCreateOptions struct {
Expand Down Expand Up @@ -67,20 +67,14 @@ func (i InstanceConfigInterface) GetCreateOptions() InstanceConfigInterfaceCreat
opts.IPRanges = i.IPRanges
}

if i.Purpose == InterfacePurposeVPC &&
i.IPv4.NAT1To1 != "" && i.IPv4.VPC != "" {
if i.Purpose == InterfacePurposeVPC && i.IPv4 != nil {
opts.IPv4 = &VPCIPv4{
VPC: i.IPv4.VPC,
NAT1To1: i.IPv4.NAT1To1,
}
}

// workaround for API issue
if i.IPAMAddress == "222" {
opts.IPAMAddress = ""
} else {
opts.IPAMAddress = i.IPAMAddress
}
opts.IPAMAddress = i.IPAMAddress

return opts
}
Expand All @@ -90,7 +84,7 @@ func (i InstanceConfigInterface) GetUpdateOptions() InstanceConfigInterfaceUpdat
Primary: i.Primary,
}

if i.Purpose == InterfacePurposeVPC {
if i.Purpose == InterfacePurposeVPC && i.IPv4 != nil {
opts.IPv4 = &VPCIPv4{
VPC: i.IPv4.VPC,
NAT1To1: i.IPv4.NAT1To1,
Expand Down
266 changes: 147 additions & 119 deletions test/integration/fixtures/TestInstance_ConfigInterface_Update.yaml

Large diffs are not rendered by default.

270 changes: 149 additions & 121 deletions test/integration/fixtures/TestInstance_ConfigInterfaces_AppendDelete.yaml

Large diffs are not rendered by default.

269 changes: 147 additions & 122 deletions test/integration/fixtures/TestInstance_ConfigInterfaces_List.yaml

Large diffs are not rendered by default.

283 changes: 156 additions & 127 deletions test/integration/fixtures/TestInstance_ConfigInterfaces_Reorder.yaml

Large diffs are not rendered by default.

300 changes: 165 additions & 135 deletions test/integration/fixtures/TestInstance_ConfigInterfaces_Update.yaml

Large diffs are not rendered by default.

198 changes: 109 additions & 89 deletions test/integration/fixtures/TestInstance_Config_Update.yaml

Large diffs are not rendered by default.

197 changes: 108 additions & 89 deletions test/integration/fixtures/TestInstance_Configs_List.yaml

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions test/integration/instance_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func setupInstanceWith3Interfaces(t *testing.T, fixturesYaml string) (
}

updateConfigOpts := config.GetUpdateOptions()
NAT1To1Any := "any"
updateConfigOpts.Interfaces = []InstanceConfigInterfaceCreateOptions{
{
Purpose: InterfacePurposePublic,
Expand All @@ -90,7 +91,7 @@ func setupInstanceWith3Interfaces(t *testing.T, fixturesYaml string) (
Purpose: InterfacePurposeVPC,
SubnetID: &vpcSubnet.ID,
IPv4: &VPCIPv4{
NAT1To1: "any",
NAT1To1: &NAT1To1Any,
},
},
}
Expand Down Expand Up @@ -282,6 +283,9 @@ func TestInstance_ConfigInterfaces_Update(t *testing.T) {
{
Purpose: InterfacePurposeVPC,
SubnetID: &vpcSubnet.ID,
IPv4: &VPCIPv4{
VPC: "192.168.0.87",
},
},
}

Expand Down Expand Up @@ -370,10 +374,10 @@ func TestInstance_ConfigInterface_Update(t *testing.T) {
if !(updatedIntfc.Primary == updateOpts.Primary) {
t.Errorf("updating interface %v didn't succeed", intfc.ID)
}

NAT1To1Any := "any"
updateOpts.IPv4 = &VPCIPv4{
VPC: "192.168.0.10",
NAT1To1: "any",
NAT1To1: &NAT1To1Any,
}

updatedIntfc, err = client.UpdateInstanceConfigInterface(
Expand Down

0 comments on commit 0bd0c94

Please sign in to comment.