Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make multiple fields nullable (nilable) in networking interface #451

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

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