implement some ad-hoc mocks for responses

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-10-25 01:36:38 +02:00
parent 056e314645
commit 4afbd6146b
7 changed files with 48 additions and 21 deletions

View File

@ -4,8 +4,8 @@ import (
"bytes"
"context"
"encoding/hex"
"errors"
"io"
"net/http"
"testing"
"github.com/docker/cli/cli/trust"
@ -27,6 +27,14 @@ type fakeClient struct {
client.Client
}
type fakeStreamResult struct {
io.ReadCloser
client.ImagePushResponse // same interface as [client.ImagePullResponse]
}
func (e fakeStreamResult) Read(p []byte) (int, error) { return e.ReadCloser.Read(p) }
func (e fakeStreamResult) Close() error { return e.ReadCloser.Close() }
func (*fakeClient) Info(context.Context) (system.Info, error) {
return system.Info{}, nil
}
@ -37,7 +45,7 @@ func (*fakeClient) ImageInspect(context.Context, string, ...client.ImageInspectO
func (*fakeClient) ImagePush(context.Context, string, client.ImagePushOptions) (client.ImagePushResponse, error) {
// FIXME(thaJeztah): how to mock this?
return nil, errors.New("don't handle response")
return fakeStreamResult{ReadCloser: http.NoBody}, nil
}
func TestTrustInspectPrettyCommandErrors(t *testing.T) {

View File

@ -272,7 +272,6 @@ func TestSignCommandChangeListIsCleanedOnError(t *testing.T) {
}
func TestSignCommandLocalFlag(t *testing.T) {
t.Skip("FIXME(thaJeztah): how to mock this?")
cli := test.NewFakeCli(&fakeClient{})
cli.SetNotaryClient(notaryfake.GetEmptyTargetsNotaryRepository)
cmd := newSignCommand(cli)