Skip to content

Commit b3094de

Browse files
committed
Add Makefile for test, lint, vet. Fix lint issues.
1 parent bd74cc7 commit b3094de

6 files changed

Lines changed: 58 additions & 13 deletions

File tree

.github/workflows/ci.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
lint:
11+
name: Lint
12+
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@master
17+
18+
- name: lint
19+
run: |
20+
go get -u honnef.co/go/tools/cmd/staticcheck@latest &&
21+
$HOME/go/bin/staticcheck &&
22+
make vet

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
all: build lint test vet
2+
3+
build:
4+
go build ./...
5+
6+
lint:
7+
staticcheck
8+
9+
test:
10+
go test -race ./...
11+
12+
vet:
13+
go vet ./...

client.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,9 @@ var (
5454
Transport: defaultTransport,
5555
}
5656

57-
acceptVersion = fmt.Sprintf("application/vnd.recurly.%s", APIVersion)
58-
recurlyVersion = fmt.Sprintf("recurly.%s", APIVersion)
59-
userAgent = fmt.Sprintf("Recurly/%s; go %s", clientVersion, runtime.Version())
60-
pathPattern = regexp.MustCompile(`{[^}]+}`)
57+
acceptVersion = fmt.Sprintf("application/vnd.recurly.%s", APIVersion)
58+
userAgent = fmt.Sprintf("Recurly/%s; go %s", clientVersion, runtime.Version())
59+
pathPattern = regexp.MustCompile(`{[^}]+}`)
6160
)
6261

6362
// Client submits API requests to Recurly

client_operations_test.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,16 @@ func TestCreateAccount(test *testing.T) {
2626
Code: String("new_account"),
2727
}
2828

29-
account, _ := client.CreateAccount(body)
29+
account, err := client.CreateAccount(body)
30+
t.Assert(err, nil, "Error not expected")
3031
t.Assert(account.Id, "abcd1234", "account.Id")
3132
}
3233

3334
func TestCreateAccountWithContext(test *testing.T) {
3435
t := &T{test}
35-
ctx, _ := context.WithTimeout(context.Background(), 20*time.Second)
36+
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
37+
defer cancel()
38+
3639
scenario := &Scenario{
3740
T: t,
3841
AssertRequest: func(req *http.Request) {
@@ -51,7 +54,8 @@ func TestCreateAccountWithContext(test *testing.T) {
5154
Code: String("new_account"),
5255
}
5356

54-
account, _ := client.CreateAccountWithContext(ctx, body)
57+
account, err := client.CreateAccountWithContext(ctx, body)
58+
t.Assert(err, nil, "Error not expected")
5559
t.Assert(account.Id, "abcd1234", "account.Id")
5660
}
5761

@@ -71,12 +75,12 @@ func TestListAccounts(test *testing.T) {
7175
"next": "/accounts?cursor=efgh5678%3A1588803986.0&limit=1&order=desc&sort=created_at",
7276
"data": [
7377
{
74-
"id": "abcd1234",
78+
"id": "abcd1234",
7579
"first_name": "marigold",
7680
"last_name": "sunflower"
7781
},
7882
{
79-
"id": "efgh5678",
83+
"id": "efgh5678",
8084
"first_name": "juniper",
8185
"last_name": "pinecone"
8286
}
@@ -103,7 +107,9 @@ func TestListAccounts(test *testing.T) {
103107

104108
func TestListAccountsWithContext(test *testing.T) {
105109
t := &T{test}
106-
ctx, _ := context.WithTimeout(context.Background(), 20*time.Second)
110+
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
111+
defer cancel()
112+
107113
scenario := &Scenario{
108114
T: t,
109115
AssertRequest: func(req *http.Request) {
@@ -118,12 +124,12 @@ func TestListAccountsWithContext(test *testing.T) {
118124
"next": "/accounts?cursor=efgh5678%3A1588803986.0&limit=1&order=desc&sort=created_at",
119125
"data": [
120126
{
121-
"id": "abcd1234",
127+
"id": "abcd1234",
122128
"first_name": "marigold",
123129
"last_name": "sunflower"
124130
},
125131
{
126-
"id": "efgh5678",
132+
"id": "efgh5678",
127133
"first_name": "juniper",
128134
"last_name": "pinecone"
129135
}
@@ -168,6 +174,7 @@ func TestCreateAccountWithNilContext(test *testing.T) {
168174
Code: String("new_account"),
169175
}
170176

171-
account, _ := client.CreateAccountWithContext(nil, body)
177+
account, err := client.CreateAccountWithContext(context.Background(), body)
178+
t.Assert(err, nil, "Error not expected")
172179
t.Assert(account.Id, "abcd1234", "account.Id")
173180
}

client_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ func TestClientInjectsResponseMetadataIntoResource(test *testing.T) {
140140
client = scenario.MockHTTPClient()
141141

142142
empty, err := client.DeleteResource("abcd1234")
143+
if err != nil {
144+
t.Errorf("DeleteResource returned err: %v", err)
145+
}
143146

144147
resp = empty.GetResponse()
145148
t.Assert(resp.Request.ID, "msy-1234", "resp.Request.ID")

logger.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ func (log *Logger) stdOut(v ...interface{}) {
9090
}
9191
}
9292

93+
//lint:ignore U1000 TODO: should `Error` call stdErr instead of stdOut?
9394
func (log *Logger) stdErr(v ...interface{}) {
9495
if log.StdErr != nil {
9596
log.StdErr.Print(v...)

0 commit comments

Comments
 (0)