@@ -14,6 +14,7 @@ func TestDetermineUpdates(t *testing.T) {
1414t .Parallel ()
1515maxConns := 1
1616tests := []struct {
17+ name string
1718updated []UpstreamServer
1819nginx []UpstreamServer
1920expectedToAdd []UpstreamServer
@@ -57,6 +58,7 @@ func TestDetermineUpdates(t *testing.T) {
5758Server :"10.0.0.2:80" ,
5859},
5960},
61+ name :"replace all" ,
6062},
6163{
6264updated : []UpstreamServer {
@@ -95,6 +97,7 @@ func TestDetermineUpdates(t *testing.T) {
9597Server :"10.0.0.1:80" ,
9698},
9799},
100+ name :"add and delete" ,
98101},
99102{
100103updated : []UpstreamServer {
@@ -119,6 +122,7 @@ func TestDetermineUpdates(t *testing.T) {
119122Server :"10.0.0.3:80" ,
120123},
121124},
125+ name :"same" ,
122126},
123127{
124128// empty values
@@ -153,21 +157,26 @@ func TestDetermineUpdates(t *testing.T) {
153157MaxConns :& maxConns ,
154158},
155159},
160+ name :"update field and delete" ,
156161},
157162}
158163
159164for _ ,test := range tests {
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
167175func TestStreamDetermineUpdates (t * testing.T ) {
168176t .Parallel ()
169177maxConns := 1
170178tests := []struct {
179+ name string
171180updated []StreamUpstreamServer
172181nginx []StreamUpstreamServer
173182expectedToAdd []StreamUpstreamServer
@@ -211,6 +220,7 @@ func TestStreamDetermineUpdates(t *testing.T) {
211220Server :"10.0.0.2:80" ,
212221},
213222},
223+ name :"replace all" ,
214224},
215225{
216226updated : []StreamUpstreamServer {
@@ -249,6 +259,7 @@ func TestStreamDetermineUpdates(t *testing.T) {
249259Server :"10.0.0.1:80" ,
250260},
251261},
262+ name :"add and delete" ,
252263},
253264{
254265updated : []StreamUpstreamServer {
@@ -276,6 +287,7 @@ func TestStreamDetermineUpdates(t *testing.T) {
276287Server :"10.0.0.3:80" ,
277288},
278289},
290+ name :"same" ,
279291},
280292{
281293// empty values
@@ -310,14 +322,18 @@ func TestStreamDetermineUpdates(t *testing.T) {
310322MaxConns :& maxConns ,
311323},
312324},
325+ name :"update field and delete" ,
313326},
314327}
315328
316329for _ ,test := range tests {
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
369385for _ ,test := range tests {
370- result := addPortToServer (test .address )
371- if result != 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+ if result != 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
377396func TestHaveSameParameters (t * testing.T ) {
378397t .Parallel ()
379398tests := []struct {
399+ msg string
380400server UpstreamServer
381401serverNGX UpstreamServer
382402expected bool
@@ -385,11 +405,13 @@ func TestHaveSameParameters(t *testing.T) {
385405server :UpstreamServer {},
386406serverNGX :UpstreamServer {},
387407expected :true ,
408+ msg :"empty" ,
388409},
389410{
390411server :UpstreamServer {ID :2 },
391412serverNGX :UpstreamServer {ID :3 },
392413expected :true ,
414+ msg :"different ID" ,
393415},
394416{
395417server :UpstreamServer {},
@@ -403,6 +425,7 @@ func TestHaveSameParameters(t *testing.T) {
403425Down :& defaultDown ,
404426},
405427expected :true ,
428+ msg :"default values" ,
406429},
407430{
408431server :UpstreamServer {
@@ -428,35 +451,43 @@ func TestHaveSameParameters(t *testing.T) {
428451Down :& defaultDown ,
429452},
430453expected :true ,
454+ msg :"same values" ,
431455},
432456{
433457server :UpstreamServer {SlowStart :"10s" },
434458serverNGX :UpstreamServer {},
435459expected :false ,
460+ msg :"different SlowStart" ,
436461},
437462{
438463server :UpstreamServer {},
439464serverNGX :UpstreamServer {SlowStart :"10s" },
440465expected :false ,
466+ msg :"different SlowStart 2" ,
441467},
442468{
443469server :UpstreamServer {SlowStart :"20s" },
444470serverNGX :UpstreamServer {SlowStart :"10s" },
445471expected :false ,
472+ msg :"different SlowStart 3" ,
446473},
447474}
448475
449476for _ ,test := range tests {
450- result := haveSameParameters (test .server ,test .serverNGX )
451- if result != 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+ if result != 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
457487func TestHaveSameParametersForStream (t * testing.T ) {
458488t .Parallel ()
459489tests := []struct {
490+ msg string
460491server StreamUpstreamServer
461492serverNGX StreamUpstreamServer
462493expected bool
@@ -465,11 +496,13 @@ func TestHaveSameParametersForStream(t *testing.T) {
465496server :StreamUpstreamServer {},
466497serverNGX :StreamUpstreamServer {},
467498expected :true ,
499+ msg :"empty" ,
468500},
469501{
470502server :StreamUpstreamServer {ID :2 },
471503serverNGX :StreamUpstreamServer {ID :3 },
472504expected :true ,
505+ msg :"different ID" ,
473506},
474507{
475508server :StreamUpstreamServer {},
@@ -483,6 +516,7 @@ func TestHaveSameParametersForStream(t *testing.T) {
483516Down :& defaultDown ,
484517},
485518expected :true ,
519+ msg :"default values" ,
486520},
487521{
488522server :StreamUpstreamServer {
@@ -508,24 +542,30 @@ func TestHaveSameParametersForStream(t *testing.T) {
508542Down :& defaultDown ,
509543},
510544expected :true ,
545+ msg :"same values" ,
511546},
512547{
513548server :StreamUpstreamServer {},
514549serverNGX :StreamUpstreamServer {SlowStart :"10s" },
515550expected :false ,
551+ msg :"different SlowStart" ,
516552},
517553{
518554server :StreamUpstreamServer {SlowStart :"20s" },
519555serverNGX :StreamUpstreamServer {SlowStart :"10s" },
520556expected :false ,
557+ msg :"different SlowStart 2" ,
521558},
522559}
523560
524561for _ ,test := range tests {
525- result := haveSameParametersForStream (test .server ,test .serverNGX )
526- if result != 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+ if result != 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
667707func TestGetStats_NoStreamEndpoint (t * testing.T ) {
708+ t .Parallel ()
668709var writeLock sync.Mutex
669710
670- t .Parallel ()
671711ts := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter ,r * http.Request ) {
672712writeLock .Lock ()
673713defer writeLock .Unlock ()