Files
moby/integration/plugin/logging/read_test.go
Sebastiaan van Stijn 786e6d80ba integration: fix empty-lines (revive)
integration/config/config_test.go:106:31: empty-lines: extra empty line at the end of a block (revive)
    integration/secret/secret_test.go:106:31: empty-lines: extra empty line at the end of a block (revive)
    integration/network/service_test.go:58:50: empty-lines: extra empty line at the end of a block (revive)
    integration/network/service_test.go:401:58: empty-lines: extra empty line at the end of a block (revive)
    integration/system/event_test.go:30:38: empty-lines: extra empty line at the end of a block (revive)
    integration/plugin/logging/read_test.go:19:41: empty-lines: extra empty line at the end of a block (revive)
    integration/service/list_test.go:30:48: empty-lines: extra empty line at the end of a block (revive)
    integration/service/create_test.go:400:46: empty-lines: extra empty line at the start of a block (revive)
    integration/container/logs_test.go:156:42: empty-lines: extra empty line at the end of a block (revive)
    integration/container/daemon_linux_test.go:135:44: empty-lines: extra empty line at the end of a block (revive)
    integration/container/restart_test.go:160:62: empty-lines: extra empty line at the end of a block (revive)
    integration/container/wait_test.go:181:47: empty-lines: extra empty line at the end of a block (revive)
    integration/container/restart_test.go:116:30: empty-lines: extra empty line at the end of a block (revive)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-09-28 01:58:50 +02:00

92 lines
2.3 KiB
Go

package logging
import (
"bytes"
"context"
"runtime"
"strings"
"testing"
"time"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/pkg/stdcopy"
"github.com/docker/docker/testutil/daemon"
"gotest.tools/v3/assert"
)
// TestReadPluginNoRead tests that reads are supported even if the plugin isn't capable.
func TestReadPluginNoRead(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("no unix domain sockets on Windows")
}
t.Parallel()
d := daemon.New(t)
d.StartWithBusybox(t, "--iptables=false")
defer d.Stop(t)
client, err := d.NewClient()
assert.Assert(t, err)
createPlugin(t, client, "test", "discard", asLogDriver)
ctx := context.Background()
err = client.PluginEnable(ctx, "test", types.PluginEnableOptions{Timeout: 30})
assert.Check(t, err)
d.Stop(t)
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,
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)
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)
errCh := make(chan error, 1)
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)
}
assert.Assert(t, strings.TrimSpace(buf.String()) == "hello world", buf.Bytes())
})
}
}