Skip to content

Commit 727adbf

Browse files
authored
build (lint): update golangci-lint to 1.42.0 (#119)
1 parent 3553389 commit 727adbf

13 files changed

+56
-63
lines changed

.github/workflows/pr.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: lint
1616
uses: golangci/golangci-lint-action@v2
1717
with:
18-
version: v1.41.1
18+
version: v1.42.0
1919

2020
tests-on-unix:
2121
needs: golangci-lint # run after golangci-lint action to not produce duplicated errors

.golangci.yml

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
linters-settings:
2+
goconst:
3+
min-len: 2
4+
min-occurrences: 2
25
gocritic:
36
enabled-tags:
47
- diagnostic
@@ -21,6 +24,8 @@ linters-settings:
2124
rules:
2225
json: camel
2326
yaml: camel
27+
misspell:
28+
locale: US
2429
revive:
2530
# see https://github.com/mgechev/revive#available-rules for details.
2631
ignore-generated-header: true
@@ -103,6 +108,7 @@ linters:
103108
# - cyclop # checks function and package cyclomatic complexity [fast: false, auto-fix: false]
104109
# - dupl # Tool for code clone detection [fast: true, auto-fix: false]
105110
# - durationcheck # check for two durations multiplied together [fast: false, auto-fix: false]
111+
# - errname # Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`. [fast: false, auto-fix: false]
106112
# - exhaustivestruct # Checks if all struct's fields are initialized [fast: false, auto-fix: false]
107113
# - forbidigo # Forbids identifiers [fast: true, auto-fix: false]
108114
# - forcetypeassert # finds forced type assertions [fast: true, auto-fix: false]

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# A Self-Documenting Makefile: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
22

33
SOURCE_FILES?=./...
4-
GOLANGCI_VERSION=v1.41.1
4+
GOLANGCI_VERSION=v1.42.0
55
COVERAGE=coverage.out
66

77
export PATH := ./bin:$(PATH)

opsmngr/deployments_hosts_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,13 @@ func TestDeployments_GetHostByHostname(t *testing.T) {
315315
}
316316
}
317317

318+
const hostname = "server1.example.com"
319+
318320
func TestDeployments_StartMonitoring(t *testing.T) {
319321
client, mux, teardown := setup()
320322

321323
defer teardown()
322324

323-
hostName := "server1.example.com"
324325
var port int32 = 27017
325326
path := fmt.Sprintf("/api/public/v1.0/groups/%s/hosts", groupID)
326327

@@ -348,7 +349,7 @@ func TestDeployments_StartMonitoring(t *testing.T) {
348349
})
349350

350351
host := &Host{
351-
Hostname: hostName,
352+
Hostname: hostname,
352353
Port: port,
353354
}
354355

@@ -370,7 +371,7 @@ func TestDeployments_StartMonitoring(t *testing.T) {
370371
HasStartupWarnings: false,
371372
Hidden: false,
372373
HostEnabled: true,
373-
Hostname: hostName,
374+
Hostname: hostname,
374375
ID: "22",
375376
JournalingEnabled: false,
376377
Links: []*atlas.Link{},
@@ -392,7 +393,6 @@ func TestDeployments_UpdateMonitoring(t *testing.T) {
392393
defer teardown()
393394

394395
hostID := "22"
395-
hostName := "server1.example.com"
396396
var port int32 = 27017
397397
path := fmt.Sprintf("/api/public/v1.0/groups/%s/hosts/%s", groupID, hostID)
398398

@@ -421,7 +421,7 @@ func TestDeployments_UpdateMonitoring(t *testing.T) {
421421
})
422422

423423
host := &Host{
424-
Hostname: hostName,
424+
Hostname: hostname,
425425
Port: port,
426426
}
427427

@@ -443,7 +443,7 @@ func TestDeployments_UpdateMonitoring(t *testing.T) {
443443
HasStartupWarnings: false,
444444
Hidden: false,
445445
HostEnabled: true,
446-
Hostname: hostName,
446+
Hostname: hostname,
447447
ID: "22",
448448
JournalingEnabled: false,
449449
Links: []*atlas.Link{},

opsmngr/diagnostics_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ func TestDiagnostics_Get(t *testing.T) {
2828
defer teardown()
2929

3030
path := fmt.Sprintf("/api/public/v1.0/groups/%s/diagnostics", groupID)
31-
31+
const expected = "test"
3232
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
3333
testMethod(t, r, http.MethodGet)
34-
_, _ = fmt.Fprint(w, "test")
34+
_, _ = fmt.Fprint(w, expected)
3535
})
3636

3737
buf := new(bytes.Buffer)
@@ -40,7 +40,7 @@ func TestDiagnostics_Get(t *testing.T) {
4040
t.Fatalf("Diagnostics.Get returned error: %v", err)
4141
}
4242

43-
if buf.String() != "test" {
43+
if buf.String() != expected {
4444
t.Fatalf("Diagnostics.Get returned error: %v", err)
4545
}
4646
}

opsmngr/global_alerts_test.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ func TestGlobalAlerts_Get(t *testing.T) {
106106

107107
defer teardown()
108108

109-
alertID := "3b7d2de0a4b02fd2c98146de"
110109
path := fmt.Sprintf("/api/public/v1.0/globalAlerts/%s", alertID)
111110

112111
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
@@ -117,7 +116,7 @@ func TestGlobalAlerts_Get(t *testing.T) {
117116
"created" : "2016-10-09T06:16:36Z",
118117
"eventTypeName" : "OPLOG_BEHIND",
119118
"groupId" : "1",
120-
"id" : "3b7d2de0a4b02fd2c98146de",
119+
"id" : "57b76ddc96e8215c017ceafb",
121120
"links" : [],
122121
"lastNotified" : "2016-10-10T20:42:32Z",
123122
"replicaSetName" : "shardedCluster-shard-0",
@@ -135,7 +134,7 @@ func TestGlobalAlerts_Get(t *testing.T) {
135134

136135
expected := &GlobalAlert{
137136
Alert: atlas.Alert{
138-
ID: "3b7d2de0a4b02fd2c98146de",
137+
ID: alertID,
139138
GroupID: "1",
140139
AlertConfigID: "5730f5e1e4b030a9634a3f69",
141140
EventTypeName: "OPLOG_BEHIND",
@@ -164,7 +163,6 @@ func TestGlobalAlerts_Acknowledge(t *testing.T) {
164163

165164
defer teardown()
166165

167-
alertID := "3b7d2de0a4b02fd2c98146de"
168166
path := fmt.Sprintf("/api/public/v1.0/globalAlerts/%s", alertID)
169167

170168
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
@@ -175,7 +173,7 @@ func TestGlobalAlerts_Acknowledge(t *testing.T) {
175173
"created" : "2016-10-09T06:16:36Z",
176174
"eventTypeName" : "OPLOG_BEHIND",
177175
"groupId" : "1",
178-
"id" : "3b7d2de0a4b02fd2c98146de",
176+
"id" : "57b76ddc96e8215c017ceafb",
179177
"links" : [],
180178
"lastNotified" : "2016-10-10T20:42:32Z",
181179
"replicaSetName" : "shardedCluster-shard-0",
@@ -200,7 +198,7 @@ func TestGlobalAlerts_Acknowledge(t *testing.T) {
200198

201199
expected := &GlobalAlert{
202200
Alert: atlas.Alert{
203-
ID: "3b7d2de0a4b02fd2c98146de",
201+
ID: alertID,
204202
GroupID: "1",
205203
AlertConfigID: "5730f5e1e4b030a9634a3f69",
206204
EventTypeName: "OPLOG_BEHIND",

opsmngr/global_api_key_whitelists_test.go

+9-10
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import (
2424
atlas "go.mongodb.org/atlas/mongodbatlas"
2525
)
2626

27+
const accessListID = "5f3cf81b89034c6b3c0a528e"
28+
2729
func TestWhitelistAPIKeys_List(t *testing.T) {
2830
client, mux, teardown := setup()
2931
defer teardown()
@@ -65,7 +67,7 @@ func TestWhitelistAPIKeys_List(t *testing.T) {
6567
},
6668
Results: []*GlobalWhitelistAPIKey{
6769
{
68-
ID: "5f3cf81b89034c6b3c0a528e",
70+
ID: accessListID,
6971
CidrBlock: "172.20.0.1",
7072
Created: "2020-08-19T13:17:01Z",
7173
Description: "test",
@@ -85,9 +87,7 @@ func TestWhitelistAPIKeys_Get(t *testing.T) {
8587
client, mux, teardown := setup()
8688
defer teardown()
8789

88-
ipAddress := "5f3cf81b89034c6b3c0a528e"
89-
90-
mux.HandleFunc(fmt.Sprintf("/api/public/v1.0/admin/whitelist/%s", ipAddress), func(w http.ResponseWriter, r *http.Request) {
90+
mux.HandleFunc(fmt.Sprintf("/api/public/v1.0/admin/whitelist/%s", accessListID), func(w http.ResponseWriter, r *http.Request) {
9191
testMethod(t, r, http.MethodGet)
9292
fmt.Fprint(w, `{
9393
"id": "5f3cf81b89034c6b3c0a528e",
@@ -99,13 +99,13 @@ func TestWhitelistAPIKeys_Get(t *testing.T) {
9999
}`)
100100
})
101101

102-
whitelistAPIKey, _, err := client.GlobalAPIKeysWhitelist.Get(ctx, ipAddress)
102+
whitelistAPIKey, _, err := client.GlobalAPIKeysWhitelist.Get(ctx, accessListID)
103103
if err != nil {
104104
t.Fatalf("GlobalWhitelistAPIKeys.Get returned error: %v", err)
105105
}
106106

107107
expected := &GlobalWhitelistAPIKey{
108-
ID: "5f3cf81b89034c6b3c0a528e",
108+
ID: accessListID,
109109
CidrBlock: "172.20.0.1",
110110
Created: "2020-08-19T13:17:01Z",
111111
Description: "test",
@@ -159,7 +159,7 @@ func TestWhitelistAPIKeys_Create(t *testing.T) {
159159
}
160160

161161
expected := &GlobalWhitelistAPIKey{
162-
ID: "5f3cf81b89034c6b3c0a528e",
162+
ID: accessListID,
163163
CidrBlock: "172.20.0.1",
164164
Created: "2020-08-19T13:17:01Z",
165165
Description: "test",
@@ -176,12 +176,11 @@ func TestWhitelistAPIKeys_Delete(t *testing.T) {
176176
client, mux, teardown := setup()
177177
defer teardown()
178178

179-
ipAddress := "5f3cf81b89034c6b3c0a528e"
180-
mux.HandleFunc(fmt.Sprintf("/api/public/v1.0/admin/whitelist/%s", ipAddress), func(w http.ResponseWriter, r *http.Request) {
179+
mux.HandleFunc(fmt.Sprintf("/api/public/v1.0/admin/whitelist/%s", accessListID), func(w http.ResponseWriter, r *http.Request) {
181180
testMethod(t, r, http.MethodDelete)
182181
})
183182

184-
_, err := client.GlobalAPIKeysWhitelist.Delete(ctx, ipAddress)
183+
_, err := client.GlobalAPIKeysWhitelist.Delete(ctx, accessListID)
185184
if err != nil {
186185
t.Fatalf("GlobalWhitelistAPIKeys.Delete returned error: %v", err)
187186
}

opsmngr/global_api_keys_test.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ const (
3131
testAPIKey = "test-apikey"
3232
)
3333

34+
const globalAPIKeyID = "5c47503320eef5699e1cce8d"
35+
3436
func TestAPIKeys_ListAPIKeys(t *testing.T) {
3537
client, mux, teardown := setup()
3638
defer teardown()
@@ -74,7 +76,7 @@ func TestAPIKeys_ListAPIKeys(t *testing.T) {
7476

7577
expected := []atlas.APIKey{
7678
{
77-
ID: "5c47503320eef5699e1cce8d",
79+
ID: globalAPIKeyID,
7880
Desc: testAPIKey,
7981
PrivateKey: "********-****-****-db2c132ca78d",
8082
PublicKey: ewmaqvdo,
@@ -165,7 +167,7 @@ func TestAPIKeys_GetAPIKey(t *testing.T) {
165167
fmt.Fprint(w, `{"desc":"test-desc"}`)
166168
})
167169

168-
apiKeys, _, err := client.GlobalAPIKeys.Get(ctx, "5c47503320eef5699e1cce8d")
170+
apiKeys, _, err := client.GlobalAPIKeys.Get(ctx, globalAPIKeyID)
169171
if err != nil {
170172
t.Errorf("APIKey.Get returned error: %v", err)
171173
}
@@ -186,7 +188,7 @@ func TestAPIKeys_Update(t *testing.T) {
186188
Roles: []string{"GLOBAL_READ_ONLY"},
187189
}
188190

189-
mux.HandleFunc(fmt.Sprintf("/api/public/v1.0/admin/apiKeys/%s", "5c47503320eef5699e1cce8d"), func(w http.ResponseWriter, r *http.Request) {
191+
mux.HandleFunc(fmt.Sprintf("/api/public/v1.0/admin/apiKeys/%s", globalAPIKeyID), func(w http.ResponseWriter, r *http.Request) {
190192
expected := map[string]interface{}{
191193
"desc": "test-apiKey",
192194
"roles": []interface{}{"GLOBAL_READ_ONLY"},
@@ -219,7 +221,7 @@ func TestAPIKeys_Update(t *testing.T) {
219221
fmt.Fprint(w, jsonBlob)
220222
})
221223

222-
apiKey, _, err := client.GlobalAPIKeys.Update(ctx, "5c47503320eef5699e1cce8d", updateRequest)
224+
apiKey, _, err := client.GlobalAPIKeys.Update(ctx, globalAPIKeyID, updateRequest)
223225
if err != nil {
224226
t.Fatalf("APIKeys.Create returned error: %v", err)
225227
}
@@ -236,7 +238,6 @@ func TestAPIKeys_Update(t *testing.T) {
236238
func TestAPIKeys_Delete(t *testing.T) {
237239
client, mux, teardown := setup()
238240
defer teardown()
239-
apiKeyID := "5c47503320eef5699e1cce8d"
240241

241242
mux.HandleFunc(fmt.Sprintf("/api/public/v1.0/admin/apiKeys/%s", apiKeyID), func(w http.ResponseWriter, r *http.Request) {
242243
testMethod(t, r, http.MethodDelete)

opsmngr/opsmngr_test.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,9 @@ func TestNewGZipRequest_badURL(t *testing.T) {
176176
testURLParseError(t, err)
177177
}
178178

179+
const ua = "testing/0.0.1"
180+
179181
func TestNewRequest_withCustomUserAgent(t *testing.T) {
180-
ua := "testing/0.0.1"
181182
c, err := New(nil, SetUserAgent(ua))
182183

183184
if err != nil {
@@ -232,6 +233,8 @@ func TestNewRequest_errorForNoTrailingSlash(t *testing.T) {
232233
}
233234
}
234235

236+
const testResponse = `{"A":"a"}`
237+
235238
func TestClient_Do(t *testing.T) {
236239
client, mux, teardown := setup()
237240
defer teardown()
@@ -244,7 +247,7 @@ func TestClient_Do(t *testing.T) {
244247
if m := http.MethodGet; m != r.Method {
245248
t.Errorf("Request method = %v, expected %v", r.Method, m)
246249
}
247-
_, _ = fmt.Fprint(w, `{"A":"a"}`)
250+
_, _ = fmt.Fprint(w, testResponse)
248251
})
249252

250253
req, _ := client.NewRequest(ctx, http.MethodGet, ".", nil)
@@ -324,13 +327,12 @@ func TestClient_withRaw(t *testing.T) {
324327
}
325328

326329
client.withRaw = true
327-
expected := `{"A":"a"}`
328330

329331
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
330332
if m := http.MethodGet; m != r.Method {
331333
t.Errorf("Request method = %v, expected %v", r.Method, m)
332334
}
333-
_, _ = fmt.Fprint(w, expected)
335+
_, _ = fmt.Fprint(w, testResponse)
334336
})
335337

336338
body := new(foo)
@@ -340,8 +342,8 @@ func TestClient_withRaw(t *testing.T) {
340342
t.Fatalf("Do(): %v", err)
341343
}
342344

343-
if string(resp.Raw) != expected {
344-
t.Errorf("expected response to be %v, Response = %v", expected, string(resp.Raw))
345+
if string(resp.Raw) != testResponse {
346+
t.Errorf("expected response to be %v, Response = %v", testResponse, string(resp.Raw))
345347
}
346348
}
347349

@@ -385,7 +387,6 @@ func TestClient_OnRequestCompleted(t *testing.T) {
385387
}
386388

387389
func TestSetUserAgent(t *testing.T) {
388-
ua := "testing/0.0.1"
389390
c, err := New(nil, SetUserAgent(ua))
390391

391392
if err != nil {

0 commit comments

Comments
 (0)