mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
client: Client.ContainerLogs: close reader on context cancellation
Use a cancelReadCloser to automatically close the reader when the context is cancelled. Consumers are still recommended to manually close the reader, but the cancelReadCloser makes the Close idempotent. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -100,14 +100,14 @@ func TestNetworkLoopbackNat(t *testing.T) {
|
||||
|
||||
poll.WaitOn(t, container.IsStopped(ctx, apiClient, cID))
|
||||
|
||||
body, err := apiClient.ContainerLogs(ctx, cID, client.ContainerLogsOptions{
|
||||
logs, err := apiClient.ContainerLogs(ctx, cID, client.ContainerLogsOptions{
|
||||
ShowStdout: true,
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
defer body.Close()
|
||||
defer logs.Close()
|
||||
|
||||
var b bytes.Buffer
|
||||
_, err = io.Copy(&b, body)
|
||||
_, err = io.Copy(&b, logs)
|
||||
assert.NilError(t, err)
|
||||
|
||||
assert.Check(t, is.Equal(msg, strings.TrimSpace(b.String())))
|
||||
|
||||
Reference in New Issue
Block a user