Skip to content

Commit

Permalink
Add ability to check multiple input/output to golden files tests
Browse files Browse the repository at this point in the history
Signed-off-by: Lucas Thiesen <lucas.thiesen@zalando.de>
  • Loading branch information
lucastt committed Oct 26, 2023
1 parent 9b9f786 commit 4aff9d3
Show file tree
Hide file tree
Showing 36 changed files with 379 additions and 52 deletions.
37 changes: 21 additions & 16 deletions aws/fake/cf.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,28 @@ type CFOutputs struct {

type CFClient struct {
cloudformationiface.CloudFormationAPI
lastStackTemplate string
lastStackParams []*cloudformation.Parameter
lastStackTags []*cloudformation.Tag
Outputs CFOutputs
templateCreationHistory []string
paramCreationHistory [][]*cloudformation.Parameter
tagCreationHistory [][]*cloudformation.Tag
Outputs CFOutputs
}

func (m *CFClient) GetLastStackTemplate() string {
return m.lastStackTemplate
func (m *CFClient) GetTemplateCreationHistory() []string {
return m.templateCreationHistory
}

func (m *CFClient) GetLastStackParams() []*cloudformation.Parameter {
return m.lastStackParams
func (m *CFClient) GetParamCreationHistory() [][]*cloudformation.Parameter {
return m.paramCreationHistory
}

func (m *CFClient) GetLastStackTags() []*cloudformation.Tag {
return m.lastStackTags
func (m *CFClient) GetTagCreationHistory() [][]*cloudformation.Tag {
return m.tagCreationHistory
}

func (m *CFClient) CleanCreationHistory() {
m.paramCreationHistory = [][]*cloudformation.Parameter{}
m.tagCreationHistory = [][]*cloudformation.Tag{}
m.templateCreationHistory = []string{}
}

func (m *CFClient) DescribeStacksPages(in *cloudformation.DescribeStacksInput, fn func(*cloudformation.DescribeStacksOutput, bool) bool) (err error) {
Expand Down Expand Up @@ -62,9 +68,9 @@ func (m *CFClient) DescribeStacks(in *cloudformation.DescribeStacksInput) (*clou
}

func (m *CFClient) CreateStack(params *cloudformation.CreateStackInput) (*cloudformation.CreateStackOutput, error) {
m.lastStackTags = params.Tags
m.lastStackParams = params.Parameters
m.lastStackTemplate = *params.TemplateBody
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.CreateStack.response.(*cloudformation.CreateStackOutput)
if !ok {
Expand All @@ -80,9 +86,8 @@ func MockCSOutput(stackId string) *cloudformation.CreateStackOutput {
}

func (m *CFClient) UpdateStack(params *cloudformation.UpdateStackInput) (*cloudformation.UpdateStackOutput, error) {
m.lastStackTags = params.Tags
m.lastStackParams = params.Parameters
m.lastStackTemplate = *params.TemplateBody
// TODO: Update stack needs another logic to register state update, so createStack and updateStack don't
// mess with each other states.

out, ok := m.Outputs.UpdateStack.response.(*cloudformation.UpdateStackOutput)
if !ok {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
54 changes: 54 additions & 0 deletions testdata/rg_alb/output/params/rg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[
{
"parameterKey": "LoadBalancerSchemeParameter",
"parameterValue": "internet-facing"
},
{
"parameterKey": "LoadBalancerSecurityGroupParameter",
"parameterValue": "42"
},
{
"parameterKey": "LoadBalancerSubnetsParameter",
"parameterValue": "foo1"
},
{
"parameterKey": "TargetGroupVPCIDParameter",
"parameterValue": "1"
},
{
"parameterKey": "TargetGroupTargetPortParameter",
"parameterValue": "0"
},
{
"parameterKey": "ListenerSslPolicyParameter",
"parameterValue": "ELBSecurityPolicy-2016-08"
},
{
"parameterKey": "IpAddressType",
"parameterValue": "ipv4"
},
{
"parameterKey": "Type",
"parameterValue": "application"
},
{
"parameterKey": "HTTP2",
"parameterValue": "true"
},
{
"parameterKey": "TargetGroupHealthCheckPathParameter",
"parameterValue": ""
},
{
"parameterKey": "TargetGroupHealthCheckPortParameter",
"parameterValue": "0"
},
{
"parameterKey": "TargetGroupHealthCheckIntervalParameter",
"parameterValue": "0"
},
{
"parameterKey": "TargetGroupHealthCheckTimeoutParameter",
"parameterValue": "0"
}
]
File renamed without changes.
219 changes: 219 additions & 0 deletions testdata/rg_alb/output/templates/rg.cf
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Load Balancer for Kubernetes Ingress",
"Parameters": {
"HTTP2": {
"Type": "String",
"Default": "true",
"Description": "H2 Enabled"
},
"IpAddressType": {
"Type": "String",
"Default": "ipv4",
"Description": "IP Address Type, 'ipv4' or 'dualstack'"
},
"ListenerSslPolicyParameter": {
"Type": "String",
"Default": "ELBSecurityPolicy-2016-08",
"Description": "The HTTPS SSL Security Policy Name"
},
"LoadBalancerSchemeParameter": {
"Type": "String",
"Default": "internet-facing",
"Description": "The Load Balancer scheme - 'internal' or 'internet-facing'"
},
"LoadBalancerSecurityGroupParameter": {
"Type": "List\u003cAWS::EC2::SecurityGroup::Id\u003e",
"Description": "The security group ID for the Load Balancer"
},
"LoadBalancerSubnetsParameter": {
"Type": "List\u003cAWS::EC2::Subnet::Id\u003e",
"Description": "The list of subnets IDs for the Load Balancer"
},
"TargetGroupHealthCheckIntervalParameter": {
"Type": "Number",
"Default": "10",
"Description": "The healthcheck interval"
},
"TargetGroupHealthCheckPathParameter": {
"Type": "String",
"Default": "/kube-system/healthz",
"Description": "The healthcheck path"
},
"TargetGroupHealthCheckPortParameter": {
"Type": "Number",
"Default": "9999",
"Description": "The healthcheck port"
},
"TargetGroupHealthCheckTimeoutParameter": {
"Type": "Number",
"Default": "5",
"Description": "The healthcheck timeout"
},
"TargetGroupTargetPortParameter": {
"Type": "Number",
"Default": "9999",
"Description": "The target port"
},
"TargetGroupVPCIDParameter": {
"Type": "AWS::EC2::VPC::Id",
"Description": "The VPCID for the TargetGroup"
},
"Type": {
"Type": "String",
"Default": "application",
"Description": "Loadbalancer Type, 'application' or 'network'"
}
},
"Resources": {
"HTTPListener": {
"Type": "AWS::ElasticLoadBalancingV2::Listener",
"Properties": {
"DefaultActions": [
{
"TargetGroupArn": {
"Ref": "TG"
},
"Type": "forward"
}
],
"LoadBalancerArn": {
"Ref": "LB"
},
"Port": 80,
"Protocol": "HTTP"
}
},
"HTTPSListener": {
"Type": "AWS::ElasticLoadBalancingV2::Listener",
"Properties": {
"Certificates": [
{
"CertificateArn": "DUMMY"
}
],
"DefaultActions": [
{
"TargetGroupArn": {
"Ref": "TG"
},
"Type": "forward"
}
],
"LoadBalancerArn": {
"Ref": "LB"
},
"Port": 443,
"Protocol": "HTTPS",
"SslPolicy": {
"Ref": "ListenerSslPolicyParameter"
}
}
},
"HTTPSListenerCertificatefc48082457b770e278fc0bd3d392d127869993166f76e8df57d19a0e662820ea": {
"Type": "AWS::ElasticLoadBalancingV2::ListenerCertificate",
"Properties": {
"Certificates": [
{
"CertificateArn": "DUMMY"
}
],
"ListenerArn": {
"Ref": "HTTPSListener"
}
}
},
"LB": {
"Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
"Properties": {
"IpAddressType": {
"Ref": "IpAddressType"
},
"LoadBalancerAttributes": [
{
"Key": "idle_timeout.timeout_seconds",
"Value": "0"
},
{
"Key": "routing.http2.enabled",
"Value": "true"
},
{
"Key": "access_logs.s3.enabled",
"Value": "false"
}
],
"Scheme": {
"Ref": "LoadBalancerSchemeParameter"
},
"SecurityGroups": {
"Ref": "LoadBalancerSecurityGroupParameter"
},
"Subnets": {
"Ref": "LoadBalancerSubnetsParameter"
},
"Tags": [
{
"Key": "StackName",
"Value": {
"Ref": "AWS::StackName"
}
}
],
"Type": {
"Ref": "Type"
}
}
},
"TG": {
"Type": "AWS::ElasticLoadBalancingV2::TargetGroup",
"Properties": {
"HealthCheckIntervalSeconds": {
"Ref": "TargetGroupHealthCheckIntervalParameter"
},
"HealthCheckPath": {
"Ref": "TargetGroupHealthCheckPathParameter"
},
"HealthCheckPort": {
"Ref": "TargetGroupHealthCheckPortParameter"
},
"HealthCheckProtocol": "HTTP",
"HealthCheckTimeoutSeconds": {
"Ref": "TargetGroupHealthCheckTimeoutParameter"
},
"HealthyThresholdCount": 0,
"Port": {
"Ref": "TargetGroupTargetPortParameter"
},
"Protocol": "HTTP",
"TargetGroupAttributes": [
{
"Key": "deregistration_delay.timeout_seconds",
"Value": "0"
}
],
"UnhealthyThresholdCount": 0,
"VpcId": {
"Ref": "TargetGroupVPCIDParameter"
}
}
}
},
"Outputs": {
"LoadBalancerDNSName": {
"Description": "DNS name for the LoadBalancer",
"Value": {
"Fn::GetAtt": [
"LB",
"DNSName"
]
}
},
"TargetGroupARN": {
"Description": "The ARN of the TargetGroup",
"Value": {
"Ref": "TG"
}
}
}
}
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions testdata/rg_nlb/output/tags/rg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"key": "kubernetes:application",
"value": ""
},{
"key": "kubernetes.io/cluster/aws:123:eu-central-1:kube-1",
"value": "owned"
},{
"key": "ingress:certificate-arn/DUMMY",
"value": "0001-01-01T00:00:00Z"
}
]
File renamed without changes.
Loading

0 comments on commit 4aff9d3

Please sign in to comment.