Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Makefile for test, lint, vet. Fix lint issues. #134

Open
wants to merge 1 commit into
base: v3-v2021-02-25
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
all: build lint test vet

build:
go build ./...

lint:
staticcheck ./...

test:
go test -race ./...

vet:
go vet ./...
7 changes: 3 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 16 additions & 9 deletions client_operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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")
}

Expand All @@ -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"
}
Expand All @@ -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) {
Expand All @@ -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"
}
Expand Down Expand Up @@ -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")
}
3 changes: 3 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down