Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit266da4c

Browse files
authored
Add more linters (#382)
1 parent1062d6a commit266da4c

File tree

5 files changed

+86
-22
lines changed

5 files changed

+86
-22
lines changed

‎.golangci.yml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,33 @@ linters-settings:
55
ignore-generated-header:true
66
rules:
77
-name:blank-imports
8+
-name:constant-logical-expr
89
-name:context-as-argument
910
-name:context-keys-type
11+
-name:defer
1012
-name:dot-imports
13+
-name:duplicated-imports
1114
-name:empty-block
1215
-name:error-naming
1316
-name:error-return
1417
-name:error-strings
1518
-name:errorf
1619
-name:exported
20+
-name:import-shadowing
1721
-name:increment-decrement
1822
-name:indent-error-flow
1923
-name:package-comments
2024
-name:range
25+
-name:range-val-address
26+
-name:range-val-in-closure
2127
-name:receiver-naming
2228
-name:redefines-builtin-id
29+
-name:string-of-int
2330
-name:superfluous-else
2431
-name:time-naming
32+
-name:unchecked-type-assertion
2533
-name:unexported-return
34+
-name:unnecessary-stmt
2635
-name:unreachable-code
2736
-name:unused-parameter
2837
-name:var-declaration
@@ -60,6 +69,7 @@ linters:
6069
-ineffassign
6170
-intrange
6271
-makezero
72+
-mirror
6373
-misspell
6474
-musttag
6575
-nilerr
@@ -68,6 +78,7 @@ linters:
6878
-perfsprint
6979
-prealloc
7080
-predeclared
81+
-paralleltest
7182
-reassign
7283
-revive
7384
-staticcheck

‎Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ GOLANGCI_LINT_VERSION = v1.61.0
44
test: unit-test test-integration test-integration-no-stream-block clean
55

66
lint:
7-
docker run--pull always --rm -v$(shell pwd):/nginx-plus-go-client -w /nginx-plus-go-client -v$(shell go env GOCACHE):/cache/go -e GOCACHE=/cache/go -e GOLANGCI_LINT_CACHE=/cache/go -v$(shell go env GOPATH)/pkg:/go/pkggolangci/golangci-lint:$(GOLANGCI_LINT_VERSION)golangci-lint --color always run
7+
go rungithub.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)run --fix
88

99
unit-test:
1010
gotest -v -shuffle=on -race client/*.go

‎client/nginx_test.go‎

Lines changed: 61 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ func TestDetermineUpdates(t *testing.T) {
1414
t.Parallel()
1515
maxConns:=1
1616
tests:= []struct {
17+
namestring
1718
updated []UpstreamServer
1819
nginx []UpstreamServer
1920
expectedToAdd []UpstreamServer
@@ -57,6 +58,7 @@ func TestDetermineUpdates(t *testing.T) {
5758
Server:"10.0.0.2:80",
5859
},
5960
},
61+
name:"replace all",
6062
},
6163
{
6264
updated: []UpstreamServer{
@@ -95,6 +97,7 @@ func TestDetermineUpdates(t *testing.T) {
9597
Server:"10.0.0.1:80",
9698
},
9799
},
100+
name:"add and delete",
98101
},
99102
{
100103
updated: []UpstreamServer{
@@ -119,6 +122,7 @@ func TestDetermineUpdates(t *testing.T) {
119122
Server:"10.0.0.3:80",
120123
},
121124
},
125+
name:"same",
122126
},
123127
{
124128
// empty values
@@ -153,21 +157,26 @@ func TestDetermineUpdates(t *testing.T) {
153157
MaxConns:&maxConns,
154158
},
155159
},
160+
name:"update field and delete",
156161
},
157162
}
158163

159164
for_,test:=rangetests {
160-
toAdd,toDelete,toUpdate:=determineUpdates(test.updated,test.nginx)
161-
if!reflect.DeepEqual(toAdd,test.expectedToAdd)||!reflect.DeepEqual(toDelete,test.expectedToDelete)||!reflect.DeepEqual(toUpdate,test.expectedToUpdate) {
162-
t.Errorf("determineUpdates(%v, %v) = (%v, %v, %v)",test.updated,test.nginx,toAdd,toDelete,toUpdate)
163-
}
165+
t.Run(test.name,func(t*testing.T) {
166+
t.Parallel()
167+
toAdd,toDelete,toUpdate:=determineUpdates(test.updated,test.nginx)
168+
if!reflect.DeepEqual(toAdd,test.expectedToAdd)||!reflect.DeepEqual(toDelete,test.expectedToDelete)||!reflect.DeepEqual(toUpdate,test.expectedToUpdate) {
169+
t.Errorf("determineUpdates(%v, %v) = (%v, %v, %v)",test.updated,test.nginx,toAdd,toDelete,toUpdate)
170+
}
171+
})
164172
}
165173
}
166174

167175
funcTestStreamDetermineUpdates(t*testing.T) {
168176
t.Parallel()
169177
maxConns:=1
170178
tests:= []struct {
179+
namestring
171180
updated []StreamUpstreamServer
172181
nginx []StreamUpstreamServer
173182
expectedToAdd []StreamUpstreamServer
@@ -211,6 +220,7 @@ func TestStreamDetermineUpdates(t *testing.T) {
211220
Server:"10.0.0.2:80",
212221
},
213222
},
223+
name:"replace all",
214224
},
215225
{
216226
updated: []StreamUpstreamServer{
@@ -249,6 +259,7 @@ func TestStreamDetermineUpdates(t *testing.T) {
249259
Server:"10.0.0.1:80",
250260
},
251261
},
262+
name:"add and delete",
252263
},
253264
{
254265
updated: []StreamUpstreamServer{
@@ -276,6 +287,7 @@ func TestStreamDetermineUpdates(t *testing.T) {
276287
Server:"10.0.0.3:80",
277288
},
278289
},
290+
name:"same",
279291
},
280292
{
281293
// empty values
@@ -310,14 +322,18 @@ func TestStreamDetermineUpdates(t *testing.T) {
310322
MaxConns:&maxConns,
311323
},
312324
},
325+
name:"update field and delete",
313326
},
314327
}
315328

316329
for_,test:=rangetests {
317-
toAdd,toDelete,toUpdate:=determineStreamUpdates(test.updated,test.nginx)
318-
if!reflect.DeepEqual(toAdd,test.expectedToAdd)||!reflect.DeepEqual(toDelete,test.expectedToDelete)||!reflect.DeepEqual(toUpdate,test.expectedToUpdate) {
319-
t.Errorf("determiteUpdates(%v, %v) = (%v, %v, %v)",test.updated,test.nginx,toAdd,toDelete,toUpdate)
320-
}
330+
t.Run(test.name,func(t*testing.T) {
331+
t.Parallel()
332+
toAdd,toDelete,toUpdate:=determineStreamUpdates(test.updated,test.nginx)
333+
if!reflect.DeepEqual(toAdd,test.expectedToAdd)||!reflect.DeepEqual(toDelete,test.expectedToDelete)||!reflect.DeepEqual(toUpdate,test.expectedToUpdate) {
334+
t.Errorf("determiteUpdates(%v, %v) = (%v, %v, %v)",test.updated,test.nginx,toAdd,toDelete,toUpdate)
335+
}
336+
})
321337
}
322338
}
323339

@@ -367,16 +383,20 @@ func TestAddPortToServer(t *testing.T) {
367383
}
368384

369385
for_,test:=rangetests {
370-
result:=addPortToServer(test.address)
371-
ifresult!=test.expected {
372-
t.Errorf("addPortToServer(%v) returned %v but expected %v for %v",test.address,result,test.expected,test.msg)
373-
}
386+
t.Run(test.msg,func(t*testing.T) {
387+
t.Parallel()
388+
result:=addPortToServer(test.address)
389+
ifresult!=test.expected {
390+
t.Errorf("addPortToServer(%v) returned %v but expected %v for %v",test.address,result,test.expected,test.msg)
391+
}
392+
})
374393
}
375394
}
376395

377396
funcTestHaveSameParameters(t*testing.T) {
378397
t.Parallel()
379398
tests:= []struct {
399+
msgstring
380400
serverUpstreamServer
381401
serverNGXUpstreamServer
382402
expectedbool
@@ -385,11 +405,13 @@ func TestHaveSameParameters(t *testing.T) {
385405
server:UpstreamServer{},
386406
serverNGX:UpstreamServer{},
387407
expected:true,
408+
msg:"empty",
388409
},
389410
{
390411
server:UpstreamServer{ID:2},
391412
serverNGX:UpstreamServer{ID:3},
392413
expected:true,
414+
msg:"different ID",
393415
},
394416
{
395417
server:UpstreamServer{},
@@ -403,6 +425,7 @@ func TestHaveSameParameters(t *testing.T) {
403425
Down:&defaultDown,
404426
},
405427
expected:true,
428+
msg:"default values",
406429
},
407430
{
408431
server:UpstreamServer{
@@ -428,35 +451,43 @@ func TestHaveSameParameters(t *testing.T) {
428451
Down:&defaultDown,
429452
},
430453
expected:true,
454+
msg:"same values",
431455
},
432456
{
433457
server:UpstreamServer{SlowStart:"10s"},
434458
serverNGX:UpstreamServer{},
435459
expected:false,
460+
msg:"different SlowStart",
436461
},
437462
{
438463
server:UpstreamServer{},
439464
serverNGX:UpstreamServer{SlowStart:"10s"},
440465
expected:false,
466+
msg:"different SlowStart 2",
441467
},
442468
{
443469
server:UpstreamServer{SlowStart:"20s"},
444470
serverNGX:UpstreamServer{SlowStart:"10s"},
445471
expected:false,
472+
msg:"different SlowStart 3",
446473
},
447474
}
448475

449476
for_,test:=rangetests {
450-
result:=haveSameParameters(test.server,test.serverNGX)
451-
ifresult!=test.expected {
452-
t.Errorf("haveSameParameters(%v, %v) returned %v but expected %v",test.server,test.serverNGX,result,test.expected)
453-
}
477+
t.Run(test.msg,func(t*testing.T) {
478+
t.Parallel()
479+
result:=haveSameParameters(test.server,test.serverNGX)
480+
ifresult!=test.expected {
481+
t.Errorf("haveSameParameters(%v, %v) returned %v but expected %v",test.server,test.serverNGX,result,test.expected)
482+
}
483+
})
454484
}
455485
}
456486

457487
funcTestHaveSameParametersForStream(t*testing.T) {
458488
t.Parallel()
459489
tests:= []struct {
490+
msgstring
460491
serverStreamUpstreamServer
461492
serverNGXStreamUpstreamServer
462493
expectedbool
@@ -465,11 +496,13 @@ func TestHaveSameParametersForStream(t *testing.T) {
465496
server:StreamUpstreamServer{},
466497
serverNGX:StreamUpstreamServer{},
467498
expected:true,
499+
msg:"empty",
468500
},
469501
{
470502
server:StreamUpstreamServer{ID:2},
471503
serverNGX:StreamUpstreamServer{ID:3},
472504
expected:true,
505+
msg:"different ID",
473506
},
474507
{
475508
server:StreamUpstreamServer{},
@@ -483,6 +516,7 @@ func TestHaveSameParametersForStream(t *testing.T) {
483516
Down:&defaultDown,
484517
},
485518
expected:true,
519+
msg:"default values",
486520
},
487521
{
488522
server:StreamUpstreamServer{
@@ -508,24 +542,30 @@ func TestHaveSameParametersForStream(t *testing.T) {
508542
Down:&defaultDown,
509543
},
510544
expected:true,
545+
msg:"same values",
511546
},
512547
{
513548
server:StreamUpstreamServer{},
514549
serverNGX:StreamUpstreamServer{SlowStart:"10s"},
515550
expected:false,
551+
msg:"different SlowStart",
516552
},
517553
{
518554
server:StreamUpstreamServer{SlowStart:"20s"},
519555
serverNGX:StreamUpstreamServer{SlowStart:"10s"},
520556
expected:false,
557+
msg:"different SlowStart 2",
521558
},
522559
}
523560

524561
for_,test:=rangetests {
525-
result:=haveSameParametersForStream(test.server,test.serverNGX)
526-
ifresult!=test.expected {
527-
t.Errorf("haveSameParametersForStream(%v, %v) returned %v but expected %v",test.server,test.serverNGX,result,test.expected)
528-
}
562+
t.Run(test.msg,func(t*testing.T) {
563+
t.Parallel()
564+
result:=haveSameParametersForStream(test.server,test.serverNGX)
565+
ifresult!=test.expected {
566+
t.Errorf("haveSameParametersForStream(%v, %v) returned %v but expected %v",test.server,test.serverNGX,result,test.expected)
567+
}
568+
})
529569
}
530570
}
531571

@@ -665,9 +705,9 @@ func TestClientWithMaxAPI(t *testing.T) {
665705
}
666706

667707
funcTestGetStats_NoStreamEndpoint(t*testing.T) {
708+
t.Parallel()
668709
varwriteLock sync.Mutex
669710

670-
t.Parallel()
671711
ts:=httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter,r*http.Request) {
672712
writeLock.Lock()
673713
deferwriteLock.Unlock()

‎tests/client_no_stream_test.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
// The API returns a special error code that we can use to determine if the API
1414
// is misconfigured or of the stream block is missing.
1515
funcTestStatsNoStream(t*testing.T) {
16+
t.Parallel()
1617
c,err:=client.NewNginxClient(helpers.GetAPIEndpoint())
1718
iferr!=nil {
1819
t.Fatalf("Error connecting to nginx: %v",err)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp