Skip to content

Commit

Permalink
Add Makefile for test, lint, vet. Fix lint issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
isaachall committed Jan 31, 2022
1 parent e1a1af0 commit c694601
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 13 deletions.
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 ]
pull_request:
branches: [ master ]

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 &&
$HOME/go/bin/staticcheck &&
make vet
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

0 comments on commit c694601

Please sign in to comment.