(t *testing.T)
| 87 | } |
| 88 | |
| 89 | func TestComposeService_Logs_Demux(t *testing.T) { |
| 90 | mockCtrl := gomock.NewController(t) |
| 91 | defer mockCtrl.Finish() |
| 92 | |
| 93 | api, cli := prepareMocks(mockCtrl) |
| 94 | tested, err := NewComposeService(cli) |
| 95 | assert.NilError(t, err) |
| 96 | |
| 97 | name := strings.ToLower(testProject) |
| 98 | |
| 99 | api.EXPECT().ContainerList(t.Context(), client.ContainerListOptions{ |
| 100 | All: true, |
| 101 | Filters: projectFilter(name).Add("label", oneOffFilter(false), compose.ConfigHashLabel), |
| 102 | }).Return( |
| 103 | client.ContainerListResult{ |
| 104 | Items: []containerType.Summary{ |
| 105 | testContainer("service", "c", false), |
| 106 | }, |
| 107 | }, |
| 108 | nil, |
| 109 | ) |
| 110 | |
| 111 | api.EXPECT(). |
| 112 | ContainerInspect(anyCancellableContext(), "c", gomock.Any()). |
| 113 | Return(client.ContainerInspectResult{ |
| 114 | Container: containerType.InspectResponse{ |
| 115 | ID: "c", |
| 116 | Config: &containerType.Config{Tty: false}, |
| 117 | }, |
| 118 | }, nil) |
| 119 | c1Reader, c1Writer := io.Pipe() |
| 120 | t.Cleanup(func() { |
| 121 | _ = c1Reader.Close() |
| 122 | _ = c1Writer.Close() |
| 123 | }) |
| 124 | c1Stdout := newStdWriter(c1Writer, stdcopy.Stdout) |
| 125 | c1Stderr := newStdWriter(c1Writer, stdcopy.Stderr) |
| 126 | go func() { |
| 127 | _, err := c1Stdout.Write([]byte("hello stdout\n")) |
| 128 | assert.NilError(t, err, "Writing to fake stdout") |
| 129 | _, err = c1Stderr.Write([]byte("hello stderr\n")) |
| 130 | assert.NilError(t, err, "Writing to fake stderr") |
| 131 | _ = c1Writer.Close() |
| 132 | }() |
| 133 | api.EXPECT().ContainerLogs(anyCancellableContext(), "c", gomock.Any()). |
| 134 | Return(c1Reader, nil) |
| 135 | |
| 136 | opts := compose.LogOptions{ |
| 137 | Project: &types.Project{ |
| 138 | Services: types.Services{ |
| 139 | "service": {Name: "service"}, |
| 140 | }, |
| 141 | }, |
| 142 | } |
| 143 | |
| 144 | consumer := &testLogConsumer{} |
| 145 | err = tested.Logs(t.Context(), name, consumer, opts) |
| 146 | assert.NilError(t, err) |
nothing calls this directly
no test coverage detected