Inject mock more directly

This commit is contained in:
Bryce Lampe
2025-05-09 10:05:35 -07:00
parent 53d91af128
commit 1c575b0966
7 changed files with 26 additions and 31 deletions

View File

@@ -46,7 +46,9 @@ var (
var _indexExamples string
// Index is an OCI index or manifest list on a remote registry.
type Index struct{}
type Index struct {
docker Client
}
// IndexArgs instantiate an Index.
type IndexArgs struct {
@@ -351,12 +353,13 @@ func (i *Index) client(
_ IndexState,
args IndexArgs,
) (Client, error) {
cfg := infer.GetConfig[Config](ctx)
if cli, ok := ctx.Value(_mockClientKey).(Client); ok {
return cli, nil
// Use our mock client, if it's set.
if i.docker != nil {
return i.docker, nil
}
cfg := infer.GetConfig[Config](ctx)
// We prefer auth from args, the provider, and state in that order. We
// build a slice in reverse order because wrap() will overwrite earlier
// entries with later ones.