mirror of
https://github.com/moby/moby.git
synced 2026-08-03 06:30:59 +00:00
integration/internal: Handle Buildkit in GetImageIDFromBody
BuildKit emits some additional events during build and they are not `build.Result` so don't fail if we encounter one. Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
@@ -29,12 +29,10 @@ func Do(ctx context.Context, t *testing.T, apiClient client.APIClient, buildCtx
|
||||
|
||||
// GetImageIDFromBody reads the image ID from the build response body.
|
||||
func GetImageIDFromBody(t *testing.T, body io.Reader) string {
|
||||
var (
|
||||
jm jsonmessage.JSONMessage
|
||||
br build.Result
|
||||
dec = json.NewDecoder(body)
|
||||
)
|
||||
var id string
|
||||
dec := json.NewDecoder(body)
|
||||
for {
|
||||
var jm jsonmessage.JSONMessage
|
||||
err := dec.Decode(&jm)
|
||||
if err == io.EOF {
|
||||
break
|
||||
@@ -43,10 +41,18 @@ func GetImageIDFromBody(t *testing.T, body io.Reader) string {
|
||||
if jm.Aux == nil {
|
||||
continue
|
||||
}
|
||||
assert.NilError(t, json.Unmarshal(*jm.Aux, &br))
|
||||
assert.Assert(t, br.ID != "", "could not read image ID from build output")
|
||||
break
|
||||
|
||||
var br build.Result
|
||||
if err := json.Unmarshal(*jm.Aux, &br); err == nil {
|
||||
if br.ID == "" {
|
||||
continue
|
||||
}
|
||||
id = br.ID
|
||||
break
|
||||
}
|
||||
}
|
||||
io.Copy(io.Discard, body)
|
||||
return br.ID
|
||||
_, _ = io.Copy(io.Discard, body)
|
||||
|
||||
assert.Assert(t, id != "", "could not read image ID from build output")
|
||||
return id
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user