diff --git a/function_test.go b/function_test.go index 8df00db..09f5984 100644 --- a/function_test.go +++ b/function_test.go @@ -3,6 +3,9 @@ package lambroll import ( "os" "testing" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/lambda" ) func TestLoadFunction(t *testing.T) { @@ -62,3 +65,42 @@ func TestLoadFunction(t *testing.T) { t.Log(fn.String()) } } + +func TestNewFunction(t *testing.T) { + conf := &lambda.FunctionConfiguration{ + FunctionName: aws.String("hello"), + MemorySize: aws.Int64(128), + Runtime: aws.String("nodejs14.x"), + Timeout: aws.Int64(3), + Handler: aws.String("index.handler"), + Role: aws.String("arn:aws:iam::0123456789012:role/YOUR_LAMBDA_ROLE_NAME"), + } + tags := map[string]*string{ + "foo": aws.String("bar"), + } + fn := newFunctionFrom(conf, nil, tags) + if *fn.FunctionName != "hello" { + t.Errorf("unexpected function name got %s", *fn.FunctionName) + } + if *fn.MemorySize != 128 { + t.Errorf("unexpected memory size got %d", *fn.MemorySize) + } + if *fn.Runtime != "nodejs14.x" { + t.Errorf("unexpected runtime got %s", *fn.Runtime) + } + if *fn.Timeout != 3 { + t.Errorf("unexpected timeout got %d", *fn.Timeout) + } + if *fn.Handler != "index.handler" { + t.Errorf("unexpected handler got %s", *fn.Handler) + } + if *fn.Role != "arn:aws:iam::0123456789012:role/YOUR_LAMBDA_ROLE_NAME" { + t.Errorf("unexpected role got %s", *fn.Role) + } + if *fn.Tags["foo"] != "bar" { + t.Errorf("unexpected tags got %v", fn.Tags) + } + if fn.SnapStart != nil { + t.Errorf("unexpected snap start got %v", fn.SnapStart) + } +} diff --git a/lambroll.go b/lambroll.go index 4792d9f..a37f72b 100644 --- a/lambroll.go +++ b/lambroll.go @@ -253,10 +253,9 @@ func newFunctionFrom(c *lambda.FunctionConfiguration, code *lambda.FunctionCodeL DeadLetterConfig: c.DeadLetterConfig, FileSystemConfigs: c.FileSystemConfigs, KMSKeyArn: c.KMSKeyArn, - SnapStart: &lambda.SnapStart{ - ApplyOn: c.SnapStart.ApplyOn, - }, + SnapStart: newSnapStart(c.SnapStart), } + if e := c.Environment; e != nil { fn.Environment = &lambda.Environment{ Variables: e.Variables, @@ -290,6 +289,15 @@ func newFunctionFrom(c *lambda.FunctionConfiguration, code *lambda.FunctionCodeL return fn } +func newSnapStart(s *lambda.SnapStartResponse) *lambda.SnapStart { + if s == nil { + return nil + } + return &lambda.SnapStart{ + ApplyOn: s.ApplyOn, + } +} + func exportEnvFile(file string) error { if file == "" { return nil