mirror of
https://github.com/moby/moby.git
synced 2026-08-13 17:06:44 +00:00
internal/testutil/daemon: Correctly check image load response
LoadImage checked the immediate ImageLoad error, but then discarded the response body. The daemon can report load failures in that JSON message stream, so tests could miss a structured load error and continue after a failed image load. Parse the ImageLoad response with jsonmessage.DisplayStream and discard only the rendered output, so streamed errors fail the test. Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
@@ -24,6 +24,7 @@ import (
|
||||
"github.com/moby/moby/api/types/events"
|
||||
"github.com/moby/moby/api/types/system"
|
||||
"github.com/moby/moby/client"
|
||||
"github.com/moby/moby/client/pkg/jsonmessage"
|
||||
"github.com/moby/moby/client/pkg/stringid"
|
||||
"github.com/moby/moby/v2/daemon/container"
|
||||
"github.com/moby/moby/v2/internal/testutil/request"
|
||||
@@ -933,8 +934,9 @@ func (d *Daemon) LoadImage(ctx context.Context, t testing.TB, img string) {
|
||||
|
||||
resp, err := c.ImageLoad(ctx, reader, client.ImageLoadWithQuiet(true))
|
||||
assert.NilError(t, err, "[%s] failed to load %s", d.id, img)
|
||||
_, _ = io.Copy(io.Discard, resp)
|
||||
_ = resp.Close()
|
||||
defer func() { _ = resp.Close() }()
|
||||
|
||||
assert.NilError(t, jsonmessage.DisplayStream(resp, io.Discard), "[%s] failed to read load response for %s", d.id, img)
|
||||
}
|
||||
|
||||
func (d *Daemon) getClientConfig() (*clientConfig, error) {
|
||||
|
||||
Reference in New Issue
Block a user