Merge pull request #51266 from thaJeztah/please_linters

client: please the linters
This commit is contained in:
Akihiro Suda
2025-10-23 01:42:46 +09:00
committed by GitHub
2 changed files with 12 additions and 10 deletions

View File

@@ -201,7 +201,7 @@ func TestImagePullWithoutErrors(t *testing.T) {
func TestImagePullResponse(t *testing.T) {
r, w := io.Pipe()
response := internal.NewJSONMessageStream(r)
ctx, cancel := context.WithCancel(context.TODO())
ctx, cancel := context.WithCancel(t.Context())
messages := response.JSONMessages(ctx)
c := make(chan jsonmessage.JSONMessage)
go func() {
@@ -215,26 +215,28 @@ func TestImagePullResponse(t *testing.T) {
}()
// Check we receive message sent to json stream
w.Write([]byte(`{"id":"test"}`))
tiemout, _ := context.WithTimeout(context.TODO(), 100*time.Millisecond)
_, _ = w.Write([]byte(`{"id":"test"}`))
ctxTO, toCancel := context.WithTimeout(t.Context(), 100*time.Millisecond)
defer toCancel()
select {
case message := <-c:
assert.Equal(t, message.ID, "test")
case <-tiemout.Done():
case <-ctxTO.Done():
t.Fatal("expected message not received")
}
// Check context cancelation
cancel()
tiemout, _ = context.WithTimeout(context.TODO(), 100*time.Millisecond)
ctxTO2, toCancel2 := context.WithTimeout(t.Context(), 100*time.Millisecond)
defer toCancel2()
select {
case _, ok := <-c:
assert.Check(t, !ok)
case <-tiemout.Done():
case <-ctxTO2.Done():
t.Fatal("expected message not received")
}
// Check Close can be ran twice without error
// Check that Close can be called twice without error
assert.NilError(t, response.Close())
assert.NilError(t, response.Close())
}

View File

@@ -23,7 +23,7 @@ func TestImagePushReferenceError(t *testing.T) {
// An empty reference is an invalid reference
_, err = client.ImagePush(context.Background(), "", ImagePushOptions{})
assert.Check(t, is.ErrorContains(err, "invalid reference format"))
// An canonical reference cannot be pushed
// A canonical reference cannot be pushed
_, err = client.ImagePush(context.Background(), "repo@sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", ImagePushOptions{})
assert.Check(t, is.Error(err, "cannot push a digest reference"))
}
@@ -46,12 +46,12 @@ func TestImagePushWithUnauthorizedErrorAndPrivilegeFuncError(t *testing.T) {
client, err := NewClientWithOpts(WithMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")))
assert.NilError(t, err)
privilegeFunc := func(_ context.Context) (string, error) {
return "", errors.New("Error requesting privilege")
return "", errors.New("error requesting privilege")
}
_, err = client.ImagePush(context.Background(), "myimage", ImagePushOptions{
PrivilegeFunc: privilegeFunc,
})
assert.Check(t, is.Error(err, "Error requesting privilege"))
assert.Check(t, is.Error(err, "error requesting privilege"))
}
func TestImagePushWithUnauthorizedErrorAndAnotherUnauthorizedError(t *testing.T) {