MCPcopy Index your code
hub / github.com/docker/cli / TestRunLogs

Function TestRunLogs

cli/command/container/logs_test.go:14–60  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestRunLogs(t *testing.T) {
15 inspectFn := func(containerID string) (client.ContainerInspectResult, error) {
16 return client.ContainerInspectResult{
17 Container: container.InspectResponse{
18 Config: &container.Config{Tty: true},
19 State: &container.State{Running: false},
20 },
21 }, nil
22 }
23
24 testcases := []struct {
25 doc string
26 options *logsOptions
27 client *fakeClient
28 expectedError string
29 expectedOut string
30 expectedErr string
31 }{
32 {
33 doc: "successful logs",
34 expectedOut: "foo",
35 options: &logsOptions{},
36 client: &fakeClient{
37 logFunc: func(container string, opts client.ContainerLogsOptions) (client.ContainerLogsResult, error) {
38 // FIXME(thaJeztah): how to mock this?
39 return mockContainerLogsResult("foo"), nil
40 },
41 inspectFunc: inspectFn,
42 },
43 },
44 }
45
46 for _, testcase := range testcases {
47 t.Run(testcase.doc, func(t *testing.T) {
48 cli := test.NewFakeCli(testcase.client)
49
50 err := runLogs(context.TODO(), cli, testcase.options)
51 if testcase.expectedError != "" {
52 assert.ErrorContains(t, err, testcase.expectedError)
53 } else if !assert.Check(t, err) {
54 return
55 }
56 assert.Check(t, is.Equal(testcase.expectedOut, cli.OutBuffer().String()))
57 assert.Check(t, is.Equal(testcase.expectedErr, cli.ErrBuffer().String()))
58 })
59 }
60}

Callers

nothing calls this directly

Calls 5

OutBufferMethod · 0.95
ErrBufferMethod · 0.95
mockContainerLogsResultFunction · 0.85
runLogsFunction · 0.70
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…