citlambda

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2021 License: MIT Imports: 7 Imported by: 0

README

Example

Testing if a Lambda Function exists.

In GO you have an CDK Stack with a simple Lambda Funktion:

	path, err := os.Getwd()
	if err != nil {
		log.Println(err)
	}
	lambdaPath := filepath.Join(path, "lambda")
	awslambda.NewFunction(stack, 
		aws.String("HelloHandler"),
		&awslambda.FunctionProps{
			MemorySize:                   aws.Float64(1024),
			Code:                         awslambda.Code_FromAsset(&lambdaPath, 
				&awss3assets.AssetOptions{}),
			Handler:                      aws.String("hello.handler"),
			Runtime:                      awslambda.Runtime_NODEJS_14_X(),
		})

To test the created physical Function you may write a test:

func TestCitLambda(t *testing.T){

	gotFc, err := citlambda.GetFunctionConfiguration(aws.String("LambdaSimpleStack"),
	aws.String("HelloHandler"))
	assert.Nil(t, err, "GetFunctionConfiguration should return no error")
	expectHandler := "hello.handler"
	assert.Equal(t, &expectHandler, gotFc.Handler )
}

Stack is not deployed

 go test -v

gives

=== RUN   TestCitLambda
FATA[0007] Template LambdaSimpleStack not found
exit status 1
FAIL	lambda-simple	

Stack is deployed

 go test -v

gives

=== RUN   TestCitLambda
--- PASS: TestCitLambda (2.75s)
PASS
ok  	lambda-simple	

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetFunctionConfiguration

func GetFunctionConfiguration(stackname *string, constructID *string) (*types.FunctionConfiguration, error)

func InvokeFunction added in v0.1.13

func InvokeFunction(stackname *string, constructID *string, eventFile *string) (*string, error)

InvokeFunction stackName - name of an CDK deployed Cloudformation Stack constructID - name of the CDK Construct of the Lambda Resource eventFile - local json file, which will be synchronosly send to the Lambda function

func SetClient

func SetClient(c LambdaInterface)

Types

type LambdaInterface

type LambdaInterface interface {
	GetFunction(ctx context.Context,
		params *lambda.GetFunctionInput,
		optFns ...func(*lambda.Options)) (*lambda.GetFunctionOutput, error)
	Invoke(ctx context.Context,
		params *lambda.InvokeInput,
		optFns ...func(*lambda.Options)) (*lambda.InvokeOutput, error)
}

type LambdaInterfaceMock added in v0.1.13

type LambdaInterfaceMock struct {
	// GetFunctionFunc mocks the GetFunction method.
	GetFunctionFunc func(ctx context.Context, params *lambda.GetFunctionInput, optFns ...func(*lambda.Options)) (*lambda.GetFunctionOutput, error)

	// InvokeFunc mocks the Invoke method.
	InvokeFunc func(ctx context.Context, params *lambda.InvokeInput, optFns ...func(*lambda.Options)) (*lambda.InvokeOutput, error)
	// contains filtered or unexported fields
}

LambdaInterfaceMock is a mock implementation of LambdaInterface.

func TestSomethingThatUsesLambdaInterface(t *testing.T) {

	// make and configure a mocked LambdaInterface
	mockedLambdaInterface := &LambdaInterfaceMock{
		GetFunctionFunc: func(ctx context.Context, params *lambda.GetFunctionInput, optFns ...func(*lambda.Options)) (*lambda.GetFunctionOutput, error) {
			panic("mock out the GetFunction method")
		},
		InvokeFunc: func(ctx context.Context, params *lambda.InvokeInput, optFns ...func(*lambda.Options)) (*lambda.InvokeOutput, error) {
			panic("mock out the Invoke method")
		},
	}

	// use mockedLambdaInterface in code that requires LambdaInterface
	// and then make assertions.

}

func (*LambdaInterfaceMock) GetFunction added in v0.1.13

func (mock *LambdaInterfaceMock) GetFunction(ctx context.Context, params *lambda.GetFunctionInput, optFns ...func(*lambda.Options)) (*lambda.GetFunctionOutput, error)

GetFunction calls GetFunctionFunc.

func (*LambdaInterfaceMock) GetFunctionCalls added in v0.1.13

func (mock *LambdaInterfaceMock) GetFunctionCalls() []struct {
	Ctx    context.Context
	Params *lambda.GetFunctionInput
	OptFns []func(*lambda.Options)
}

GetFunctionCalls gets all the calls that were made to GetFunction. Check the length with:

len(mockedLambdaInterface.GetFunctionCalls())

func (*LambdaInterfaceMock) Invoke added in v0.1.13

func (mock *LambdaInterfaceMock) Invoke(ctx context.Context, params *lambda.InvokeInput, optFns ...func(*lambda.Options)) (*lambda.InvokeOutput, error)

Invoke calls InvokeFunc.

func (*LambdaInterfaceMock) InvokeCalls added in v0.1.13

func (mock *LambdaInterfaceMock) InvokeCalls() []struct {
	Ctx    context.Context
	Params *lambda.InvokeInput
	OptFns []func(*lambda.Options)
}

InvokeCalls gets all the calls that were made to Invoke. Check the length with:

len(mockedLambdaInterface.InvokeCalls())

Jump to

Keyboard shortcuts

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