Skip to content

Commit 9f9e405

Browse files
thaJeztahpull[bot]
authored andcommitted
daemon/logger/fluentd: add coverage for ValidateLogOpt(), parseAddress()
This exposed a bug where host is ignored on some valid cases (to be fixed). Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 04fe5e2 commit 9f9e405

2 files changed

Lines changed: 126 additions & 8 deletions

File tree

daemon/logger/fluentd/fluentd_test.go

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package fluentd // import "github.com/docker/docker/daemon/logger/fluentd"
22
import (
33
"testing"
44

5+
"github.com/google/go-cmp/cmp"
56
"gotest.tools/v3/assert"
67
)
78

@@ -22,3 +23,128 @@ func TestValidateLogOptReconnectInterval(t *testing.T) {
2223
})
2324
}
2425
}
26+
27+
func TestValidateLogOptAddress(t *testing.T) {
28+
29+
// paths to try
30+
paths := []string{"/", "/some-path"}
31+
32+
tests := []struct {
33+
addr string
34+
paths []string // paths to append to addr, should be an error for tcp/udp
35+
expected location
36+
expectedErr string
37+
}{
38+
{
39+
addr: "",
40+
expected: location{
41+
protocol: defaultProtocol,
42+
host: defaultHost,
43+
port: defaultPort,
44+
},
45+
},
46+
{
47+
addr: "192.168.1.1",
48+
paths: paths,
49+
expected: location{
50+
port: defaultPort,
51+
protocol: defaultProtocol,
52+
},
53+
},
54+
{
55+
addr: "[::1]",
56+
paths: paths,
57+
expected: location{
58+
port: defaultPort,
59+
protocol: defaultProtocol,
60+
},
61+
},
62+
{
63+
addr: "example.com",
64+
paths: paths,
65+
expected: location{
66+
port: defaultPort,
67+
protocol: defaultProtocol,
68+
},
69+
},
70+
{
71+
addr: "tcp://",
72+
paths: paths,
73+
expected: location{
74+
protocol: "tcp",
75+
port: defaultPort,
76+
},
77+
},
78+
{
79+
addr: "tcp://example.com",
80+
paths: paths,
81+
expected: location{
82+
protocol: "tcp",
83+
port: defaultPort,
84+
},
85+
},
86+
{
87+
addr: "tcp://example.com:65535",
88+
paths: paths,
89+
expected: location{
90+
protocol: "tcp",
91+
host: "example.com",
92+
port: 65535,
93+
},
94+
},
95+
{
96+
addr: "://",
97+
expectedErr: "invalid syntax",
98+
},
99+
{
100+
addr: "something://",
101+
expectedErr: "invalid syntax",
102+
},
103+
{
104+
addr: "corrupted:c",
105+
expectedErr: "invalid syntax",
106+
},
107+
{
108+
addr: "tcp://example.com:port",
109+
expectedErr: "invalid port",
110+
},
111+
{
112+
addr: "tcp://example.com:-1",
113+
expectedErr: "invalid port",
114+
},
115+
{
116+
addr: "unix:///some/socket.sock",
117+
expected: location{
118+
protocol: "unix",
119+
path: "/some/socket.sock",
120+
},
121+
},
122+
{
123+
addr: "unix:///some/socket.sock:80", // unusual, but technically valid
124+
expected: location{
125+
protocol: "unix",
126+
path: "/some/socket.sock:80",
127+
},
128+
},
129+
}
130+
for _, tc := range tests {
131+
tc := tc
132+
if len(tc.paths) == 0 {
133+
tc.paths = []string{""}
134+
}
135+
for _, path := range tc.paths {
136+
address := tc.addr + path
137+
t.Run(address, func(t *testing.T) {
138+
err := ValidateLogOpt(map[string]string{addressKey: address})
139+
if tc.expectedErr != "" {
140+
assert.ErrorContains(t, err, tc.expectedErr)
141+
return
142+
}
143+
144+
assert.NilError(t, err)
145+
addr, _ := parseAddress(address)
146+
assert.DeepEqual(t, tc.expected, *addr, cmp.AllowUnexported(location{}))
147+
})
148+
}
149+
}
150+
}

integration-cli/docker_cli_daemon_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,14 +1671,6 @@ func (s *DockerDaemonSuite) TestDaemonRestartLocalVolumes(c *testing.T) {
16711671
assert.NilError(c, err, out)
16721672
}
16731673

1674-
// FIXME(vdemeester) should be a unit test
1675-
func (s *DockerDaemonSuite) TestDaemonCorruptedFluentdAddress(c *testing.T) {
1676-
d := daemon.New(c, dockerBinary, dockerdBinary, testdaemon.WithEnvironment(testEnv.Execution))
1677-
assert.Assert(c, d.StartWithError("--log-driver=fluentd", "--log-opt", "fluentd-address=corrupted:c") != nil)
1678-
expected := "invalid fluentd-address corrupted:c: "
1679-
icmd.RunCommand("grep", expected, d.LogFileName()).Assert(c, icmd.Success)
1680-
}
1681-
16821674
// FIXME(vdemeester) Use a new daemon instance instead of the Suite one
16831675
func (s *DockerDaemonSuite) TestDaemonStartWithoutHost(c *testing.T) {
16841676
s.d.UseDefaultHost = true

0 commit comments

Comments
 (0)