Skip to content

Commit 1d109eb

Browse files
authored
Update the action for golangci-lint (#303)
* update the version of golangci-lint, and switch to using the github action * Actually use the latest * fix new lint errors * split linting into seperate action, go back to installing using curl rather than using the action * fix version * define new ctx key type for entry test * use the key * explicit linters in .golangci
1 parent 9d4fa97 commit 1d109eb

File tree

6 files changed

+50
-19
lines changed

6 files changed

+50
-19
lines changed

.github/workflows/lint.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: tests
2+
on:
3+
push:
4+
pull_request:
5+
6+
jobs:
7+
8+
test:
9+
name: lint
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Set up Go 1.13
13+
uses: actions/setup-go@v1
14+
with:
15+
go-version: 1.13
16+
id: go
17+
18+
- name: Check out code into the Go module directory
19+
uses: actions/checkout@v1
20+
21+
- name: golangci-golint
22+
run: |
23+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.27.0
24+
./bin/golangci-lint run -v ./...
25+

.github/workflows/tests.yml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
jobs:
77

88
test:
9-
name: run tests and lint
9+
name: run tests with code coverage
1010
runs-on: ubuntu-latest
1111
steps:
1212
- name: Set up Go 1.13
@@ -18,17 +18,6 @@ jobs:
1818
- name: Check out code into the Go module directory
1919
uses: actions/checkout@v1
2020

21-
- name: golangci-golint
22-
run: |
23-
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.22.2
24-
./bin/golangci-lint run -v ./...
25-
26-
- name: gofmt check
27-
run: diff -u <(echo -n) <(gofmt -d ./)
28-
29-
- name: go vet
30-
run: go vet -v ./...
31-
3221
- name: go test
3322
run: go test -race -coverprofile=coverage.txt -covermode=atomic ./...
3423

.golangci.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
linters:
2+
disable-all: true
3+
enable:
4+
- gofmt
5+
- errcheck
6+
- deadcode
7+
- gosimple
8+
- govet
9+
- ineffassign
10+
- staticcheck
11+
- structcheck
12+
- typecheck
13+
- unused
14+
- varcheck
15+
116
run:
217
skip-files:
318
# These were code-generated, and cannot be changed without breaking RPC compatability.

lambda/entry_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616
"github.com/stretchr/testify/assert"
1717
)
1818

19+
type ctxTestKey struct{}
20+
1921
func TestStartRuntimeAPIWithContext(t *testing.T) {
2022
server, _ := runtimeAPIServer("null", 1) // serve a single invoke, and then cause an internal error
2123
expected := "expected"
@@ -26,8 +28,8 @@ func TestStartRuntimeAPIWithContext(t *testing.T) {
2628
logFatalf = func(format string, v ...interface{}) {}
2729
defer func() { logFatalf = log.Fatalf }()
2830

29-
StartWithContext(context.WithValue(context.Background(), "key", expected), func(ctx context.Context) error {
30-
actual, _ = ctx.Value("key").(string)
31+
StartWithContext(context.WithValue(context.Background(), ctxTestKey{}, expected), func(ctx context.Context) error {
32+
actual, _ = ctx.Value(ctxTestKey{}).(string)
3133
return nil
3234
})
3335

@@ -40,8 +42,8 @@ func TestStartRPCWithContext(t *testing.T) {
4042
port := getFreeTCPPort()
4143
os.Setenv("_LAMBDA_SERVER_PORT", fmt.Sprintf("%d", port))
4244
defer os.Unsetenv("_LAMBDA_SERVER_PORT")
43-
go StartWithContext(context.WithValue(context.Background(), "key", expected), func(ctx context.Context) error {
44-
actual, _ = ctx.Value("key").(string)
45+
go StartWithContext(context.WithValue(context.Background(), ctxTestKey{}, expected), func(ctx context.Context) error {
46+
actual, _ = ctx.Value(ctxTestKey{}).(string)
4547
return nil
4648
})
4749

lambda/function.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ func (fn *Function) Invoke(req *messages.InvokeRequest, response *messages.Invok
5757
}
5858
invokeContext = lambdacontext.NewContext(invokeContext, lc)
5959

60+
// nolint:staticcheck
6061
invokeContext = context.WithValue(invokeContext, "x-amzn-trace-id", req.XAmznTraceId)
6162
os.Setenv("_X_AMZN_TRACE_ID", req.XAmznTraceId)
6263

lambda/function_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"context"
77
"encoding/json"
88
"errors"
9-
"fmt"
109
"os"
1110
"testing"
1211
"time"
@@ -84,7 +83,7 @@ func TestInvokeWithContext(t *testing.T) {
8483

8584
type CustomError struct{}
8685

87-
func (e CustomError) Error() string { return fmt.Sprintf("Something bad happened!") }
86+
func (e CustomError) Error() string { return "Something bad happened!" }
8887

8988
func TestCustomError(t *testing.T) {
9089

@@ -103,7 +102,7 @@ func TestCustomError(t *testing.T) {
103102

104103
type CustomError2 struct{}
105104

106-
func (e *CustomError2) Error() string { return fmt.Sprintf("Something bad happened!") }
105+
func (e *CustomError2) Error() string { return "Something bad happened!" }
107106

108107
func TestCustomErrorRef(t *testing.T) {
109108

0 commit comments

Comments
 (0)