Skip to content

Commit

Permalink
Merge pull request #44 from fujiwara/localstack
Browse files Browse the repository at this point in the history
test on Localstack
  • Loading branch information
fujiwara authored May 25, 2020
2 parents c8e764a + 8080e32 commit 4c36cd5
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 8 deletions.
29 changes: 28 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,20 @@ jobs:
- 1.14
name: Build
runs-on: ubuntu-latest
steps:

services:
localstack:
image: localstack/localstack
env:
SERVICES: lambda,sts,s3
DEFAULT_REGION: ap-northeast-1
DEBUG: 1
LAMBDA_EXECUTOR: local
TEST_AWS_ACCOUNT_ID: 123456789012
ports:
- 4566:4566

steps:
- name: Set up Go
uses: actions/setup-go@v1
with:
Expand All @@ -23,3 +35,18 @@ jobs:
run: |
make clean
make test
- name: deploy test
run: |
make
./cmd/lambroll/lambroll deploy \
--function test/function.json \
--src test/src \
--endpoint http://127.0.0.1:4566 \
--tfstate test/terraform.tfstate \
--log-level debug
env:
FUNCTION_NAME: hello
AWS_REGION: ap-northeast-1
AWS_ACCESS_KEY_ID: dummy
AWS_SECRET_ACCESS_KEY: dummy
2 changes: 1 addition & 1 deletion archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestCreateZipArchive(t *testing.T) {
if err != nil {
t.Error("failed to new zip reader", err)
}
if len(zr.File) != 3 {
if len(zr.File) != 4 {
t.Errorf("unexpected included files num %d expect %d", len(zr.File), 3)
}
for _, f := range zr.File {
Expand Down
9 changes: 5 additions & 4 deletions create.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@ func (app *App) prepareFunctionCodeForDeploy(opt DeployOption, fn *Function) err
info os.FileInfo
)

if fi, err := os.Stat(*opt.Src); err != nil {
return errors.Wrapf(err, "src %s is not found", *opt.Src)
src := *opt.Src
if fi, err := os.Stat(src); err != nil {
return errors.Wrapf(err, "src %s is not found", src)
} else if fi.IsDir() {
zipfile, info, err = createZipArchive(fi.Name(), opt.Excludes)
zipfile, info, err = createZipArchive(src, opt.Excludes)
if err != nil {
return err
}
defer os.Remove(zipfile.Name())
} else if !fi.IsDir() {
zipfile, info, err = loadZipArchive(fi.Name())
zipfile, info, err = loadZipArchive(src)
if err != nil {
return err
}
Expand Down
6 changes: 4 additions & 2 deletions lambroll.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ func New(opt *Option) (*App, error) {
}
if opt.Endpoint != nil && *opt.Endpoint != "" {
customResolverFunc := func(service, region string, optFns ...func(*endpoints.Options)) (endpoints.ResolvedEndpoint, error) {
if service == endpoints.LambdaServiceID {
switch service {
case endpoints.S3ServiceID, endpoints.LambdaServiceID, endpoints.StsServiceID:
return endpoints.ResolvedEndpoint{
URL: *opt.Endpoint,
}, nil
default:
return endpoints.DefaultResolver().EndpointFor(service, region, optFns...)
}
return endpoints.DefaultResolver().EndpointFor(service, region, optFns...)
}
awsCfg.EndpointResolver = endpoints.ResolverFunc(customResolverFunc)
}
Expand Down
4 changes: 4 additions & 0 deletions test/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
exports.handler = async function (event, context) {
console.log("EVENT: \n" + JSON.stringify(event, null, 2))
return context.logStreamName
}

0 comments on commit 4c36cd5

Please sign in to comment.