Skip to content

Commit

Permalink
Merge pull request #276 from fujiwara/fix-panic-on-init
Browse files Browse the repository at this point in the history
Fix panic on init
  • Loading branch information
fujiwara authored Nov 30, 2022
2 parents 6f3e321 + bc5a49a commit dab5b17
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
42 changes: 42 additions & 0 deletions function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
}
14 changes: 11 additions & 3 deletions lambroll.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit dab5b17

Please sign in to comment.