2016-11-14 18:53:53 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2018-04-19 22:30:59 +00:00
|
|
|
"context"
|
2016-11-14 18:53:53 +00:00
|
|
|
"strings"
|
2019-09-09 21:06:12 +00:00
|
|
|
"testing"
|
2016-11-14 18:53:53 +00:00
|
|
|
|
2017-05-24 03:56:26 +00:00
|
|
|
"github.com/docker/docker/client"
|
2023-07-28 08:38:51 +00:00
|
|
|
"github.com/docker/docker/integration-cli/cli"
|
2023-07-14 18:02:38 +00:00
|
|
|
"github.com/docker/docker/testutil"
|
2020-02-07 13:39:24 +00:00
|
|
|
"gotest.tools/v3/assert"
|
2016-11-14 18:53:53 +00:00
|
|
|
)
|
|
|
|
|
2022-06-16 21:32:10 +00:00
|
|
|
type DockerCLIPluginLogDriverSuite struct {
|
|
|
|
ds *DockerSuite
|
|
|
|
}
|
|
|
|
|
2023-07-14 18:02:38 +00:00
|
|
|
func (s *DockerCLIPluginLogDriverSuite) TearDownTest(ctx context.Context, c *testing.T) {
|
|
|
|
s.ds.TearDownTest(ctx, c)
|
2022-06-16 21:32:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerCLIPluginLogDriverSuite) OnTimeout(c *testing.T) {
|
|
|
|
s.ds.OnTimeout(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerCLIPluginLogDriverSuite) TestPluginLogDriver(c *testing.T) {
|
2016-11-14 18:53:53 +00:00
|
|
|
testRequires(c, IsAmd64, DaemonIsLinux)
|
|
|
|
|
2023-07-28 08:38:51 +00:00
|
|
|
const pluginName = "cpuguy83/docker-logdriver-test:latest"
|
2016-11-14 18:53:53 +00:00
|
|
|
|
2023-07-28 08:38:51 +00:00
|
|
|
cli.DockerCmd(c, "plugin", "install", pluginName)
|
|
|
|
cli.DockerCmd(c, "run", "--log-driver", pluginName, "--name=test", "busybox", "echo", "hello")
|
|
|
|
out := cli.DockerCmd(c, "logs", "test").Combined()
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, strings.TrimSpace(out), "hello")
|
2016-11-14 18:53:53 +00:00
|
|
|
|
2023-07-28 08:38:51 +00:00
|
|
|
cli.DockerCmd(c, "start", "-a", "test")
|
|
|
|
out = cli.DockerCmd(c, "logs", "test").Combined()
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Equal(c, strings.TrimSpace(out), "hello\nhello")
|
2016-11-14 18:53:53 +00:00
|
|
|
|
2023-07-28 08:38:51 +00:00
|
|
|
cli.DockerCmd(c, "rm", "test")
|
|
|
|
cli.DockerCmd(c, "plugin", "disable", pluginName)
|
|
|
|
cli.DockerCmd(c, "plugin", "rm", pluginName)
|
2016-11-14 18:53:53 +00:00
|
|
|
}
|
2017-04-11 21:21:21 +00:00
|
|
|
|
|
|
|
// Make sure log drivers are listed in info, and v2 plugins are not.
|
2022-06-16 21:32:10 +00:00
|
|
|
func (s *DockerCLIPluginLogDriverSuite) TestPluginLogDriverInfoList(c *testing.T) {
|
2017-04-11 21:21:21 +00:00
|
|
|
testRequires(c, IsAmd64, DaemonIsLinux)
|
2023-07-28 08:38:51 +00:00
|
|
|
const pluginName = "cpuguy83/docker-logdriver-test"
|
2017-04-11 21:21:21 +00:00
|
|
|
|
2023-07-28 08:38:51 +00:00
|
|
|
cli.DockerCmd(c, "plugin", "install", pluginName)
|
2017-05-24 03:56:26 +00:00
|
|
|
|
2023-04-03 11:00:29 +00:00
|
|
|
apiClient, err := client.NewClientWithOpts(client.FromEnv)
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2023-04-03 11:00:29 +00:00
|
|
|
defer apiClient.Close()
|
2017-04-11 21:21:21 +00:00
|
|
|
|
2023-07-14 18:02:38 +00:00
|
|
|
info, err := apiClient.Info(testutil.GetContext(c))
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.NilError(c, err)
|
2017-05-24 03:56:26 +00:00
|
|
|
|
2017-04-11 21:21:21 +00:00
|
|
|
drivers := strings.Join(info.Plugins.Log, " ")
|
2019-04-04 13:23:19 +00:00
|
|
|
assert.Assert(c, strings.Contains(drivers, "json-file"))
|
|
|
|
assert.Assert(c, !strings.Contains(drivers, pluginName))
|
2017-04-11 21:21:21 +00:00
|
|
|
}
|