(t *testing.T)
| 12 | ) |
| 13 | |
| 14 | func 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…