MCPcopy
hub / github.com/docker/compose / TestComposeService_Logs_Demux

Function TestComposeService_Logs_Demux

pkg/compose/logs_test.go:89–148  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

87}
88
89func 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)

Callers

nothing calls this directly

Calls 15

LogsForContainerMethod · 0.95
prepareMocksFunction · 0.85
NewComposeServiceFunction · 0.85
projectFilterFunction · 0.85
oneOffFilterFunction · 0.85
testContainerFunction · 0.85
anyCancellableContextFunction · 0.85
newStdWriterFunction · 0.85
CloseMethod · 0.65
LogsMethod · 0.65
ContainerListMethod · 0.45
EXPECTMethod · 0.45

Tested by

no test coverage detected