From b6a0e2936144d1c3bfbbceab7e67808767ed52dd Mon Sep 17 00:00:00 2001 From: Sergey Vilgelm Date: Sun, 24 Sep 2023 20:39:48 -0700 Subject: [PATCH] fix TestClientOnResponseError parallel tests In case of using `t.Parallel()` inside a for loop, the loop variables must be copied, otherwise only the last test will be executed. ```go for _, test := range tests { t.Run(test.name, func(t *testing.T) { t.Parallel() ``` changed to ```go for _, test := range tests { test := test t.Run(test.name, func(t *testing.T) { t.Parallel() ``` also the AuthServer must be created within the test, otherwise some tests fail. `t.Log(test.Name)` can be used to verify the issue: ```go for _, test := range tests { t.Run(test.name, func(t *testing.T) { t.Parallel() t.Log("Test name:", test.name) ``` --- client_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/client_test.go b/client_test.go index dff2aaaa..ad02f62f 100644 --- a/client_test.go +++ b/client_test.go @@ -780,9 +780,6 @@ func TestNewWithLocalAddr(t *testing.T) { } func TestClientOnResponseError(t *testing.T) { - ts := createAuthServer(t) - defer ts.Close() - tests := []struct { name string setup func(*Client) @@ -862,8 +859,12 @@ func TestClientOnResponseError(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { t.Parallel() + ts := createAuthServer(t) + defer ts.Close() + var assertErrorHook = func(r *Request, err error) { assertNotNil(t, r) v, ok := err.(*ResponseError)