diff --git a/spinifex/gateway/ec2/eigw/CreateEgressOnlyInternetGateway.go b/spinifex/gateway/ec2/eigw/CreateEgressOnlyInternetGateway.go index 068a50fad..2084499fd 100644 --- a/spinifex/gateway/ec2/eigw/CreateEgressOnlyInternetGateway.go +++ b/spinifex/gateway/ec2/eigw/CreateEgressOnlyInternetGateway.go @@ -9,7 +9,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateCreateEgressOnlyInternetGatewayInput validates the input parameters func ValidateCreateEgressOnlyInternetGatewayInput(input *ec2.CreateEgressOnlyInternetGatewayInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/ec2/eigw/DeleteEgressOnlyInternetGateway.go b/spinifex/gateway/ec2/eigw/DeleteEgressOnlyInternetGateway.go index ec589ae02..1bad9f454 100644 --- a/spinifex/gateway/ec2/eigw/DeleteEgressOnlyInternetGateway.go +++ b/spinifex/gateway/ec2/eigw/DeleteEgressOnlyInternetGateway.go @@ -9,7 +9,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateDeleteEgressOnlyInternetGatewayInput validates the input parameters func ValidateDeleteEgressOnlyInternetGatewayInput(input *ec2.DeleteEgressOnlyInternetGatewayInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/ec2/eigw/DescribeEgressOnlyInternetGateways.go b/spinifex/gateway/ec2/eigw/DescribeEgressOnlyInternetGateways.go index ef3a83909..2616671cb 100644 --- a/spinifex/gateway/ec2/eigw/DescribeEgressOnlyInternetGateways.go +++ b/spinifex/gateway/ec2/eigw/DescribeEgressOnlyInternetGateways.go @@ -9,7 +9,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateDescribeEgressOnlyInternetGatewaysInput validates the input parameters func ValidateDescribeEgressOnlyInternetGatewaysInput(input *ec2.DescribeEgressOnlyInternetGatewaysInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/ec2/eip/AssociateAddress.go b/spinifex/gateway/ec2/eip/AssociateAddress.go index 6e35b82be..89b9d4039 100644 --- a/spinifex/gateway/ec2/eip/AssociateAddress.go +++ b/spinifex/gateway/ec2/eip/AssociateAddress.go @@ -9,7 +9,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateAssociateAddressInput validates the input parameters func ValidateAssociateAddressInput(input *ec2.AssociateAddressInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/ec2/eip/DisassociateAddress.go b/spinifex/gateway/ec2/eip/DisassociateAddress.go index d444fe0e4..2e150f058 100644 --- a/spinifex/gateway/ec2/eip/DisassociateAddress.go +++ b/spinifex/gateway/ec2/eip/DisassociateAddress.go @@ -9,7 +9,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateDisassociateAddressInput validates the input parameters func ValidateDisassociateAddressInput(input *ec2.DisassociateAddressInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/ec2/eip/ReleaseAddress.go b/spinifex/gateway/ec2/eip/ReleaseAddress.go index cdd963731..769130a46 100644 --- a/spinifex/gateway/ec2/eip/ReleaseAddress.go +++ b/spinifex/gateway/ec2/eip/ReleaseAddress.go @@ -9,7 +9,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateReleaseAddressInput validates the input parameters func ValidateReleaseAddressInput(input *ec2.ReleaseAddressInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/ec2/igw/AttachInternetGateway.go b/spinifex/gateway/ec2/igw/AttachInternetGateway.go index e6f42c655..56c66b179 100644 --- a/spinifex/gateway/ec2/igw/AttachInternetGateway.go +++ b/spinifex/gateway/ec2/igw/AttachInternetGateway.go @@ -9,7 +9,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateAttachInternetGatewayInput validates the input parameters func ValidateAttachInternetGatewayInput(input *ec2.AttachInternetGatewayInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/ec2/igw/DeleteInternetGateway.go b/spinifex/gateway/ec2/igw/DeleteInternetGateway.go index 1c8e04092..e7dec8d1a 100644 --- a/spinifex/gateway/ec2/igw/DeleteInternetGateway.go +++ b/spinifex/gateway/ec2/igw/DeleteInternetGateway.go @@ -9,7 +9,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateDeleteInternetGatewayInput validates the input parameters func ValidateDeleteInternetGatewayInput(input *ec2.DeleteInternetGatewayInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/ec2/igw/DetachInternetGateway.go b/spinifex/gateway/ec2/igw/DetachInternetGateway.go index 7603819cd..e468e3b14 100644 --- a/spinifex/gateway/ec2/igw/DetachInternetGateway.go +++ b/spinifex/gateway/ec2/igw/DetachInternetGateway.go @@ -9,7 +9,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateDetachInternetGatewayInput validates the input parameters func ValidateDetachInternetGatewayInput(input *ec2.DetachInternetGatewayInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/ec2/instance/GetConsoleOutput.go b/spinifex/gateway/ec2/instance/GetConsoleOutput.go index a8251245b..edca7b437 100644 --- a/spinifex/gateway/ec2/instance/GetConsoleOutput.go +++ b/spinifex/gateway/ec2/instance/GetConsoleOutput.go @@ -13,7 +13,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateGetConsoleOutputInput validates the input parameters func ValidateGetConsoleOutputInput(input *ec2.GetConsoleOutputInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/ec2/instance/RebootInstances.go b/spinifex/gateway/ec2/instance/RebootInstances.go index ed7ffaf73..9a8b80756 100644 --- a/spinifex/gateway/ec2/instance/RebootInstances.go +++ b/spinifex/gateway/ec2/instance/RebootInstances.go @@ -14,7 +14,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateRebootInstancesInput validates the input parameters func ValidateRebootInstancesInput(input *ec2.RebootInstancesInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/ec2/instance/StartInstances.go b/spinifex/gateway/ec2/instance/StartInstances.go index f4c8da133..2754f2e24 100644 --- a/spinifex/gateway/ec2/instance/StartInstances.go +++ b/spinifex/gateway/ec2/instance/StartInstances.go @@ -17,7 +17,6 @@ type startStoppedInstanceRequest struct { InstanceID string `json:"instance_id"` } -// ValidateStartInstancesInput validates the input parameters func ValidateStartInstancesInput(input *ec2.StartInstancesInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/ec2/instance/StopInstances.go b/spinifex/gateway/ec2/instance/StopInstances.go index 59427ba53..b6929ad3a 100644 --- a/spinifex/gateway/ec2/instance/StopInstances.go +++ b/spinifex/gateway/ec2/instance/StopInstances.go @@ -14,7 +14,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateStopInstancesInput validates the input parameters func ValidateStopInstancesInput(input *ec2.StopInstancesInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/ec2/instance/TerminateInstances.go b/spinifex/gateway/ec2/instance/TerminateInstances.go index 588fc5acc..ea6410081 100644 --- a/spinifex/gateway/ec2/instance/TerminateInstances.go +++ b/spinifex/gateway/ec2/instance/TerminateInstances.go @@ -19,7 +19,6 @@ type terminateStoppedInstanceRequest struct { InstanceID string `json:"instance_id"` } -// ValidateTerminateInstancesInput validates the input parameters func ValidateTerminateInstancesInput(input *ec2.TerminateInstancesInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/ec2/natgw/CreateNatGateway.go b/spinifex/gateway/ec2/natgw/CreateNatGateway.go index 068103397..dab7d0502 100644 --- a/spinifex/gateway/ec2/natgw/CreateNatGateway.go +++ b/spinifex/gateway/ec2/natgw/CreateNatGateway.go @@ -9,10 +9,23 @@ import ( "github.com/nats-io/nats.go" ) +func ValidateCreateNatGatewayInput(input *ec2.CreateNatGatewayInput) error { + if input == nil { + return errors.New(awserrors.ErrorInvalidParameterValue) + } + if input.SubnetId == nil || *input.SubnetId == "" { + return errors.New(awserrors.ErrorMissingParameter) + } + if input.AllocationId == nil || *input.AllocationId == "" { + return errors.New(awserrors.ErrorMissingParameter) + } + return nil +} + func CreateNatGateway(input *ec2.CreateNatGatewayInput, natsConn *nats.Conn, accountID string) (ec2.CreateNatGatewayOutput, error) { var output ec2.CreateNatGatewayOutput - if input == nil { - return output, errors.New(awserrors.ErrorInvalidParameterValue) + if err := ValidateCreateNatGatewayInput(input); err != nil { + return output, err } svc := handlers_ec2_natgw.NewNATSNatGatewayService(natsConn) result, err := svc.CreateNatGateway(input, accountID) diff --git a/spinifex/gateway/ec2/natgw/DeleteNatGateway.go b/spinifex/gateway/ec2/natgw/DeleteNatGateway.go index 19d5322fb..5ee85ffef 100644 --- a/spinifex/gateway/ec2/natgw/DeleteNatGateway.go +++ b/spinifex/gateway/ec2/natgw/DeleteNatGateway.go @@ -9,10 +9,20 @@ import ( "github.com/nats-io/nats.go" ) +func ValidateDeleteNatGatewayInput(input *ec2.DeleteNatGatewayInput) error { + if input == nil { + return errors.New(awserrors.ErrorInvalidParameterValue) + } + if input.NatGatewayId == nil || *input.NatGatewayId == "" { + return errors.New(awserrors.ErrorMissingParameter) + } + return nil +} + func DeleteNatGateway(input *ec2.DeleteNatGatewayInput, natsConn *nats.Conn, accountID string) (ec2.DeleteNatGatewayOutput, error) { var output ec2.DeleteNatGatewayOutput - if input == nil { - return output, errors.New(awserrors.ErrorInvalidParameterValue) + if err := ValidateDeleteNatGatewayInput(input); err != nil { + return output, err } svc := handlers_ec2_natgw.NewNATSNatGatewayService(natsConn) result, err := svc.DeleteNatGateway(input, accountID) diff --git a/spinifex/gateway/ec2/natgw/natgw_test.go b/spinifex/gateway/ec2/natgw/natgw_test.go index ae7b887fe..75a1a22ed 100644 --- a/spinifex/gateway/ec2/natgw/natgw_test.go +++ b/spinifex/gateway/ec2/natgw/natgw_test.go @@ -3,6 +3,7 @@ package gateway_ec2_natgw import ( "testing" + "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" "github.com/mulgadc/spinifex/spinifex/awserrors" "github.com/stretchr/testify/assert" @@ -12,25 +13,78 @@ const testAccountID = "123456789012" // CreateNatGateway tests +func TestValidateCreateNatGatewayInput(t *testing.T) { + tests := []struct { + name string + input *ec2.CreateNatGatewayInput + wantErr string + }{ + {"nil input", nil, awserrors.ErrorInvalidParameterValue}, + {"missing SubnetId", &ec2.CreateNatGatewayInput{AllocationId: aws.String("eipalloc-1")}, awserrors.ErrorMissingParameter}, + {"empty SubnetId", &ec2.CreateNatGatewayInput{SubnetId: aws.String(""), AllocationId: aws.String("eipalloc-1")}, awserrors.ErrorMissingParameter}, + {"missing AllocationId", &ec2.CreateNatGatewayInput{SubnetId: aws.String("subnet-1")}, awserrors.ErrorMissingParameter}, + {"empty AllocationId", &ec2.CreateNatGatewayInput{SubnetId: aws.String("subnet-1"), AllocationId: aws.String("")}, awserrors.ErrorMissingParameter}, + {"valid input", &ec2.CreateNatGatewayInput{SubnetId: aws.String("subnet-1"), AllocationId: aws.String("eipalloc-1")}, ""}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := ValidateCreateNatGatewayInput(tt.input) + if tt.wantErr == "" { + assert.NoError(t, err) + } else { + assert.EqualError(t, err, tt.wantErr) + } + }) + } +} + func TestCreateNatGateway_NilInput(t *testing.T) { _, err := CreateNatGateway(nil, nil, testAccountID) assert.EqualError(t, err, awserrors.ErrorInvalidParameterValue) } func TestCreateNatGateway_NilNATS(t *testing.T) { - _, err := CreateNatGateway(&ec2.CreateNatGatewayInput{}, nil, testAccountID) + _, err := CreateNatGateway(&ec2.CreateNatGatewayInput{ + SubnetId: aws.String("subnet-1"), + AllocationId: aws.String("eipalloc-1"), + }, nil, testAccountID) assert.Error(t, err) } // DeleteNatGateway tests +func TestValidateDeleteNatGatewayInput(t *testing.T) { + tests := []struct { + name string + input *ec2.DeleteNatGatewayInput + wantErr string + }{ + {"nil input", nil, awserrors.ErrorInvalidParameterValue}, + {"missing NatGatewayId", &ec2.DeleteNatGatewayInput{}, awserrors.ErrorMissingParameter}, + {"empty NatGatewayId", &ec2.DeleteNatGatewayInput{NatGatewayId: aws.String("")}, awserrors.ErrorMissingParameter}, + {"valid input", &ec2.DeleteNatGatewayInput{NatGatewayId: aws.String("nat-1")}, ""}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := ValidateDeleteNatGatewayInput(tt.input) + if tt.wantErr == "" { + assert.NoError(t, err) + } else { + assert.EqualError(t, err, tt.wantErr) + } + }) + } +} + func TestDeleteNatGateway_NilInput(t *testing.T) { _, err := DeleteNatGateway(nil, nil, testAccountID) assert.EqualError(t, err, awserrors.ErrorInvalidParameterValue) } func TestDeleteNatGateway_NilNATS(t *testing.T) { - _, err := DeleteNatGateway(&ec2.DeleteNatGatewayInput{}, nil, testAccountID) + _, err := DeleteNatGateway(&ec2.DeleteNatGatewayInput{ + NatGatewayId: aws.String("nat-1"), + }, nil, testAccountID) assert.Error(t, err) } diff --git a/spinifex/gateway/ec2/placementgroup/CreatePlacementGroup.go b/spinifex/gateway/ec2/placementgroup/CreatePlacementGroup.go index 36bd3887e..5dcad6506 100644 --- a/spinifex/gateway/ec2/placementgroup/CreatePlacementGroup.go +++ b/spinifex/gateway/ec2/placementgroup/CreatePlacementGroup.go @@ -9,7 +9,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateCreatePlacementGroupInput validates the input parameters func ValidateCreatePlacementGroupInput(input *ec2.CreatePlacementGroupInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/ec2/placementgroup/DeletePlacementGroup.go b/spinifex/gateway/ec2/placementgroup/DeletePlacementGroup.go index 36bb4c0f5..39c009b7d 100644 --- a/spinifex/gateway/ec2/placementgroup/DeletePlacementGroup.go +++ b/spinifex/gateway/ec2/placementgroup/DeletePlacementGroup.go @@ -9,7 +9,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateDeletePlacementGroupInput validates the input parameters func ValidateDeletePlacementGroupInput(input *ec2.DeletePlacementGroupInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/ec2/routetable/AssociateRouteTable.go b/spinifex/gateway/ec2/routetable/AssociateRouteTable.go index 7379658f8..eb99ece7f 100644 --- a/spinifex/gateway/ec2/routetable/AssociateRouteTable.go +++ b/spinifex/gateway/ec2/routetable/AssociateRouteTable.go @@ -9,10 +9,23 @@ import ( "github.com/nats-io/nats.go" ) +func ValidateAssociateRouteTableInput(input *ec2.AssociateRouteTableInput) error { + if input == nil { + return errors.New(awserrors.ErrorInvalidParameterValue) + } + if input.RouteTableId == nil || *input.RouteTableId == "" { + return errors.New(awserrors.ErrorMissingParameter) + } + if input.SubnetId == nil || *input.SubnetId == "" { + return errors.New(awserrors.ErrorMissingParameter) + } + return nil +} + func AssociateRouteTable(input *ec2.AssociateRouteTableInput, natsConn *nats.Conn, accountID string) (ec2.AssociateRouteTableOutput, error) { var output ec2.AssociateRouteTableOutput - if input == nil { - return output, errors.New(awserrors.ErrorInvalidParameterValue) + if err := ValidateAssociateRouteTableInput(input); err != nil { + return output, err } svc := handlers_ec2_routetable.NewNATSRouteTableService(natsConn) result, err := svc.AssociateRouteTable(input, accountID) diff --git a/spinifex/gateway/ec2/routetable/CreateRoute.go b/spinifex/gateway/ec2/routetable/CreateRoute.go index 9acd1527c..8d89b5f1c 100644 --- a/spinifex/gateway/ec2/routetable/CreateRoute.go +++ b/spinifex/gateway/ec2/routetable/CreateRoute.go @@ -9,10 +9,23 @@ import ( "github.com/nats-io/nats.go" ) +func ValidateCreateRouteInput(input *ec2.CreateRouteInput) error { + if input == nil { + return errors.New(awserrors.ErrorInvalidParameterValue) + } + if input.RouteTableId == nil || *input.RouteTableId == "" { + return errors.New(awserrors.ErrorMissingParameter) + } + if input.DestinationCidrBlock == nil || *input.DestinationCidrBlock == "" { + return errors.New(awserrors.ErrorMissingParameter) + } + return nil +} + func CreateRoute(input *ec2.CreateRouteInput, natsConn *nats.Conn, accountID string) (ec2.CreateRouteOutput, error) { var output ec2.CreateRouteOutput - if input == nil { - return output, errors.New(awserrors.ErrorInvalidParameterValue) + if err := ValidateCreateRouteInput(input); err != nil { + return output, err } svc := handlers_ec2_routetable.NewNATSRouteTableService(natsConn) result, err := svc.CreateRoute(input, accountID) diff --git a/spinifex/gateway/ec2/routetable/CreateRouteTable.go b/spinifex/gateway/ec2/routetable/CreateRouteTable.go index 018e58729..57a315ea2 100644 --- a/spinifex/gateway/ec2/routetable/CreateRouteTable.go +++ b/spinifex/gateway/ec2/routetable/CreateRouteTable.go @@ -9,10 +9,20 @@ import ( "github.com/nats-io/nats.go" ) +func ValidateCreateRouteTableInput(input *ec2.CreateRouteTableInput) error { + if input == nil { + return errors.New(awserrors.ErrorInvalidParameterValue) + } + if input.VpcId == nil || *input.VpcId == "" { + return errors.New(awserrors.ErrorMissingParameter) + } + return nil +} + func CreateRouteTable(input *ec2.CreateRouteTableInput, natsConn *nats.Conn, accountID string) (ec2.CreateRouteTableOutput, error) { var output ec2.CreateRouteTableOutput - if input == nil { - return output, errors.New(awserrors.ErrorInvalidParameterValue) + if err := ValidateCreateRouteTableInput(input); err != nil { + return output, err } svc := handlers_ec2_routetable.NewNATSRouteTableService(natsConn) result, err := svc.CreateRouteTable(input, accountID) diff --git a/spinifex/gateway/ec2/routetable/DeleteRoute.go b/spinifex/gateway/ec2/routetable/DeleteRoute.go index 0c3a471d7..c12ed369f 100644 --- a/spinifex/gateway/ec2/routetable/DeleteRoute.go +++ b/spinifex/gateway/ec2/routetable/DeleteRoute.go @@ -9,10 +9,23 @@ import ( "github.com/nats-io/nats.go" ) +func ValidateDeleteRouteInput(input *ec2.DeleteRouteInput) error { + if input == nil { + return errors.New(awserrors.ErrorInvalidParameterValue) + } + if input.RouteTableId == nil || *input.RouteTableId == "" { + return errors.New(awserrors.ErrorMissingParameter) + } + if input.DestinationCidrBlock == nil || *input.DestinationCidrBlock == "" { + return errors.New(awserrors.ErrorMissingParameter) + } + return nil +} + func DeleteRoute(input *ec2.DeleteRouteInput, natsConn *nats.Conn, accountID string) (ec2.DeleteRouteOutput, error) { var output ec2.DeleteRouteOutput - if input == nil { - return output, errors.New(awserrors.ErrorInvalidParameterValue) + if err := ValidateDeleteRouteInput(input); err != nil { + return output, err } svc := handlers_ec2_routetable.NewNATSRouteTableService(natsConn) result, err := svc.DeleteRoute(input, accountID) diff --git a/spinifex/gateway/ec2/routetable/DeleteRouteTable.go b/spinifex/gateway/ec2/routetable/DeleteRouteTable.go index ba3cbb384..a903e0e9b 100644 --- a/spinifex/gateway/ec2/routetable/DeleteRouteTable.go +++ b/spinifex/gateway/ec2/routetable/DeleteRouteTable.go @@ -9,10 +9,20 @@ import ( "github.com/nats-io/nats.go" ) +func ValidateDeleteRouteTableInput(input *ec2.DeleteRouteTableInput) error { + if input == nil { + return errors.New(awserrors.ErrorInvalidParameterValue) + } + if input.RouteTableId == nil || *input.RouteTableId == "" { + return errors.New(awserrors.ErrorMissingParameter) + } + return nil +} + func DeleteRouteTable(input *ec2.DeleteRouteTableInput, natsConn *nats.Conn, accountID string) (ec2.DeleteRouteTableOutput, error) { var output ec2.DeleteRouteTableOutput - if input == nil { - return output, errors.New(awserrors.ErrorInvalidParameterValue) + if err := ValidateDeleteRouteTableInput(input); err != nil { + return output, err } svc := handlers_ec2_routetable.NewNATSRouteTableService(natsConn) result, err := svc.DeleteRouteTable(input, accountID) diff --git a/spinifex/gateway/ec2/routetable/DisassociateRouteTable.go b/spinifex/gateway/ec2/routetable/DisassociateRouteTable.go index 1c952e95a..e650b3ff5 100644 --- a/spinifex/gateway/ec2/routetable/DisassociateRouteTable.go +++ b/spinifex/gateway/ec2/routetable/DisassociateRouteTable.go @@ -9,10 +9,20 @@ import ( "github.com/nats-io/nats.go" ) +func ValidateDisassociateRouteTableInput(input *ec2.DisassociateRouteTableInput) error { + if input == nil { + return errors.New(awserrors.ErrorInvalidParameterValue) + } + if input.AssociationId == nil || *input.AssociationId == "" { + return errors.New(awserrors.ErrorMissingParameter) + } + return nil +} + func DisassociateRouteTable(input *ec2.DisassociateRouteTableInput, natsConn *nats.Conn, accountID string) (ec2.DisassociateRouteTableOutput, error) { var output ec2.DisassociateRouteTableOutput - if input == nil { - return output, errors.New(awserrors.ErrorInvalidParameterValue) + if err := ValidateDisassociateRouteTableInput(input); err != nil { + return output, err } svc := handlers_ec2_routetable.NewNATSRouteTableService(natsConn) result, err := svc.DisassociateRouteTable(input, accountID) diff --git a/spinifex/gateway/ec2/routetable/ReplaceRoute.go b/spinifex/gateway/ec2/routetable/ReplaceRoute.go index 2b4705573..60bb7297a 100644 --- a/spinifex/gateway/ec2/routetable/ReplaceRoute.go +++ b/spinifex/gateway/ec2/routetable/ReplaceRoute.go @@ -9,10 +9,23 @@ import ( "github.com/nats-io/nats.go" ) +func ValidateReplaceRouteInput(input *ec2.ReplaceRouteInput) error { + if input == nil { + return errors.New(awserrors.ErrorInvalidParameterValue) + } + if input.RouteTableId == nil || *input.RouteTableId == "" { + return errors.New(awserrors.ErrorMissingParameter) + } + if input.DestinationCidrBlock == nil || *input.DestinationCidrBlock == "" { + return errors.New(awserrors.ErrorMissingParameter) + } + return nil +} + func ReplaceRoute(input *ec2.ReplaceRouteInput, natsConn *nats.Conn, accountID string) (ec2.ReplaceRouteOutput, error) { var output ec2.ReplaceRouteOutput - if input == nil { - return output, errors.New(awserrors.ErrorInvalidParameterValue) + if err := ValidateReplaceRouteInput(input); err != nil { + return output, err } svc := handlers_ec2_routetable.NewNATSRouteTableService(natsConn) result, err := svc.ReplaceRoute(input, accountID) diff --git a/spinifex/gateway/ec2/routetable/ReplaceRouteTableAssociation.go b/spinifex/gateway/ec2/routetable/ReplaceRouteTableAssociation.go index 8e2b3d90c..01556f5ef 100644 --- a/spinifex/gateway/ec2/routetable/ReplaceRouteTableAssociation.go +++ b/spinifex/gateway/ec2/routetable/ReplaceRouteTableAssociation.go @@ -9,10 +9,23 @@ import ( "github.com/nats-io/nats.go" ) +func ValidateReplaceRouteTableAssociationInput(input *ec2.ReplaceRouteTableAssociationInput) error { + if input == nil { + return errors.New(awserrors.ErrorInvalidParameterValue) + } + if input.AssociationId == nil || *input.AssociationId == "" { + return errors.New(awserrors.ErrorMissingParameter) + } + if input.RouteTableId == nil || *input.RouteTableId == "" { + return errors.New(awserrors.ErrorMissingParameter) + } + return nil +} + func ReplaceRouteTableAssociation(input *ec2.ReplaceRouteTableAssociationInput, natsConn *nats.Conn, accountID string) (ec2.ReplaceRouteTableAssociationOutput, error) { var output ec2.ReplaceRouteTableAssociationOutput - if input == nil { - return output, errors.New(awserrors.ErrorInvalidParameterValue) + if err := ValidateReplaceRouteTableAssociationInput(input); err != nil { + return output, err } svc := handlers_ec2_routetable.NewNATSRouteTableService(natsConn) result, err := svc.ReplaceRouteTableAssociation(input, accountID) diff --git a/spinifex/gateway/ec2/routetable/routetable_test.go b/spinifex/gateway/ec2/routetable/routetable_test.go index bce6c765e..39abe0db1 100644 --- a/spinifex/gateway/ec2/routetable/routetable_test.go +++ b/spinifex/gateway/ec2/routetable/routetable_test.go @@ -3,6 +3,7 @@ package gateway_ec2_routetable import ( "testing" + "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" "github.com/mulgadc/spinifex/spinifex/awserrors" "github.com/stretchr/testify/assert" @@ -12,25 +13,71 @@ const testAccountID = "123456789012" // CreateRouteTable tests +func TestValidateCreateRouteTableInput(t *testing.T) { + tests := []struct { + name string + input *ec2.CreateRouteTableInput + wantErr string + }{ + {"nil input", nil, awserrors.ErrorInvalidParameterValue}, + {"missing VpcId", &ec2.CreateRouteTableInput{}, awserrors.ErrorMissingParameter}, + {"empty VpcId", &ec2.CreateRouteTableInput{VpcId: aws.String("")}, awserrors.ErrorMissingParameter}, + {"valid input", &ec2.CreateRouteTableInput{VpcId: aws.String("vpc-1")}, ""}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := ValidateCreateRouteTableInput(tt.input) + if tt.wantErr == "" { + assert.NoError(t, err) + } else { + assert.EqualError(t, err, tt.wantErr) + } + }) + } +} + func TestCreateRouteTable_NilInput(t *testing.T) { _, err := CreateRouteTable(nil, nil, testAccountID) assert.EqualError(t, err, awserrors.ErrorInvalidParameterValue) } func TestCreateRouteTable_NilNATS(t *testing.T) { - _, err := CreateRouteTable(&ec2.CreateRouteTableInput{}, nil, testAccountID) + _, err := CreateRouteTable(&ec2.CreateRouteTableInput{VpcId: aws.String("vpc-1")}, nil, testAccountID) assert.Error(t, err) } // DeleteRouteTable tests +func TestValidateDeleteRouteTableInput(t *testing.T) { + tests := []struct { + name string + input *ec2.DeleteRouteTableInput + wantErr string + }{ + {"nil input", nil, awserrors.ErrorInvalidParameterValue}, + {"missing RouteTableId", &ec2.DeleteRouteTableInput{}, awserrors.ErrorMissingParameter}, + {"empty RouteTableId", &ec2.DeleteRouteTableInput{RouteTableId: aws.String("")}, awserrors.ErrorMissingParameter}, + {"valid input", &ec2.DeleteRouteTableInput{RouteTableId: aws.String("rtb-1")}, ""}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := ValidateDeleteRouteTableInput(tt.input) + if tt.wantErr == "" { + assert.NoError(t, err) + } else { + assert.EqualError(t, err, tt.wantErr) + } + }) + } +} + func TestDeleteRouteTable_NilInput(t *testing.T) { _, err := DeleteRouteTable(nil, nil, testAccountID) assert.EqualError(t, err, awserrors.ErrorInvalidParameterValue) } func TestDeleteRouteTable_NilNATS(t *testing.T) { - _, err := DeleteRouteTable(&ec2.DeleteRouteTableInput{}, nil, testAccountID) + _, err := DeleteRouteTable(&ec2.DeleteRouteTableInput{RouteTableId: aws.String("rtb-1")}, nil, testAccountID) assert.Error(t, err) } @@ -48,72 +95,229 @@ func TestDescribeRouteTables_NilNATS(t *testing.T) { // CreateRoute tests +func TestValidateCreateRouteInput(t *testing.T) { + tests := []struct { + name string + input *ec2.CreateRouteInput + wantErr string + }{ + {"nil input", nil, awserrors.ErrorInvalidParameterValue}, + {"missing RouteTableId", &ec2.CreateRouteInput{DestinationCidrBlock: aws.String("0.0.0.0/0")}, awserrors.ErrorMissingParameter}, + {"empty RouteTableId", &ec2.CreateRouteInput{RouteTableId: aws.String(""), DestinationCidrBlock: aws.String("0.0.0.0/0")}, awserrors.ErrorMissingParameter}, + {"missing DestinationCidrBlock", &ec2.CreateRouteInput{RouteTableId: aws.String("rtb-1")}, awserrors.ErrorMissingParameter}, + {"empty DestinationCidrBlock", &ec2.CreateRouteInput{RouteTableId: aws.String("rtb-1"), DestinationCidrBlock: aws.String("")}, awserrors.ErrorMissingParameter}, + {"valid input", &ec2.CreateRouteInput{RouteTableId: aws.String("rtb-1"), DestinationCidrBlock: aws.String("0.0.0.0/0")}, ""}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := ValidateCreateRouteInput(tt.input) + if tt.wantErr == "" { + assert.NoError(t, err) + } else { + assert.EqualError(t, err, tt.wantErr) + } + }) + } +} + func TestCreateRoute_NilInput(t *testing.T) { _, err := CreateRoute(nil, nil, testAccountID) assert.EqualError(t, err, awserrors.ErrorInvalidParameterValue) } func TestCreateRoute_NilNATS(t *testing.T) { - _, err := CreateRoute(&ec2.CreateRouteInput{}, nil, testAccountID) + _, err := CreateRoute(&ec2.CreateRouteInput{ + RouteTableId: aws.String("rtb-1"), + DestinationCidrBlock: aws.String("0.0.0.0/0"), + }, nil, testAccountID) assert.Error(t, err) } // DeleteRoute tests +func TestValidateDeleteRouteInput(t *testing.T) { + tests := []struct { + name string + input *ec2.DeleteRouteInput + wantErr string + }{ + {"nil input", nil, awserrors.ErrorInvalidParameterValue}, + {"missing RouteTableId", &ec2.DeleteRouteInput{DestinationCidrBlock: aws.String("0.0.0.0/0")}, awserrors.ErrorMissingParameter}, + {"missing DestinationCidrBlock", &ec2.DeleteRouteInput{RouteTableId: aws.String("rtb-1")}, awserrors.ErrorMissingParameter}, + {"valid input", &ec2.DeleteRouteInput{RouteTableId: aws.String("rtb-1"), DestinationCidrBlock: aws.String("0.0.0.0/0")}, ""}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := ValidateDeleteRouteInput(tt.input) + if tt.wantErr == "" { + assert.NoError(t, err) + } else { + assert.EqualError(t, err, tt.wantErr) + } + }) + } +} + func TestDeleteRoute_NilInput(t *testing.T) { _, err := DeleteRoute(nil, nil, testAccountID) assert.EqualError(t, err, awserrors.ErrorInvalidParameterValue) } func TestDeleteRoute_NilNATS(t *testing.T) { - _, err := DeleteRoute(&ec2.DeleteRouteInput{}, nil, testAccountID) + _, err := DeleteRoute(&ec2.DeleteRouteInput{ + RouteTableId: aws.String("rtb-1"), + DestinationCidrBlock: aws.String("0.0.0.0/0"), + }, nil, testAccountID) assert.Error(t, err) } // ReplaceRoute tests +func TestValidateReplaceRouteInput(t *testing.T) { + tests := []struct { + name string + input *ec2.ReplaceRouteInput + wantErr string + }{ + {"nil input", nil, awserrors.ErrorInvalidParameterValue}, + {"missing RouteTableId", &ec2.ReplaceRouteInput{DestinationCidrBlock: aws.String("0.0.0.0/0")}, awserrors.ErrorMissingParameter}, + {"missing DestinationCidrBlock", &ec2.ReplaceRouteInput{RouteTableId: aws.String("rtb-1")}, awserrors.ErrorMissingParameter}, + {"valid input", &ec2.ReplaceRouteInput{RouteTableId: aws.String("rtb-1"), DestinationCidrBlock: aws.String("0.0.0.0/0")}, ""}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := ValidateReplaceRouteInput(tt.input) + if tt.wantErr == "" { + assert.NoError(t, err) + } else { + assert.EqualError(t, err, tt.wantErr) + } + }) + } +} + func TestReplaceRoute_NilInput(t *testing.T) { _, err := ReplaceRoute(nil, nil, testAccountID) assert.EqualError(t, err, awserrors.ErrorInvalidParameterValue) } func TestReplaceRoute_NilNATS(t *testing.T) { - _, err := ReplaceRoute(&ec2.ReplaceRouteInput{}, nil, testAccountID) + _, err := ReplaceRoute(&ec2.ReplaceRouteInput{ + RouteTableId: aws.String("rtb-1"), + DestinationCidrBlock: aws.String("0.0.0.0/0"), + }, nil, testAccountID) assert.Error(t, err) } // AssociateRouteTable tests +func TestValidateAssociateRouteTableInput(t *testing.T) { + tests := []struct { + name string + input *ec2.AssociateRouteTableInput + wantErr string + }{ + {"nil input", nil, awserrors.ErrorInvalidParameterValue}, + {"missing RouteTableId", &ec2.AssociateRouteTableInput{SubnetId: aws.String("subnet-1")}, awserrors.ErrorMissingParameter}, + {"missing SubnetId", &ec2.AssociateRouteTableInput{RouteTableId: aws.String("rtb-1")}, awserrors.ErrorMissingParameter}, + {"valid input", &ec2.AssociateRouteTableInput{RouteTableId: aws.String("rtb-1"), SubnetId: aws.String("subnet-1")}, ""}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := ValidateAssociateRouteTableInput(tt.input) + if tt.wantErr == "" { + assert.NoError(t, err) + } else { + assert.EqualError(t, err, tt.wantErr) + } + }) + } +} + func TestAssociateRouteTable_NilInput(t *testing.T) { _, err := AssociateRouteTable(nil, nil, testAccountID) assert.EqualError(t, err, awserrors.ErrorInvalidParameterValue) } func TestAssociateRouteTable_NilNATS(t *testing.T) { - _, err := AssociateRouteTable(&ec2.AssociateRouteTableInput{}, nil, testAccountID) + _, err := AssociateRouteTable(&ec2.AssociateRouteTableInput{ + RouteTableId: aws.String("rtb-1"), + SubnetId: aws.String("subnet-1"), + }, nil, testAccountID) assert.Error(t, err) } // DisassociateRouteTable tests +func TestValidateDisassociateRouteTableInput(t *testing.T) { + tests := []struct { + name string + input *ec2.DisassociateRouteTableInput + wantErr string + }{ + {"nil input", nil, awserrors.ErrorInvalidParameterValue}, + {"missing AssociationId", &ec2.DisassociateRouteTableInput{}, awserrors.ErrorMissingParameter}, + {"empty AssociationId", &ec2.DisassociateRouteTableInput{AssociationId: aws.String("")}, awserrors.ErrorMissingParameter}, + {"valid input", &ec2.DisassociateRouteTableInput{AssociationId: aws.String("rtbassoc-1")}, ""}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := ValidateDisassociateRouteTableInput(tt.input) + if tt.wantErr == "" { + assert.NoError(t, err) + } else { + assert.EqualError(t, err, tt.wantErr) + } + }) + } +} + func TestDisassociateRouteTable_NilInput(t *testing.T) { _, err := DisassociateRouteTable(nil, nil, testAccountID) assert.EqualError(t, err, awserrors.ErrorInvalidParameterValue) } func TestDisassociateRouteTable_NilNATS(t *testing.T) { - _, err := DisassociateRouteTable(&ec2.DisassociateRouteTableInput{}, nil, testAccountID) + _, err := DisassociateRouteTable(&ec2.DisassociateRouteTableInput{ + AssociationId: aws.String("rtbassoc-1"), + }, nil, testAccountID) assert.Error(t, err) } // ReplaceRouteTableAssociation tests +func TestValidateReplaceRouteTableAssociationInput(t *testing.T) { + tests := []struct { + name string + input *ec2.ReplaceRouteTableAssociationInput + wantErr string + }{ + {"nil input", nil, awserrors.ErrorInvalidParameterValue}, + {"missing AssociationId", &ec2.ReplaceRouteTableAssociationInput{RouteTableId: aws.String("rtb-1")}, awserrors.ErrorMissingParameter}, + {"missing RouteTableId", &ec2.ReplaceRouteTableAssociationInput{AssociationId: aws.String("rtbassoc-1")}, awserrors.ErrorMissingParameter}, + {"valid input", &ec2.ReplaceRouteTableAssociationInput{AssociationId: aws.String("rtbassoc-1"), RouteTableId: aws.String("rtb-1")}, ""}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := ValidateReplaceRouteTableAssociationInput(tt.input) + if tt.wantErr == "" { + assert.NoError(t, err) + } else { + assert.EqualError(t, err, tt.wantErr) + } + }) + } +} + func TestReplaceRouteTableAssociation_NilInput(t *testing.T) { _, err := ReplaceRouteTableAssociation(nil, nil, testAccountID) assert.EqualError(t, err, awserrors.ErrorInvalidParameterValue) } func TestReplaceRouteTableAssociation_NilNATS(t *testing.T) { - _, err := ReplaceRouteTableAssociation(&ec2.ReplaceRouteTableAssociationInput{}, nil, testAccountID) + _, err := ReplaceRouteTableAssociation(&ec2.ReplaceRouteTableAssociationInput{ + AssociationId: aws.String("rtbassoc-1"), + RouteTableId: aws.String("rtb-1"), + }, nil, testAccountID) assert.Error(t, err) } diff --git a/spinifex/gateway/ec2/volume/CreateVolume.go b/spinifex/gateway/ec2/volume/CreateVolume.go index a3a253472..288a1971e 100644 --- a/spinifex/gateway/ec2/volume/CreateVolume.go +++ b/spinifex/gateway/ec2/volume/CreateVolume.go @@ -9,7 +9,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateCreateVolumeInput validates the input parameters func ValidateCreateVolumeInput(input *ec2.CreateVolumeInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/ec2/volume/DeleteVolume.go b/spinifex/gateway/ec2/volume/DeleteVolume.go index 7621b3ab9..e52be12fc 100644 --- a/spinifex/gateway/ec2/volume/DeleteVolume.go +++ b/spinifex/gateway/ec2/volume/DeleteVolume.go @@ -10,7 +10,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateDeleteVolumeInput validates the input parameters func ValidateDeleteVolumeInput(input *ec2.DeleteVolumeInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/ec2/volume/DescribeVolumeStatus.go b/spinifex/gateway/ec2/volume/DescribeVolumeStatus.go index 69526c9ce..e5597d62a 100644 --- a/spinifex/gateway/ec2/volume/DescribeVolumeStatus.go +++ b/spinifex/gateway/ec2/volume/DescribeVolumeStatus.go @@ -10,7 +10,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateDescribeVolumeStatusInput validates the input parameters func ValidateDescribeVolumeStatusInput(input *ec2.DescribeVolumeStatusInput) error { if input == nil { return nil diff --git a/spinifex/gateway/ec2/volume/DescribeVolumes.go b/spinifex/gateway/ec2/volume/DescribeVolumes.go index d47b2b10e..82aa8133d 100644 --- a/spinifex/gateway/ec2/volume/DescribeVolumes.go +++ b/spinifex/gateway/ec2/volume/DescribeVolumes.go @@ -10,7 +10,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateDescribeVolumesInput validates the input parameters func ValidateDescribeVolumesInput(input *ec2.DescribeVolumesInput) error { if input == nil { return nil diff --git a/spinifex/gateway/ec2/volume/DescribeVolumesModifications.go b/spinifex/gateway/ec2/volume/DescribeVolumesModifications.go index 8daf2a6ad..0043565e1 100644 --- a/spinifex/gateway/ec2/volume/DescribeVolumesModifications.go +++ b/spinifex/gateway/ec2/volume/DescribeVolumesModifications.go @@ -10,7 +10,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateDescribeVolumesModificationsInput validates the input parameters func ValidateDescribeVolumesModificationsInput(input *ec2.DescribeVolumesModificationsInput) error { if input == nil { return nil diff --git a/spinifex/gateway/ec2/volume/ModifyVolume.go b/spinifex/gateway/ec2/volume/ModifyVolume.go index 22009006a..dfcfb770a 100644 --- a/spinifex/gateway/ec2/volume/ModifyVolume.go +++ b/spinifex/gateway/ec2/volume/ModifyVolume.go @@ -10,7 +10,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateModifyVolumeInput validates the input parameters func ValidateModifyVolumeInput(input *ec2.ModifyVolumeInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/ec2/vpc/CreateNetworkInterface.go b/spinifex/gateway/ec2/vpc/CreateNetworkInterface.go index f7694f8ab..ed740c2de 100644 --- a/spinifex/gateway/ec2/vpc/CreateNetworkInterface.go +++ b/spinifex/gateway/ec2/vpc/CreateNetworkInterface.go @@ -9,7 +9,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateCreateNetworkInterfaceInput validates the input parameters func ValidateCreateNetworkInterfaceInput(input *ec2.CreateNetworkInterfaceInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/ec2/vpc/CreateSubnet.go b/spinifex/gateway/ec2/vpc/CreateSubnet.go index e3281afad..232ea256d 100644 --- a/spinifex/gateway/ec2/vpc/CreateSubnet.go +++ b/spinifex/gateway/ec2/vpc/CreateSubnet.go @@ -9,7 +9,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateCreateSubnetInput validates the input parameters func ValidateCreateSubnetInput(input *ec2.CreateSubnetInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/ec2/vpc/CreateVpc.go b/spinifex/gateway/ec2/vpc/CreateVpc.go index 162bfb55f..57c4f93e1 100644 --- a/spinifex/gateway/ec2/vpc/CreateVpc.go +++ b/spinifex/gateway/ec2/vpc/CreateVpc.go @@ -9,7 +9,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateCreateVpcInput validates the input parameters func ValidateCreateVpcInput(input *ec2.CreateVpcInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/ec2/vpc/DeleteNetworkInterface.go b/spinifex/gateway/ec2/vpc/DeleteNetworkInterface.go index 4c71867da..0a37ed702 100644 --- a/spinifex/gateway/ec2/vpc/DeleteNetworkInterface.go +++ b/spinifex/gateway/ec2/vpc/DeleteNetworkInterface.go @@ -9,7 +9,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateDeleteNetworkInterfaceInput validates the input parameters func ValidateDeleteNetworkInterfaceInput(input *ec2.DeleteNetworkInterfaceInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/ec2/vpc/DeleteSubnet.go b/spinifex/gateway/ec2/vpc/DeleteSubnet.go index 9ad34a6eb..3e7da3992 100644 --- a/spinifex/gateway/ec2/vpc/DeleteSubnet.go +++ b/spinifex/gateway/ec2/vpc/DeleteSubnet.go @@ -9,7 +9,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateDeleteSubnetInput validates the input parameters func ValidateDeleteSubnetInput(input *ec2.DeleteSubnetInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/ec2/vpc/DeleteVpc.go b/spinifex/gateway/ec2/vpc/DeleteVpc.go index 8c2a832e2..5745eb75e 100644 --- a/spinifex/gateway/ec2/vpc/DeleteVpc.go +++ b/spinifex/gateway/ec2/vpc/DeleteVpc.go @@ -9,7 +9,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateDeleteVpcInput validates the input parameters func ValidateDeleteVpcInput(input *ec2.DeleteVpcInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/ec2/vpc/DescribeVpcAttribute.go b/spinifex/gateway/ec2/vpc/DescribeVpcAttribute.go index bb0df28fc..1060a240c 100644 --- a/spinifex/gateway/ec2/vpc/DescribeVpcAttribute.go +++ b/spinifex/gateway/ec2/vpc/DescribeVpcAttribute.go @@ -9,7 +9,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateDescribeVpcAttributeInput validates the input parameters func ValidateDescribeVpcAttributeInput(input *ec2.DescribeVpcAttributeInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/ec2/vpc/ModifyNetworkInterfaceAttribute.go b/spinifex/gateway/ec2/vpc/ModifyNetworkInterfaceAttribute.go index 3769e5e76..260ddd159 100644 --- a/spinifex/gateway/ec2/vpc/ModifyNetworkInterfaceAttribute.go +++ b/spinifex/gateway/ec2/vpc/ModifyNetworkInterfaceAttribute.go @@ -9,7 +9,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateModifyNetworkInterfaceAttributeInput validates the input parameters func ValidateModifyNetworkInterfaceAttributeInput(input *ec2.ModifyNetworkInterfaceAttributeInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) @@ -17,6 +16,9 @@ func ValidateModifyNetworkInterfaceAttributeInput(input *ec2.ModifyNetworkInterf if input.NetworkInterfaceId == nil || *input.NetworkInterfaceId == "" { return errors.New(awserrors.ErrorMissingParameter) } + if len(input.Groups) == 0 && input.Description == nil { + return errors.New(awserrors.ErrorInvalidParameterValue) + } return nil } diff --git a/spinifex/gateway/ec2/vpc/ModifyNetworkInterfaceAttribute_test.go b/spinifex/gateway/ec2/vpc/ModifyNetworkInterfaceAttribute_test.go index 2012dc99a..c9c19b9ed 100644 --- a/spinifex/gateway/ec2/vpc/ModifyNetworkInterfaceAttribute_test.go +++ b/spinifex/gateway/ec2/vpc/ModifyNetworkInterfaceAttribute_test.go @@ -26,9 +26,17 @@ func TestModifyNetworkInterfaceAttribute_EmptyNetworkInterfaceId(t *testing.T) { assert.EqualError(t, err, awserrors.ErrorMissingParameter) } -func TestModifyNetworkInterfaceAttribute_NilNATS(t *testing.T) { +func TestModifyNetworkInterfaceAttribute_NoAttributes(t *testing.T) { _, err := ModifyNetworkInterfaceAttribute(&ec2.ModifyNetworkInterfaceAttributeInput{ NetworkInterfaceId: aws.String("eni-abc123"), }, nil, "123456789012") + assert.EqualError(t, err, awserrors.ErrorInvalidParameterValue) +} + +func TestModifyNetworkInterfaceAttribute_NilNATS(t *testing.T) { + _, err := ModifyNetworkInterfaceAttribute(&ec2.ModifyNetworkInterfaceAttributeInput{ + NetworkInterfaceId: aws.String("eni-abc123"), + Description: &ec2.AttributeValue{Value: aws.String("desc")}, + }, nil, "123456789012") assert.Error(t, err) } diff --git a/spinifex/gateway/ec2/vpc/ModifySubnetAttribute.go b/spinifex/gateway/ec2/vpc/ModifySubnetAttribute.go index df3f0195a..234816282 100644 --- a/spinifex/gateway/ec2/vpc/ModifySubnetAttribute.go +++ b/spinifex/gateway/ec2/vpc/ModifySubnetAttribute.go @@ -9,7 +9,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateModifySubnetAttributeInput validates the input parameters func ValidateModifySubnetAttributeInput(input *ec2.ModifySubnetAttributeInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/ec2/vpc/ModifyVpcAttribute.go b/spinifex/gateway/ec2/vpc/ModifyVpcAttribute.go index 2e75f1cd5..c6766edad 100644 --- a/spinifex/gateway/ec2/vpc/ModifyVpcAttribute.go +++ b/spinifex/gateway/ec2/vpc/ModifyVpcAttribute.go @@ -9,7 +9,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateModifyVpcAttributeInput validates the input parameters func ValidateModifyVpcAttributeInput(input *ec2.ModifyVpcAttributeInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/elbv2/CreateListener.go b/spinifex/gateway/elbv2/CreateListener.go index 876deed8a..9e6c9833a 100644 --- a/spinifex/gateway/elbv2/CreateListener.go +++ b/spinifex/gateway/elbv2/CreateListener.go @@ -9,7 +9,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateCreateListenerInput validates the input parameters func ValidateCreateListenerInput(input *elbv2.CreateListenerInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/elbv2/CreateLoadBalancer.go b/spinifex/gateway/elbv2/CreateLoadBalancer.go index aec75e01d..e79226e66 100644 --- a/spinifex/gateway/elbv2/CreateLoadBalancer.go +++ b/spinifex/gateway/elbv2/CreateLoadBalancer.go @@ -9,7 +9,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateCreateLoadBalancerInput validates the input parameters func ValidateCreateLoadBalancerInput(input *elbv2.CreateLoadBalancerInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/elbv2/CreateTargetGroup.go b/spinifex/gateway/elbv2/CreateTargetGroup.go index bb03ed371..b5a09ce98 100644 --- a/spinifex/gateway/elbv2/CreateTargetGroup.go +++ b/spinifex/gateway/elbv2/CreateTargetGroup.go @@ -9,7 +9,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateCreateTargetGroupInput validates the input parameters func ValidateCreateTargetGroupInput(input *elbv2.CreateTargetGroupInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/elbv2/DeleteListener.go b/spinifex/gateway/elbv2/DeleteListener.go index d233adb41..6db99bb62 100644 --- a/spinifex/gateway/elbv2/DeleteListener.go +++ b/spinifex/gateway/elbv2/DeleteListener.go @@ -9,7 +9,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateDeleteListenerInput validates the input parameters func ValidateDeleteListenerInput(input *elbv2.DeleteListenerInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/elbv2/DeleteLoadBalancer.go b/spinifex/gateway/elbv2/DeleteLoadBalancer.go index 3b423c1e1..5a022b124 100644 --- a/spinifex/gateway/elbv2/DeleteLoadBalancer.go +++ b/spinifex/gateway/elbv2/DeleteLoadBalancer.go @@ -9,7 +9,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateDeleteLoadBalancerInput validates the input parameters func ValidateDeleteLoadBalancerInput(input *elbv2.DeleteLoadBalancerInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/elbv2/DeleteTargetGroup.go b/spinifex/gateway/elbv2/DeleteTargetGroup.go index 673fc2d47..3e1eba3b8 100644 --- a/spinifex/gateway/elbv2/DeleteTargetGroup.go +++ b/spinifex/gateway/elbv2/DeleteTargetGroup.go @@ -9,7 +9,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateDeleteTargetGroupInput validates the input parameters func ValidateDeleteTargetGroupInput(input *elbv2.DeleteTargetGroupInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/elbv2/DeregisterTargets.go b/spinifex/gateway/elbv2/DeregisterTargets.go index df101604e..2a16436e7 100644 --- a/spinifex/gateway/elbv2/DeregisterTargets.go +++ b/spinifex/gateway/elbv2/DeregisterTargets.go @@ -9,7 +9,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateDeregisterTargetsInput validates the input parameters func ValidateDeregisterTargetsInput(input *elbv2.DeregisterTargetsInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/elbv2/DescribeLoadBalancerAttributes.go b/spinifex/gateway/elbv2/DescribeLoadBalancerAttributes.go index 59f827d06..0ed9a930f 100644 --- a/spinifex/gateway/elbv2/DescribeLoadBalancerAttributes.go +++ b/spinifex/gateway/elbv2/DescribeLoadBalancerAttributes.go @@ -9,7 +9,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateDescribeLoadBalancerAttributesInput validates the input parameters func ValidateDescribeLoadBalancerAttributesInput(input *elbv2.DescribeLoadBalancerAttributesInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/elbv2/DescribeTargetGroupAttributes.go b/spinifex/gateway/elbv2/DescribeTargetGroupAttributes.go index 5046931a1..2402be09d 100644 --- a/spinifex/gateway/elbv2/DescribeTargetGroupAttributes.go +++ b/spinifex/gateway/elbv2/DescribeTargetGroupAttributes.go @@ -9,7 +9,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateDescribeTargetGroupAttributesInput validates the input parameters func ValidateDescribeTargetGroupAttributesInput(input *elbv2.DescribeTargetGroupAttributesInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/elbv2/DescribeTargetHealth.go b/spinifex/gateway/elbv2/DescribeTargetHealth.go index 62704d0fa..c5a8d5bd6 100644 --- a/spinifex/gateway/elbv2/DescribeTargetHealth.go +++ b/spinifex/gateway/elbv2/DescribeTargetHealth.go @@ -9,7 +9,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateDescribeTargetHealthInput validates the input parameters func ValidateDescribeTargetHealthInput(input *elbv2.DescribeTargetHealthInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/elbv2/GetLBConfig.go b/spinifex/gateway/elbv2/GetLBConfig.go index bea59e4c7..9c5338822 100644 --- a/spinifex/gateway/elbv2/GetLBConfig.go +++ b/spinifex/gateway/elbv2/GetLBConfig.go @@ -8,7 +8,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateGetLBConfigInput validates the input parameters func ValidateGetLBConfigInput(input *handlers_elbv2.GetLBConfigInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/elbv2/LBAgentHeartbeat.go b/spinifex/gateway/elbv2/LBAgentHeartbeat.go index 8ab430a69..2334e70d1 100644 --- a/spinifex/gateway/elbv2/LBAgentHeartbeat.go +++ b/spinifex/gateway/elbv2/LBAgentHeartbeat.go @@ -8,7 +8,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateLBAgentHeartbeatInput validates the input parameters func ValidateLBAgentHeartbeatInput(input *handlers_elbv2.LBAgentHeartbeatInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/elbv2/ModifyLoadBalancerAttributes.go b/spinifex/gateway/elbv2/ModifyLoadBalancerAttributes.go index 39fa656e3..0e57ca24e 100644 --- a/spinifex/gateway/elbv2/ModifyLoadBalancerAttributes.go +++ b/spinifex/gateway/elbv2/ModifyLoadBalancerAttributes.go @@ -9,7 +9,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateModifyLoadBalancerAttributesInput validates the input parameters func ValidateModifyLoadBalancerAttributesInput(input *elbv2.ModifyLoadBalancerAttributesInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/elbv2/ModifyTargetGroupAttributes.go b/spinifex/gateway/elbv2/ModifyTargetGroupAttributes.go index 8f826e28c..f759608db 100644 --- a/spinifex/gateway/elbv2/ModifyTargetGroupAttributes.go +++ b/spinifex/gateway/elbv2/ModifyTargetGroupAttributes.go @@ -9,7 +9,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateModifyTargetGroupAttributesInput validates the input parameters func ValidateModifyTargetGroupAttributesInput(input *elbv2.ModifyTargetGroupAttributesInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue) diff --git a/spinifex/gateway/elbv2/RegisterTargets.go b/spinifex/gateway/elbv2/RegisterTargets.go index 0f116953b..b2e568433 100644 --- a/spinifex/gateway/elbv2/RegisterTargets.go +++ b/spinifex/gateway/elbv2/RegisterTargets.go @@ -9,7 +9,6 @@ import ( "github.com/nats-io/nats.go" ) -// ValidateRegisterTargetsInput validates the input parameters func ValidateRegisterTargetsInput(input *elbv2.RegisterTargetsInput) error { if input == nil { return errors.New(awserrors.ErrorInvalidParameterValue)