From 14a256f83c06cecbe19b8b61cc41204954fc1ee7 Mon Sep 17 00:00:00 2001 From: Bhavik Kumar Date: Sun, 12 May 2019 14:53:53 +1200 Subject: [PATCH 1/9] Modify panic test by using a slice of the path directories --- lambda/panic_test.go | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/lambda/panic_test.go b/lambda/panic_test.go index 597e76be..8617fabf 100644 --- a/lambda/panic_test.go +++ b/lambda/panic_test.go @@ -111,26 +111,30 @@ func testRuntimeStackTrace(t *testing.T) { packagePath, err := getPackagePath() assert.NoError(t, err) + // The frame.Path will only contain the last 5 directories + if len(packagePath) >= 5 { + packagePath = packagePath[len(packagePath)-4:] + } + packagePath = append(packagePath, "panic_test.go") + frame := panicInfo.StackTrace[0] - assert.Equal(t, packagePath+"/panic_test.go", frame.Path) + framePaths := strings.Split(frame.Path, "/") + + assert.ElementsMatch(t, framePaths, packagePath) assert.True(t, frame.Line > 0) assert.Equal(t, "testRuntimeStackTrace", frame.Label) } -func getPackagePath() (string, error) { +func getPackagePath() (paths []string, err error) { fullPath, err := os.Getwd() if err != nil { - return "", err + return } - basePath := os.Getenv("GOPATH") - if basePath == "" { - if runtime.GOOS == "windows" { - basePath = os.Getenv("USERPROFILE") + "/go" - } else { - basePath = os.Getenv("HOME") + "/go" - } + if runtime.GOOS == "windows" { + paths = strings.Split(fullPath, "\\") + } else { + paths = strings.Split(fullPath, "/") } - basePath = strings.Split(basePath, ":")[0] - return strings.Replace(fullPath, basePath+"/src/", "", 1), nil + return } From cbadb7afcf6b2594441c96b492bd41542b22a700 Mon Sep 17 00:00:00 2001 From: Bhavik Kumar Date: Sun, 12 May 2019 15:08:12 +1200 Subject: [PATCH 2/9] Add go module files --- go.mod | 10 ++++++++++ go.sum | 4 ++++ 2 files changed, 14 insertions(+) create mode 100644 go.mod create mode 100644 go.sum diff --git a/go.mod b/go.mod new file mode 100644 index 00000000..71fea4a6 --- /dev/null +++ b/go.mod @@ -0,0 +1,10 @@ +module github.com/bhavikkumar/aws-lambda-go + +go 1.12 + +require ( + github.com/davecgh/go-spew v1.1.0 + github.com/pmezard/go-difflib v1.0.0 + github.com/stretchr/testify v1.2.1 + gopkg.in/urfave/cli.v1 v1.20.0 +) diff --git a/go.sum b/go.sum new file mode 100644 index 00000000..349bde24 --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +gopkg.in/urfave/cli.v1 v1.20.0/go.mod h1:vuBzUtMdQeixQj8LVd+/98pzhxNGQoyuPBlsXHOQNO0= From d1794e457d24c9dc5fc1089e034c3c7977cc93e6 Mon Sep 17 00:00:00 2001 From: Bhavik Kumar Date: Sun, 12 May 2019 15:26:34 +1200 Subject: [PATCH 3/9] Add job which uses go modules but is allowed to fail --- .travis.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.travis.yml b/.travis.yml index 153f5c05..b737076a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,6 +17,8 @@ install: matrix: allow_failures: - go: tip + - go: 1.12 + env: GO111MODULE=on fast_finish: true notifications: @@ -34,3 +36,14 @@ script: after_success: - bash <(curl -s https://codecov.io/bash) + +jobs: + include: + - stage: "Go Module" + go: 1.12 + env: GO111MODULE=on + before_install: + - go mod download + install: + - go get golang.org/x/lint/golint + - go get github.com/haya14busa/goverage \ No newline at end of file From fa47d7cdc1af6c0a42383094e4f12ea2c3345737 Mon Sep 17 00:00:00 2001 From: Bhavik Kumar Date: Sun, 12 May 2019 16:46:25 +1200 Subject: [PATCH 4/9] Add test for length and order of the path --- lambda/panic_test.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lambda/panic_test.go b/lambda/panic_test.go index 8617fabf..288b672e 100644 --- a/lambda/panic_test.go +++ b/lambda/panic_test.go @@ -111,15 +111,19 @@ func testRuntimeStackTrace(t *testing.T) { packagePath, err := getPackagePath() assert.NoError(t, err) - // The frame.Path will only contain the last 5 directories + frame := panicInfo.StackTrace[0] + framePaths := strings.Split(frame.Path, "/") + + // The frame.Path will only contain the last 5 directories if there are more than 5 directories. if len(packagePath) >= 5 { packagePath = packagePath[len(packagePath)-4:] } packagePath = append(packagePath, "panic_test.go") - frame := panicInfo.StackTrace[0] - framePaths := strings.Split(frame.Path, "/") - + assert.Len(t, framePaths, len(packagePath)) + for i := range framePaths { + assert.Equal(t, framePaths[i], packagePath[i]) + } assert.ElementsMatch(t, framePaths, packagePath) assert.True(t, frame.Line > 0) assert.Equal(t, "testRuntimeStackTrace", frame.Label) From ef1946c427aa909cbd258f07a5f18a3709faa8a9 Mon Sep 17 00:00:00 2001 From: Bhavik Kumar Date: Sun, 12 May 2019 16:57:43 +1200 Subject: [PATCH 5/9] Simplify testing of frame path to be similar style to original --- lambda/panic_test.go | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/lambda/panic_test.go b/lambda/panic_test.go index 288b672e..07a18b3e 100644 --- a/lambda/panic_test.go +++ b/lambda/panic_test.go @@ -112,33 +112,28 @@ func testRuntimeStackTrace(t *testing.T) { assert.NoError(t, err) frame := panicInfo.StackTrace[0] - framePaths := strings.Split(frame.Path, "/") - // The frame.Path will only contain the last 5 directories if there are more than 5 directories. - if len(packagePath) >= 5 { - packagePath = packagePath[len(packagePath)-4:] - } - packagePath = append(packagePath, "panic_test.go") - - assert.Len(t, framePaths, len(packagePath)) - for i := range framePaths { - assert.Equal(t, framePaths[i], packagePath[i]) - } - assert.ElementsMatch(t, framePaths, packagePath) + assert.Equal(t, frame.Path, packagePath+"/panic_test.go") assert.True(t, frame.Line > 0) assert.Equal(t, "testRuntimeStackTrace", frame.Label) } -func getPackagePath() (paths []string, err error) { +func getPackagePath() (string, error) { fullPath, err := os.Getwd() if err != nil { - return + return "", err } + var paths []string if runtime.GOOS == "windows" { paths = strings.Split(fullPath, "\\") } else { paths = strings.Split(fullPath, "/") } - return + + // The frame.Path will only contain the last 5 directories if there are more than 5 directories. + if len(paths) >= 5 { + paths = paths[len(paths)-4:] + } + return strings.Join(paths, "/"), nil } From 766afd0006880c1b8fb4f76e84a1340719ee64e0 Mon Sep 17 00:00:00 2001 From: Bhavik Kumar Date: Sun, 12 May 2019 16:59:39 +1200 Subject: [PATCH 6/9] Use build matrix for go modules in attempt to speed up the build --- .travis.yml | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index b737076a..d717bfbe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,14 @@ install: - go get github.com/haya14busa/goverage matrix: + include: + - go: 1.12 + env: GO111MODULE=on + before_install: + - go mod download + install: + - go get golang.org/x/lint/golint + - go get github.com/haya14busa/goverage allow_failures: - go: tip - go: 1.12 @@ -35,15 +43,4 @@ script: - golint $LINT_PKGS # lint - ignore failures for now after_success: - - bash <(curl -s https://codecov.io/bash) - -jobs: - include: - - stage: "Go Module" - go: 1.12 - env: GO111MODULE=on - before_install: - - go mod download - install: - - go get golang.org/x/lint/golint - - go get github.com/haya14busa/goverage \ No newline at end of file + - bash <(curl -s https://codecov.io/bash) \ No newline at end of file From 6ad0b2a06b4859f7993c2b304dce18da3e510f3a Mon Sep 17 00:00:00 2001 From: Bhavik Kumar Date: Sun, 12 May 2019 17:16:06 +1200 Subject: [PATCH 7/9] Revert accidental line change --- lambda/panic_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lambda/panic_test.go b/lambda/panic_test.go index 07a18b3e..92db8fd7 100644 --- a/lambda/panic_test.go +++ b/lambda/panic_test.go @@ -113,7 +113,7 @@ func testRuntimeStackTrace(t *testing.T) { frame := panicInfo.StackTrace[0] - assert.Equal(t, frame.Path, packagePath+"/panic_test.go") + assert.Equal(t, packagePath+"/panic_test.go", frame.Path) assert.True(t, frame.Line > 0) assert.Equal(t, "testRuntimeStackTrace", frame.Label) } From 4bf2a638ff79183ba90f5b4a56c4edadd338e51d Mon Sep 17 00:00:00 2001 From: Bhavik Kumar Date: Sun, 12 May 2019 17:17:50 +1200 Subject: [PATCH 8/9] Tidy go module files --- go.mod | 5 +++-- go.sum | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 71fea4a6..1f9ee1e3 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,9 @@ module github.com/bhavikkumar/aws-lambda-go go 1.12 require ( - github.com/davecgh/go-spew v1.1.0 - github.com/pmezard/go-difflib v1.0.0 + github.com/aws/aws-lambda-go v1.10.0 + github.com/davecgh/go-spew v1.1.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect github.com/stretchr/testify v1.2.1 gopkg.in/urfave/cli.v1 v1.20.0 ) diff --git a/go.sum b/go.sum index 349bde24..69dd139e 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,10 @@ +github.com/aws/aws-lambda-go v1.10.0 h1:uafgdfYGQD0UeT7d2uKdyWW8j/ZYRifRPIdmeqLzLCk= +github.com/aws/aws-lambda-go v1.10.0/go.mod h1:zUsUQhAUjYzR8AuduJPCfhBuKWUaDbQiPOG+ouzmE1A= +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.2.1 h1:52QO5WkIUcHGIR7EnGagH88x1bUzqGXTC5/1bDTUQ7U= github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +gopkg.in/urfave/cli.v1 v1.20.0 h1:NdAVW6RYxDif9DhDHaAortIu956m2c0v+09AZBPTbE0= gopkg.in/urfave/cli.v1 v1.20.0/go.mod h1:vuBzUtMdQeixQj8LVd+/98pzhxNGQoyuPBlsXHOQNO0= From 63f713a36fefaed638b9655d8d729a2e9b748d78 Mon Sep 17 00:00:00 2001 From: Bhavik Kumar Date: Tue, 14 May 2019 22:12:03 +1200 Subject: [PATCH 9/9] Fix module name --- go.mod | 3 +-- go.sum | 2 -- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 1f9ee1e3..76e68829 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,8 @@ -module github.com/bhavikkumar/aws-lambda-go +module github.com/aws/aws-lambda-go go 1.12 require ( - github.com/aws/aws-lambda-go v1.10.0 github.com/davecgh/go-spew v1.1.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/stretchr/testify v1.2.1 diff --git a/go.sum b/go.sum index 69dd139e..c9a878ca 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,3 @@ -github.com/aws/aws-lambda-go v1.10.0 h1:uafgdfYGQD0UeT7d2uKdyWW8j/ZYRifRPIdmeqLzLCk= -github.com/aws/aws-lambda-go v1.10.0/go.mod h1:zUsUQhAUjYzR8AuduJPCfhBuKWUaDbQiPOG+ouzmE1A= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=