From 7284f87dae0ae4f3732c3be287948563e2645787 Mon Sep 17 00:00:00 2001 From: Isaac Hall Date: Mon, 31 Jan 2022 09:36:23 -0800 Subject: [PATCH] Add Makefile for test, lint, vet. Fix lint issues. --- .github/workflows/ci.yml | 22 ++++++++++++++++++++++ .travis.yml | 8 ++++++++ Makefile | 13 +++++++++++++ client.go | 7 +++---- client_operations_test.go | 25 ++++++++++++++++--------- client_test.go | 3 +++ logger.go | 1 + 7 files changed, 66 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 Makefile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..3360b45 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,22 @@ +name: CI + +on: + push: + branches: [ master, v3-v2021-02-25 ] + pull_request: + branches: [ master, v3-v2021-02-25 ] + +jobs: + lint: + name: Lint + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@master + + - name: lint + run: | + go get -u honnef.co/go/tools/cmd/staticcheck@latest && + make lint && + make vet diff --git a/.travis.yml b/.travis.yml index e182ec3..a65617f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,3 +2,11 @@ language: go go: - 1.x + +install: + - go get -u honnef.co/go/tools/cmd/staticcheck + +script: + - make lint + - make vet + - make test diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4305240 --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +all: build lint test vet + +build: + go build ./... + +lint: + staticcheck ./... + +test: + go test -race ./... + +vet: + go vet ./... diff --git a/client.go b/client.go index 43ea3c6..926f541 100644 --- a/client.go +++ b/client.go @@ -54,10 +54,9 @@ var ( Transport: defaultTransport, } - acceptVersion = fmt.Sprintf("application/vnd.recurly.%s", APIVersion) - recurlyVersion = fmt.Sprintf("recurly.%s", APIVersion) - userAgent = fmt.Sprintf("Recurly/%s; go %s", clientVersion, runtime.Version()) - pathPattern = regexp.MustCompile(`{[^}]+}`) + acceptVersion = fmt.Sprintf("application/vnd.recurly.%s", APIVersion) + userAgent = fmt.Sprintf("Recurly/%s; go %s", clientVersion, runtime.Version()) + pathPattern = regexp.MustCompile(`{[^}]+}`) ) // Client submits API requests to Recurly diff --git a/client_operations_test.go b/client_operations_test.go index 2ade5de..03881fc 100644 --- a/client_operations_test.go +++ b/client_operations_test.go @@ -26,13 +26,16 @@ func TestCreateAccount(test *testing.T) { Code: String("new_account"), } - account, _ := client.CreateAccount(body) + account, err := client.CreateAccount(body) + t.Assert(err, nil, "Error not expected") t.Assert(account.Id, "abcd1234", "account.Id") } func TestCreateAccountWithContext(test *testing.T) { t := &T{test} - ctx, _ := context.WithTimeout(context.Background(), 20*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) + defer cancel() + scenario := &Scenario{ T: t, AssertRequest: func(req *http.Request) { @@ -51,7 +54,8 @@ func TestCreateAccountWithContext(test *testing.T) { Code: String("new_account"), } - account, _ := client.CreateAccountWithContext(ctx, body) + account, err := client.CreateAccountWithContext(ctx, body) + t.Assert(err, nil, "Error not expected") t.Assert(account.Id, "abcd1234", "account.Id") } @@ -71,12 +75,12 @@ func TestListAccounts(test *testing.T) { "next": "/accounts?cursor=efgh5678%3A1588803986.0&limit=1&order=desc&sort=created_at", "data": [ { - "id": "abcd1234", + "id": "abcd1234", "first_name": "marigold", "last_name": "sunflower" }, { - "id": "efgh5678", + "id": "efgh5678", "first_name": "juniper", "last_name": "pinecone" } @@ -103,7 +107,9 @@ func TestListAccounts(test *testing.T) { func TestListAccountsWithContext(test *testing.T) { t := &T{test} - ctx, _ := context.WithTimeout(context.Background(), 20*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) + defer cancel() + scenario := &Scenario{ T: t, AssertRequest: func(req *http.Request) { @@ -118,12 +124,12 @@ func TestListAccountsWithContext(test *testing.T) { "next": "/accounts?cursor=efgh5678%3A1588803986.0&limit=1&order=desc&sort=created_at", "data": [ { - "id": "abcd1234", + "id": "abcd1234", "first_name": "marigold", "last_name": "sunflower" }, { - "id": "efgh5678", + "id": "efgh5678", "first_name": "juniper", "last_name": "pinecone" } @@ -168,6 +174,7 @@ func TestCreateAccountWithNilContext(test *testing.T) { Code: String("new_account"), } - account, _ := client.CreateAccountWithContext(nil, body) + account, err := client.CreateAccountWithContext(context.Background(), body) + t.Assert(err, nil, "Error not expected") t.Assert(account.Id, "abcd1234", "account.Id") } diff --git a/client_test.go b/client_test.go index 6de2a7c..19a1054 100644 --- a/client_test.go +++ b/client_test.go @@ -141,6 +141,9 @@ func TestClientInjectsResponseMetadataIntoResource(test *testing.T) { client = scenario.MockHTTPClient() empty, err := client.DeleteResource("abcd1234") + if err != nil { + t.Errorf("DeleteResource returned err: %v", err) + } resp = empty.GetResponse() t.Assert(resp.Request.ID, "msy-1234", "resp.Request.ID") diff --git a/logger.go b/logger.go index 5c59638..5e28e79 100644 --- a/logger.go +++ b/logger.go @@ -90,6 +90,7 @@ func (log *Logger) stdOut(v ...interface{}) { } } +//lint:ignore U1000 TODO: should `Error` call stdErr instead of stdOut? func (log *Logger) stdErr(v ...interface{}) { if log.StdErr != nil { log.StdErr.Print(v...)