Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cli/command/cli_options.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,6 +6,7 @@ import (
"strconv"

"github.com/docker/cli/cli/streams"
"github.com/docker/docker/client"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is correct but plugins are going to import the whole API client pkg now right?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm... let me check if it makes a difference (I somewhat expect it to already be in here, but maybe not).

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the cli/command/cli.go already depends on this, as client.APIClient is part of the interface;

typeCliinterface {
Client() client.APIClient

"github.com/moby/term"
)

Expand DownExpand Up@@ -86,3 +87,11 @@ func WithDefaultContextStoreConfig() DockerCliOption {
return nil
}
}

// WithAPIClient configures the cli to use the given API client.
func WithAPIClient(c client.APIClient) DockerCliOption {
return func(cli *DockerCli) error {
cli.client = c
return nil
}
}
35 changes: 31 additions & 4 deletions cmd/docker/builder_test.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,7 @@ package main

import (
"bytes"
"context"
"os"
"path/filepath"
"testing"
Expand All@@ -10,6 +11,8 @@ import (
"github.com/docker/cli/cli/context/store"
"github.com/docker/cli/cli/flags"
"github.com/docker/cli/internal/test/output"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
"gotest.tools/v3/assert"
"gotest.tools/v3/fs"
)
Expand DownExpand Up@@ -63,7 +66,11 @@ echo '{"SchemaVersion":"0.1.0","Vendor":"Docker Inc.","Version":"v0.6.3","ShortD
}

var b bytes.Buffer
dockerCli, err := command.NewDockerCli(command.WithInputStream(discard), command.WithCombinedStreams(&b))
dockerCli, err := command.NewDockerCli(
command.WithAPIClient(&fakeClient{}),
command.WithInputStream(discard),
command.WithCombinedStreams(&b),
)
assert.NilError(t, err)
assert.NilError(t, dockerCli.Initialize(flags.NewClientOptions()))

Expand DownExpand Up@@ -107,6 +114,14 @@ echo '{"SchemaVersion":"0.1.0","Vendor":"Docker Inc.","Version":"v0.6.3","ShortD
}
}

type fakeClient struct {
client.Client
}

func (c *fakeClient) Ping(_ context.Context) (types.Ping, error) {
return types.Ping{OSType: "linux"}, nil
}

func TestBuildkitDisabled(t *testing.T) {
t.Setenv("DOCKER_BUILDKIT", "0")

Expand All@@ -117,7 +132,11 @@ func TestBuildkitDisabled(t *testing.T) {

b := bytes.NewBuffer(nil)

dockerCli, err := command.NewDockerCli(command.WithInputStream(discard), command.WithCombinedStreams(b))
dockerCli, err := command.NewDockerCli(
command.WithAPIClient(&fakeClient{}),
command.WithInputStream(discard),
command.WithCombinedStreams(b),
)
assert.NilError(t, err)
assert.NilError(t, dockerCli.Initialize(flags.NewClientOptions()))
dockerCli.ConfigFile().CLIPluginsExtraDirs = []string{dir.Path()}
Expand DownExpand Up@@ -147,7 +166,11 @@ func TestBuilderBroken(t *testing.T) {

b := bytes.NewBuffer(nil)

dockerCli, err := command.NewDockerCli(command.WithInputStream(discard), command.WithCombinedStreams(b))
dockerCli, err := command.NewDockerCli(
command.WithAPIClient(&fakeClient{}),
command.WithInputStream(discard),
command.WithCombinedStreams(b),
)
assert.NilError(t, err)
assert.NilError(t, dockerCli.Initialize(flags.NewClientOptions()))
dockerCli.ConfigFile().CLIPluginsExtraDirs = []string{dir.Path()}
Expand DownExpand Up@@ -180,7 +203,11 @@ func TestBuilderBrokenEnforced(t *testing.T) {

b := bytes.NewBuffer(nil)

dockerCli, err := command.NewDockerCli(command.WithInputStream(discard), command.WithCombinedStreams(b))
dockerCli, err := command.NewDockerCli(
command.WithAPIClient(&fakeClient{}),
command.WithInputStream(discard),
command.WithCombinedStreams(b),
)
assert.NilError(t, err)
assert.NilError(t, dockerCli.Initialize(flags.NewClientOptions()))
dockerCli.ConfigFile().CLIPluginsExtraDirs = []string{dir.Path()}
Expand Down