@@ -2,6 +2,7 @@ package main
22
33import (
44 "bytes"
5+ "context"
56 "os"
67 "path/filepath"
78 "testing"
@@ -10,6 +11,8 @@ import (
1011 "github.com/docker/cli/cli/context/store"
1112 "github.com/docker/cli/cli/flags"
1213 "github.com/docker/cli/internal/test/output"
14+ "github.com/docker/docker/api/types"
15+ "github.com/docker/docker/client"
1316 "gotest.tools/v3/assert"
1417 "gotest.tools/v3/fs"
1518)
@@ -63,7 +66,11 @@ echo '{"SchemaVersion":"0.1.0","Vendor":"Docker Inc.","Version":"v0.6.3","ShortD
6366 }
6467
6568 var b bytes.Buffer
66- dockerCli , err := command .NewDockerCli (command .WithInputStream (discard ), command .WithCombinedStreams (& b ))
69+ dockerCli , err := command .NewDockerCli (
70+ command .WithAPIClient (& fakeClient {}),
71+ command .WithInputStream (discard ),
72+ command .WithCombinedStreams (& b ),
73+ )
6774 assert .NilError (t , err )
6875 assert .NilError (t , dockerCli .Initialize (flags .NewClientOptions ()))
6976
@@ -107,6 +114,14 @@ echo '{"SchemaVersion":"0.1.0","Vendor":"Docker Inc.","Version":"v0.6.3","ShortD
107114 }
108115}
109116
117+ type fakeClient struct {
118+ client.Client
119+ }
120+
121+ func (c * fakeClient ) Ping (_ context.Context ) (types.Ping , error ) {
122+ return types.Ping {OSType : "linux" }, nil
123+ }
124+
110125func TestBuildkitDisabled (t * testing.T ) {
111126 t .Setenv ("DOCKER_BUILDKIT" , "0" )
112127
@@ -117,7 +132,11 @@ func TestBuildkitDisabled(t *testing.T) {
117132
118133 b := bytes .NewBuffer (nil )
119134
120- dockerCli , err := command .NewDockerCli (command .WithInputStream (discard ), command .WithCombinedStreams (b ))
135+ dockerCli , err := command .NewDockerCli (
136+ command .WithAPIClient (& fakeClient {}),
137+ command .WithInputStream (discard ),
138+ command .WithCombinedStreams (b ),
139+ )
121140 assert .NilError (t , err )
122141 assert .NilError (t , dockerCli .Initialize (flags .NewClientOptions ()))
123142 dockerCli .ConfigFile ().CLIPluginsExtraDirs = []string {dir .Path ()}
@@ -147,7 +166,11 @@ func TestBuilderBroken(t *testing.T) {
147166
148167 b := bytes .NewBuffer (nil )
149168
150- dockerCli , err := command .NewDockerCli (command .WithInputStream (discard ), command .WithCombinedStreams (b ))
169+ dockerCli , err := command .NewDockerCli (
170+ command .WithAPIClient (& fakeClient {}),
171+ command .WithInputStream (discard ),
172+ command .WithCombinedStreams (b ),
173+ )
151174 assert .NilError (t , err )
152175 assert .NilError (t , dockerCli .Initialize (flags .NewClientOptions ()))
153176 dockerCli .ConfigFile ().CLIPluginsExtraDirs = []string {dir .Path ()}
@@ -180,7 +203,11 @@ func TestBuilderBrokenEnforced(t *testing.T) {
180203
181204 b := bytes .NewBuffer (nil )
182205
183- dockerCli , err := command .NewDockerCli (command .WithInputStream (discard ), command .WithCombinedStreams (b ))
206+ dockerCli , err := command .NewDockerCli (
207+ command .WithAPIClient (& fakeClient {}),
208+ command .WithInputStream (discard ),
209+ command .WithCombinedStreams (b ),
210+ )
184211 assert .NilError (t , err )
185212 assert .NilError (t , dockerCli .Initialize (flags .NewClientOptions ()))
186213 dockerCli .ConfigFile ().CLIPluginsExtraDirs = []string {dir .Path ()}
0 commit comments