Skip to content

Commit

Permalink
Make multiple fields nullable (nilable) in networking interface
Browse files Browse the repository at this point in the history
  • Loading branch information
zliang-akamai committed Jan 17, 2024
1 parent 84a6d48 commit f3c4342
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 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
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 f3c4342

Please sign in to comment.