Browse code

client: remove redundant capturing of loop vars (copyloopvar)

client/client_test.go:91:3: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar)
tc := tc
^
client/client_test.go:326:3: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar)
tc := tc
^
client/client_test.go:481:3: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar)
tc := tc
^
client/image_list_test.go:183:3: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar)
tc := tc
^
client/image_push_test.go:163:3: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar)
tc := tc
^
client/image_tag_test.go:50:3: The copy of the 'for' variable "repo" can be deleted (Go 1.22+) (copyloopvar)
repo := repo
^
client/image_tag_test.go:61:3: The copy of the 'for' variable "repotag" can be deleted (Go 1.22+) (copyloopvar)
repotag := repotag
^
client/ping_test.go:114:3: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar)
tc := tc
^
client/request_test.go:53:3: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar)
tc := tc
^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2024/11/12 21:08:20
Showing 6 changed files
... ...
@@ -88,7 +88,6 @@ func TestNewClientWithOpsFromEnv(t *testing.T) {
88 88
 
89 89
 	env.PatchAll(t, nil)
90 90
 	for _, tc := range testcases {
91
-		tc := tc
92 91
 		t.Run(tc.doc, func(t *testing.T) {
93 92
 			env.PatchAll(t, tc.envs)
94 93
 			client, err := NewClientWithOpts(FromEnv)
... ...
@@ -323,7 +322,6 @@ func TestNegotiateAPIVersion(t *testing.T) {
323 323
 	}
324 324
 
325 325
 	for _, tc := range tests {
326
-		tc := tc
327 326
 		t.Run(tc.doc, func(t *testing.T) {
328 327
 			opts := make([]Opt, 0)
329 328
 			if tc.clientVersion != "" {
... ...
@@ -478,7 +476,6 @@ func TestClientRedirect(t *testing.T) {
478 478
 	}
479 479
 
480 480
 	for _, tc := range tests {
481
-		tc := tc
482 481
 		t.Run(tc.httpMethod, func(t *testing.T) {
483 482
 			req, err := http.NewRequest(tc.httpMethod, "/redirectme", nil)
484 483
 			assert.Check(t, err)
... ...
@@ -180,7 +180,6 @@ func TestImageListWithSharedSize(t *testing.T) {
180 180
 		{name: "set after 1.42, if requested", version: "1.42", options: image.ListOptions{SharedSize: true}, sharedSize: "1"},
181 181
 		{name: "unset before 1.42, even if requested", version: "1.41", options: image.ListOptions{SharedSize: true}},
182 182
 	} {
183
-		tc := tc
184 183
 		t.Run(tc.name, func(t *testing.T) {
185 184
 			t.Parallel()
186 185
 			var query url.Values
... ...
@@ -160,7 +160,6 @@ func TestImagePushWithoutErrors(t *testing.T) {
160 160
 		},
161 161
 	}
162 162
 	for _, tc := range testCases {
163
-		tc := tc
164 163
 		t.Run(fmt.Sprintf("%s,all-tags=%t", tc.reference, tc.all), func(t *testing.T) {
165 164
 			client := &Client{
166 165
 				client: newMockClient(func(req *http.Request) (*http.Response, error) {
... ...
@@ -47,7 +47,6 @@ func TestImageTagInvalidSourceImageName(t *testing.T) {
47 47
 
48 48
 	invalidRepos := []string{"fo$z$", "Foo@3cc", "Foo$3", "Foo*3", "Fo^3", "Foo!3", "F)xcz(", "fo%asd", "aa/asdf$$^/aa"}
49 49
 	for _, repo := range invalidRepos {
50
-		repo := repo
51 50
 		t.Run("invalidRepo/"+repo, func(t *testing.T) {
52 51
 			t.Parallel()
53 52
 			err := client.ImageTag(ctx, "busybox", repo)
... ...
@@ -58,7 +57,6 @@ func TestImageTagInvalidSourceImageName(t *testing.T) {
58 58
 	longTag := testutil.GenerateRandomAlphaOnlyString(121)
59 59
 	invalidTags := []string{"repo:fo$z$", "repo:Foo@3cc", "repo:Foo$3", "repo:Foo*3", "repo:Fo^3", "repo:Foo!3", "repo:%goodbye", "repo:#hashtagit", "repo:F)xcz(", "repo:-foo", "repo:..", longTag}
60 60
 	for _, repotag := range invalidTags {
61
-		repotag := repotag
62 61
 		t.Run("invalidTag/"+repotag, func(t *testing.T) {
63 62
 			t.Parallel()
64 63
 			err := client.ImageTag(ctx, "busybox", repotag)
... ...
@@ -111,7 +111,6 @@ func TestPingHeadFallback(t *testing.T) {
111 111
 	}
112 112
 
113 113
 	for _, tc := range tests {
114
-		tc := tc
115 114
 		t.Run(http.StatusText(tc.status), func(t *testing.T) {
116 115
 			var reqs []string
117 116
 			client := &Client{
... ...
@@ -50,7 +50,6 @@ func TestSetHostHeader(t *testing.T) {
50 50
 	}
51 51
 
52 52
 	for _, tc := range testCases {
53
-		tc := tc
54 53
 		t.Run(tc.host, func(t *testing.T) {
55 54
 			hostURL, err := ParseHostURL(tc.host)
56 55
 			assert.Check(t, err)