Skip to content

Commit

Permalink
lb: add DescribeLoadBalancer & CreateLoadBalancer
Browse files Browse the repository at this point in the history
these functions should force `doWork` to run `updateStack` function depending on lb state

Signed-off-by: Mustafa Abdelrahman <mustafa.abdelrahman@zalando.de>
  • Loading branch information
MustafaSaber committed Feb 1, 2024
1 parent c530fcd commit 231c031
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
4 changes: 4 additions & 0 deletions aws/fake/cf.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ func (m *CFClient) UpdateStack(params *cloudformation.UpdateStackInput) (*cloudf
// Update stack needs to use different variable to register change history,
// so createStack and updateStack mocks don't mess with each other states.

m.tagCreationHistory = append(m.tagCreationHistory, params.Tags)
m.paramCreationHistory = append(m.paramCreationHistory, params.Parameters)
m.templateCreationHistory = append(m.templateCreationHistory, *params.TemplateBody)

out, ok := m.Outputs.UpdateStack.response.(*cloudformation.UpdateStackOutput)
if !ok {
return nil, m.Outputs.UpdateStack.err
Expand Down
26 changes: 23 additions & 3 deletions aws/fake/elbv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ type ELBv2Outputs struct {
DescribeTags *APIResponse
DescribeTargetGroups *APIResponse
DescribeTargetHealth *APIResponse
CreateLoadBalancer *APIResponse
DescribeLoadBalancer *APIResponse
}

type ELBv2Client struct {
elbv2iface.ELBV2API
Outputs ELBv2Outputs
Rtinputs []*elbv2.RegisterTargetsInput
Dtinputs []*elbv2.DeregisterTargetsInput
Outputs ELBv2Outputs
Rtinputs []*elbv2.RegisterTargetsInput
Dtinputs []*elbv2.DeregisterTargetsInput
LBinputes []*elbv2.CreateLoadBalancerInput
}

func (m *ELBv2Client) RegisterTargets(in *elbv2.RegisterTargetsInput) (*elbv2.RegisterTargetsOutput, error) {
Expand Down Expand Up @@ -67,6 +70,23 @@ func (m *ELBv2Client) DescribeTargetHealth(*elbv2.DescribeTargetHealthInput) (*e
return out, m.Outputs.DescribeTargetHealth.err
}

func (m *ELBv2Client) CreateLoadBalancer(in *elbv2.CreateLoadBalancerInput) (*elbv2.CreateLoadBalancerOutput, error) {
m.LBinputes = append(m.LBinputes, in)
out, ok := m.Outputs.CreateLoadBalancer.response.(*elbv2.CreateLoadBalancerOutput)
if !ok {
return nil, m.Outputs.CreateLoadBalancer.err
}
return out, m.Outputs.CreateLoadBalancer.err
}

func (m *ELBv2Client) DescribeLoadBalancers(in *elbv2.DescribeLoadBalancersInput) (*elbv2.DescribeLoadBalancersOutput, error) {
out, ok := m.Outputs.DescribeLoadBalancer.response.(*elbv2.DescribeLoadBalancersOutput)
if !ok {
return nil, m.Outputs.DescribeLoadBalancer.err
}
return out, m.Outputs.DescribeLoadBalancer.err
}

func MockDeregisterTargetsOutput() *elbv2.DeregisterTargetsOutput {
return &elbv2.DeregisterTargetsOutput{}
}
9 changes: 8 additions & 1 deletion worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ func TestResourceConversionOneToOne(tt *testing.T) {
clusterID := "aws:123:eu-central-1:kube-1"
vpcID := "1"
securityGroupID := "42"
running := int64(16) // See https://github.com/aws/aws-sdk-go/blob/master/service/ec2/api.go, type InstanceState
// See https://github.com/aws/aws-sdk-go/blob/master/service/ec2/api.go, type InstanceState
// * 0 : pending
// * 16 : running
// * 32 : shutting-down
// * 48 : terminated
// * 64 : stopping
// * 80 : stopped
running := int64(16)

for _, scenario := range []struct {
name string
Expand Down

0 comments on commit 231c031

Please sign in to comment.