Skip to content

Commit c4264f9

Browse files
committed
test: e2e exit codes
Signed-off-by: Alano Terblanche <[email protected]>
1 parent 4194878 commit c4264f9

File tree

1 file changed

+94
-29
lines changed

1 file changed

+94
-29
lines changed

e2e/global/cli_test.go

Lines changed: 94 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"testing"
1313
"time"
1414

15+
"github.com/docker/cli/e2e/internal/fixtures"
1516
"github.com/docker/cli/internal/test"
1617
"github.com/docker/cli/internal/test/environment"
1718
"gotest.tools/v3/assert"
@@ -80,6 +81,9 @@ func TestPromptExitCode(t *testing.T) {
8081
ctx, cancel := context.WithCancel(context.Background())
8182
t.Cleanup(cancel)
8283

84+
dir := fixtures.SetupConfigFile(t)
85+
t.Cleanup(dir.Remove)
86+
8387
testCases := []struct {
8488
name string
8589
run func(t *testing.T) icmd.Cmd
@@ -120,26 +124,87 @@ func TestPromptExitCode(t *testing.T) {
120124
return icmd.Command("docker", "system", "prune")
121125
},
122126
},
123-
{
124-
name: "plugin install",
125-
run: func(t *testing.T) icmd.Cmd {
126-
t.Helper()
127-
return icmd.Command("docker", "plugin", "install", "--disable", "vieux/sshfs")
128-
},
129-
},
130-
{
131-
name: "plugin upgrade",
132-
run: func(t *testing.T) icmd.Cmd {
133-
t.Helper()
134-
icmd.RunCmd(
135-
icmd.Command("docker", "plugin", "install", "--disable", "--grant-all-permissions", "vieux/sshfs"),
136-
)
137-
icmd.RunCmd(
138-
icmd.Command("docker", "plugin", "disable", "vieux/sshfs"),
139-
)
140-
return icmd.Command("docker", "plugin", "upgrade", "vieux/sshfs:latest", "vieux/sshfs:next")
141-
},
142-
},
127+
// {
128+
// name: "plugin install",
129+
// run: func(t *testing.T) icmd.Cmd {
130+
// t.Helper()
131+
// skip.If(t, versions.LessThan(environment.DaemonAPIVersion(t), "1.44"))
132+
// skip.If(t, environment.SkipPluginTests())
133+
//
134+
// p := &types.PluginConfig{
135+
// Interface: types.PluginConfigInterface{
136+
// Socket: "basic.sock",
137+
// Types: []types.PluginInterfaceType{{Capability: "docker.dummy/1.0"}},
138+
// },
139+
// Entrypoint: []string{"/plugin-install"},
140+
// }
141+
// configJSON, err := json.Marshal(p)
142+
// assert.NilError(t, err)
143+
//
144+
// pluginDir := fs.NewDir(t, "plugin_test_install",
145+
// fs.WithFile("config.json", string(configJSON), fs.WithMode(0o644)),
146+
// fs.WithDir("rootfs", fs.WithMode(0o755)),
147+
// )
148+
// t.Cleanup(pluginDir.Remove)
149+
//
150+
// plugin := "registry:5000/plugin-content-trust-install:latest"
151+
// opts := []icmd.CmdOp{
152+
// fixtures.WithConfig(dir.Path()),
153+
// fixtures.WithTrust,
154+
// fixtures.WithNotary,
155+
// }
156+
//
157+
// icmd.RunCmd(icmd.Command("docker", "plugin", "create", plugin, pluginDir.Path()), opts...).Assert(t, icmd.Success)
158+
// icmd.RunCmd(icmd.Command("docker", "plugin", "push", plugin), append(opts, fixtures.WithPassphrase("foo", "bar"))...).Assert(t, icmd.Success)
159+
// icmd.RunCmd(icmd.Command("docker", "plugin", "rm", "-f", plugin), opts...).Assert(t, icmd.Success)
160+
// return icmd.Command("docker", "plugin", "install", plugin)
161+
// },
162+
// },
163+
// {
164+
// name: "plugin upgrade",
165+
// run: func(t *testing.T) icmd.Cmd {
166+
// t.Helper()
167+
// skip.If(t, versions.LessThan(environment.DaemonAPIVersion(t), "1.44"))
168+
// skip.If(t, environment.SkipPluginTests())
169+
//
170+
// p := &types.PluginConfig{
171+
// Interface: types.PluginConfigInterface{
172+
// Socket: "basic2.sock",
173+
// Types: []types.PluginInterfaceType{{Capability: "docker.dummy/1.0"}},
174+
// },
175+
// Entrypoint: []string{"/plugin-upgrade"},
176+
// }
177+
// configJSON, err := json.Marshal(p)
178+
// assert.NilError(t, err)
179+
//
180+
// pluginDir := fs.NewDir(t, "plugin_test_upgrade",
181+
// fs.WithFile("config.json", string(configJSON), fs.WithMode(0o644)),
182+
// fs.WithDir("rootfs", fs.WithMode(0o755)),
183+
// )
184+
// t.Cleanup(pluginDir.Remove)
185+
//
186+
// plugin := "registry:5000/plugin-content-trust-upgrade"
187+
// icmd.RunCommand("docker", "plugin", "rm", "-f", plugin+":latest")
188+
// icmd.RunCommand("docker", "plugin", "rm", "-f", plugin+":next")
189+
// icmd.RunCommand("docker", "plugin", "create", plugin+":latest", pluginDir.Path())
190+
// icmd.RunCommand("docker", "plugin", "create", plugin+":next", pluginDir.Path())
191+
// icmd.RunCmd(icmd.Command("docker", "plugin", "push", plugin+":latest"),
192+
// fixtures.WithConfig(dir.Path()),
193+
// fixtures.WithTrust,
194+
// fixtures.WithNotary,
195+
// fixtures.WithPassphrase("foo1", "bar1"),
196+
// )
197+
// icmd.RunCmd(icmd.Command("docker", "plugin", "push", plugin+":next"),
198+
// fixtures.WithConfig(dir.Path()),
199+
// fixtures.WithTrust,
200+
// fixtures.WithNotary,
201+
// fixtures.WithPassphrase("foo2", "bar2"),
202+
// )
203+
//
204+
// icmd.RunCommand("docker", "plugin", "install", "--disable", "--grant-all-permissions", plugin+":latest")
205+
// return icmd.Command("docker", "plugin", "upgrade", plugin+":latest", plugin+":next")
206+
// },
207+
// },
143208
{
144209
name: "revoke trust",
145210
run: func(t *testing.T) icmd.Cmd {
@@ -159,7 +224,7 @@ func TestPromptExitCode(t *testing.T) {
159224
t.Parallel()
160225

161226
buf := new(bytes.Buffer)
162-
bufioWriter := bufio.NewWriter(buf)
227+
bufioWriter := bufio.NewWriterSize(buf, 4096*4)
163228

164229
writeDone := make(chan struct{})
165230
w := test.NewWriterWithHook(bufioWriter, func(p []byte) {
@@ -168,19 +233,19 @@ func TestPromptExitCode(t *testing.T) {
168233

169234
r, _ := io.Pipe()
170235
defer r.Close()
171-
172236
result := icmd.StartCmd(tc.run(t),
237+
fixtures.WithConfig(dir.Path()),
238+
fixtures.WithNotary,
239+
fixtures.WithTrust,
173240
icmd.WithStdout(w),
174241
icmd.WithStderr(w),
175242
icmd.WithStdin(r))
176243

177-
writeCtx, writeCancel := context.WithTimeout(ctx, 500*time.Millisecond)
178-
defer writeCancel()
244+
writeCtx, writeCtxCancel := context.WithTimeout(ctx, 5*time.Second)
245+
defer writeCtxCancel()
179246

180-
// wait for the prompt to be ready
181247
select {
182248
case <-writeCtx.Done():
183-
t.Fatalf("command did not write prompt to stdout")
184249
case <-writeDone:
185250
// drain the channel for future writes
186251
go func() {
@@ -194,10 +259,10 @@ func TestPromptExitCode(t *testing.T) {
194259
}()
195260
}
196261

197-
// ensure we have written to the prompt
198262
assert.NilError(t, bufioWriter.Flush())
199-
assert.Check(t, buf.Len() > 0)
200-
assert.Check(t, strings.Contains(buf.String(), "[y/N]"))
263+
assert.Check(t, buf.Len() > 0, "expected prompt to be written to stdout")
264+
assert.Check(t, strings.Contains(buf.String(), "[y/N]"), "expected prompt to be written to stdout: %s", buf.String())
265+
201266
buf.Reset()
202267

203268
assert.NilError(t, result.Cmd.Process.Signal(syscall.SIGINT))

0 commit comments

Comments
 (0)