Browse code

client: please the linters

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

Sebastiaan van Stijn authored on 2025/10/22 21:16:29
Showing 2 changed files
... ...
@@ -201,7 +201,7 @@ func TestImagePullWithoutErrors(t *testing.T) {
201 201
 func TestImagePullResponse(t *testing.T) {
202 202
 	r, w := io.Pipe()
203 203
 	response := internal.NewJSONMessageStream(r)
204
-	ctx, cancel := context.WithCancel(context.TODO())
204
+	ctx, cancel := context.WithCancel(t.Context())
205 205
 	messages := response.JSONMessages(ctx)
206 206
 	c := make(chan jsonmessage.JSONMessage)
207 207
 	go func() {
... ...
@@ -215,26 +215,28 @@ func TestImagePullResponse(t *testing.T) {
215 215
 	}()
216 216
 
217 217
 	// Check we receive message sent to json stream
218
-	w.Write([]byte(`{"id":"test"}`))
219
-	tiemout, _ := context.WithTimeout(context.TODO(), 100*time.Millisecond)
218
+	_, _ = w.Write([]byte(`{"id":"test"}`))
219
+	ctxTO, toCancel := context.WithTimeout(t.Context(), 100*time.Millisecond)
220
+	defer toCancel()
220 221
 	select {
221 222
 	case message := <-c:
222 223
 		assert.Equal(t, message.ID, "test")
223
-	case <-tiemout.Done():
224
+	case <-ctxTO.Done():
224 225
 		t.Fatal("expected message not received")
225 226
 	}
226 227
 
227 228
 	// Check context cancelation
228 229
 	cancel()
229
-	tiemout, _ = context.WithTimeout(context.TODO(), 100*time.Millisecond)
230
+	ctxTO2, toCancel2 := context.WithTimeout(t.Context(), 100*time.Millisecond)
231
+	defer toCancel2()
230 232
 	select {
231 233
 	case _, ok := <-c:
232 234
 		assert.Check(t, !ok)
233
-	case <-tiemout.Done():
235
+	case <-ctxTO2.Done():
234 236
 		t.Fatal("expected message not received")
235 237
 	}
236 238
 
237
-	// Check Close can be ran twice without error
239
+	// Check that Close can be called twice without error
238 240
 	assert.NilError(t, response.Close())
239 241
 	assert.NilError(t, response.Close())
240 242
 }
... ...
@@ -23,7 +23,7 @@ func TestImagePushReferenceError(t *testing.T) {
23 23
 	// An empty reference is an invalid reference
24 24
 	_, err = client.ImagePush(context.Background(), "", ImagePushOptions{})
25 25
 	assert.Check(t, is.ErrorContains(err, "invalid reference format"))
26
-	// An canonical reference cannot be pushed
26
+	// A canonical reference cannot be pushed
27 27
 	_, err = client.ImagePush(context.Background(), "repo@sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", ImagePushOptions{})
28 28
 	assert.Check(t, is.Error(err, "cannot push a digest reference"))
29 29
 }
... ...
@@ -46,12 +46,12 @@ func TestImagePushWithUnauthorizedErrorAndPrivilegeFuncError(t *testing.T) {
46 46
 	client, err := NewClientWithOpts(WithMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")))
47 47
 	assert.NilError(t, err)
48 48
 	privilegeFunc := func(_ context.Context) (string, error) {
49
-		return "", errors.New("Error requesting privilege")
49
+		return "", errors.New("error requesting privilege")
50 50
 	}
51 51
 	_, err = client.ImagePush(context.Background(), "myimage", ImagePushOptions{
52 52
 		PrivilegeFunc: privilegeFunc,
53 53
 	})
54
-	assert.Check(t, is.Error(err, "Error requesting privilege"))
54
+	assert.Check(t, is.Error(err, "error requesting privilege"))
55 55
 }
56 56
 
57 57
 func TestImagePushWithUnauthorizedErrorAndAnotherUnauthorizedError(t *testing.T) {