Improve error reporting when image loading fails

Closes gh-31243
This commit is contained in:
Andy Wilkinson
2024-11-07 20:07:22 +00:00
parent 03a3425767
commit 2fa28fb822
5 changed files with 86 additions and 12 deletions

View File

@@ -252,6 +252,16 @@ class DockerApiTests {
.withMessageContaining("Invalid response received");
}
@Test // gh-31243
void loadWithErrorResponseThrowsException() throws Exception {
Image image = Image.of(getClass().getResourceAsStream("type/image.json"));
ImageArchive archive = ImageArchive.from(image);
URI loadUri = new URI(IMAGES_URL + "/load");
given(http().post(eq(loadUri), eq("application/x-tar"), any())).willReturn(responseOf("load-error.json"));
assertThatIllegalStateException().isThrownBy(() -> this.api.load(archive, this.loadListener))
.withMessageContaining("Error response received");
}
@Test
void loadLoadsImage() throws Exception {
Image image = Image.of(getClass().getResourceAsStream("type/image.json"));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@ package org.springframework.boot.buildpack.platform.docker;
import org.junit.jupiter.api.Test;
import org.springframework.boot.buildpack.platform.docker.LoadImageUpdateEvent.ErrorDetail;
import org.springframework.boot.buildpack.platform.docker.ProgressUpdateEvent.ProgressDetail;
import static org.assertj.core.api.Assertions.assertThat;
@@ -36,9 +37,16 @@ class LoadImageUpdateEventTests extends ProgressUpdateEventTests<LoadImageUpdate
assertThat(event.getStream()).isEqualTo("stream");
}
@Test
void getErrorDetailReturnsErrorDetail() {
LoadImageUpdateEvent event = createEvent();
assertThat(event.getErrorDetail()).extracting(ErrorDetail::getMessage).isEqualTo("max depth exceeded");
}
@Override
protected LoadImageUpdateEvent createEvent(String status, ProgressDetail progressDetail, String progress) {
return new LoadImageUpdateEvent("stream", status, progressDetail, progress);
return new LoadImageUpdateEvent("stream", status, progressDetail, progress,
new ErrorDetail("max depth exceeded"));
}
}