|
@@ -29,45 +29,62 @@ func TestReadPluginNoRead(t *testing.T) {
|
|
|
createPlugin(t, client, "test", "discard", asLogDriver)
|
|
|
|
|
|
ctx := context.Background()
|
|
|
- defer func() {
|
|
|
- err = client.PluginRemove(ctx, "test", types.PluginRemoveOptions{Force: true})
|
|
|
- assert.Check(t, err)
|
|
|
- }()
|
|
|
|
|
|
err = client.PluginEnable(ctx, "test", types.PluginEnableOptions{Timeout: 30})
|
|
|
assert.Check(t, err)
|
|
|
+ d.Stop(t)
|
|
|
|
|
|
- c, err := client.ContainerCreate(ctx,
|
|
|
- &container.Config{
|
|
|
- Image: "busybox",
|
|
|
- Cmd: []string{"/bin/echo", "hello world"},
|
|
|
- },
|
|
|
- &container.HostConfig{LogConfig: container.LogConfig{Type: "test"}},
|
|
|
- nil,
|
|
|
- "",
|
|
|
- )
|
|
|
- assert.Assert(t, err)
|
|
|
+ cfg := &container.Config{
|
|
|
+ Image: "busybox",
|
|
|
+ Cmd: []string{"/bin/echo", "hello world"},
|
|
|
+ }
|
|
|
+ for desc, test := range map[string]struct {
|
|
|
+ dOpts []string
|
|
|
+ logsSupported bool
|
|
|
+ }{
|
|
|
+ "default": {logsSupported: true},
|
|
|
+ "disabled caching": {[]string{"--log-opt=cache-disabled=true"}, false},
|
|
|
+ "explicitly enabled caching": {[]string{"--log-opt=cache-disabled=false"}, true},
|
|
|
+ } {
|
|
|
+ t.Run(desc, func(t *testing.T) {
|
|
|
+ d.Start(t, append([]string{"--iptables=false"}, test.dOpts...)...)
|
|
|
+ defer d.Stop(t)
|
|
|
+ c, err := client.ContainerCreate(ctx,
|
|
|
+ cfg,
|
|
|
+ &container.HostConfig{LogConfig: container.LogConfig{Type: "test"}},
|
|
|
+ nil,
|
|
|
+ "",
|
|
|
+ )
|
|
|
+ assert.Assert(t, err)
|
|
|
+ defer client.ContainerRemove(ctx, c.ID, types.ContainerRemoveOptions{Force: true})
|
|
|
|
|
|
- err = client.ContainerStart(ctx, c.ID, types.ContainerStartOptions{})
|
|
|
- assert.Assert(t, err)
|
|
|
+ err = client.ContainerStart(ctx, c.ID, types.ContainerStartOptions{})
|
|
|
+ assert.Assert(t, err)
|
|
|
|
|
|
- logs, err := client.ContainerLogs(ctx, c.ID, types.ContainerLogsOptions{ShowStdout: true})
|
|
|
- assert.Assert(t, err)
|
|
|
- defer logs.Close()
|
|
|
+ logs, err := client.ContainerLogs(ctx, c.ID, types.ContainerLogsOptions{ShowStdout: true})
|
|
|
+ if !test.logsSupported {
|
|
|
+ assert.Assert(t, err != nil)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ assert.Assert(t, err)
|
|
|
+ defer logs.Close()
|
|
|
|
|
|
- buf := bytes.NewBuffer(nil)
|
|
|
+ buf := bytes.NewBuffer(nil)
|
|
|
|
|
|
- errCh := make(chan error)
|
|
|
- go func() {
|
|
|
- _, err := stdcopy.StdCopy(buf, buf, logs)
|
|
|
- errCh <- err
|
|
|
- }()
|
|
|
+ errCh := make(chan error)
|
|
|
+ go func() {
|
|
|
+ _, err := stdcopy.StdCopy(buf, buf, logs)
|
|
|
+ errCh <- err
|
|
|
+ }()
|
|
|
|
|
|
- select {
|
|
|
- case <-time.After(60 * time.Second):
|
|
|
- t.Fatal("timeout waiting for IO to complete")
|
|
|
- case err := <-errCh:
|
|
|
- assert.Assert(t, err)
|
|
|
+ select {
|
|
|
+ case <-time.After(60 * time.Second):
|
|
|
+ t.Fatal("timeout waiting for IO to complete")
|
|
|
+ case err := <-errCh:
|
|
|
+ assert.Assert(t, err)
|
|
|
+ }
|
|
|
+ assert.Assert(t, strings.TrimSpace(buf.String()) == "hello world", buf.Bytes())
|
|
|
+ })
|
|
|
}
|
|
|
- assert.Assert(t, strings.TrimSpace(buf.String()) == "hello world", buf.Bytes())
|
|
|
+
|
|
|
}
|