cit

package module
v0.1.17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2021 License: MIT Imports: 10 Imported by: 0

README

CIT

CDK Infrastructure Testing

Project to support Infrastructure Testing with AWS CDK. You get physical Resource objects from the name of the cdk stack and the constructid.

Overview

See Blog1.

Example

Testing the resulting cidr of an vpc

In Typescript you create a stack named "vpc":

new VpcProjektStack(app, 'vpc', {

And name the construct "baseVPC".

var vpc = new Vpc(this, "baseVPC", {

Now you can test things on the created AWS vpc with a small go programm:

package main

import (
	"testing"
	aws "github.com/aws/aws-sdk-go-v2/aws"
	ec2 "github.com/megaproaktiv/citec2"
	"github.com/stretchr/testify/assert"
)

func TestVpcPro(t *testing.T) {
	
	vpc,err := ec2.GetVpc(aws.String("vpc"), aws.String("baseVPC"))
	assert.Nil(t,err)
	assert.Equal(t, "10.0.96.0/21",*vpc.CidrBlock)
}

Which you call with

go test

Or more verbose

go test -v

"PASS" or "FAIL" will indicate whether the created vpc exists and have this cdr block.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AUTO_INIT bool

initialise clients

Functions

func Autoinit added in v0.1.6

func Autoinit() bool

func ExtractConstructID

func ExtractConstructID(path *string) string

ExtractCounstructid

"aws:cdk:path": "vpc/baseVPC/Resource"

func LogicalIDfromCID

func LogicalIDfromCID(stackContent *string, constructID *string) (*string, error)

LogicalIDfromCID - get logicalID

func PhysicalIDfromCID

func PhysicalIDfromCID(client CloudFormationInterface, stack *string, constructId *string) (*string, error)

PhysicalIDfromCID get AWS physical id from CDK contruct ID stack - Stackname constructID - awssns.NewTopic(stack, jsii.String("MyTopic") << MyTopic

func SetClient added in v0.1.12

func SetClient(c CloudFormationInterface)

Types

type CloudFormationInterface

type CloudFormationInterface interface {
	GetTemplate(ctx context.Context, params *cloudformation.GetTemplateInput, optFns ...func(*cloudformation.Options)) (*cloudformation.GetTemplateOutput, error)
	DescribeStackResource(ctx context.Context, params *cloudformation.DescribeStackResourceInput, optFns ...func(*cloudformation.Options)) (*cloudformation.DescribeStackResourceOutput, error)
}
var CfnClient CloudFormationInterface

type CloudFormationInterfaceMock added in v0.1.13

type CloudFormationInterfaceMock struct {
	// DescribeStackResourceFunc mocks the DescribeStackResource method.
	DescribeStackResourceFunc func(ctx context.Context, params *cloudformation.DescribeStackResourceInput, optFns ...func(*cloudformation.Options)) (*cloudformation.DescribeStackResourceOutput, error)

	// GetTemplateFunc mocks the GetTemplate method.
	GetTemplateFunc func(ctx context.Context, params *cloudformation.GetTemplateInput, optFns ...func(*cloudformation.Options)) (*cloudformation.GetTemplateOutput, error)
	// contains filtered or unexported fields
}

CloudFormationInterfaceMock is a mock implementation of CloudFormationInterface.

    func TestSomethingThatUsesCloudFormationInterface(t *testing.T) {

        // make and configure a mocked CloudFormationInterface
        mockedCloudFormationInterface := &CloudFormationInterfaceMock{
            DescribeStackResourceFunc: func(ctx context.Context, params *cloudformation.DescribeStackResourceInput, optFns ...func(*cloudformation.Options)) (*cloudformation.DescribeStackResourceOutput, error) {
	               panic("mock out the DescribeStackResource method")
            },
            GetTemplateFunc: func(ctx context.Context, params *cloudformation.GetTemplateInput, optFns ...func(*cloudformation.Options)) (*cloudformation.GetTemplateOutput, error) {
	               panic("mock out the GetTemplate method")
            },
        }

        // use mockedCloudFormationInterface in code that requires CloudFormationInterface
        // and then make assertions.

    }

func (*CloudFormationInterfaceMock) DescribeStackResource added in v0.1.13

DescribeStackResource calls DescribeStackResourceFunc.

func (*CloudFormationInterfaceMock) DescribeStackResourceCalls added in v0.1.13

func (mock *CloudFormationInterfaceMock) DescribeStackResourceCalls() []struct {
	Ctx    context.Context
	Params *cloudformation.DescribeStackResourceInput
	OptFns []func(*cloudformation.Options)
}

DescribeStackResourceCalls gets all the calls that were made to DescribeStackResource. Check the length with:

len(mockedCloudFormationInterface.DescribeStackResourceCalls())

func (*CloudFormationInterfaceMock) GetTemplate added in v0.1.13

GetTemplate calls GetTemplateFunc.

func (*CloudFormationInterfaceMock) GetTemplateCalls added in v0.1.13

func (mock *CloudFormationInterfaceMock) GetTemplateCalls() []struct {
	Ctx    context.Context
	Params *cloudformation.GetTemplateInput
	OptFns []func(*cloudformation.Options)
}

GetTemplateCalls gets all the calls that were made to GetTemplate. Check the length with:

len(mockedCloudFormationInterface.GetTemplateCalls())

type Resource

type Resource struct {
	Metadata map[string]interface{} `json:"Metadata,omitempty"`
}

type Resources

type Resources map[string]Resource

type SimpleCfn added in v0.1.15

type SimpleCfn struct {
	StagesAvailable []string `json:"StagesAvailable"`
	TemplateBody    string   `json:"TemplateBody"`
}

type Template

type Template struct {
	AWSTemplateFormatVersion string                 `json:"AWSTemplateFormatVersion,omitempty"`
	Description              string                 `json:"Description,omitempty"`
	Metadata                 map[string]interface{} `json:"Metadata,omitempty"`
	Parameters               map[string]interface{} `json:"Parameters,omitempty"`
	Rules                    map[string]interface{} `json:"Rules,omitempty"`
	Mappings                 map[string]interface{} `json:"Mappings,omitempty"`
	CDKMetadata              map[string]interface{} `json:"CDKMetadata,omitempty"`
	Conditions               map[string]interface{} `json:"Conditions,omitempty"`
	Transform                map[string]interface{} `json:"Transform,omitempty"`
	Resources                Resources              `json:"Resources,omitempty"`
	Outputs                  map[string]interface{} `json:"Outputs,omitempty"`
}

Template Content See https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-anatomy.html and https://github.com/awslabs/goformation/blob/d7193b5126b26a12ad1c810c7c481023cef849d8/cloudformation/template.go#L14

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL