From a0cb1714bf839d300e507ba3e70fe05f37895e2c Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Sat, 26 Apr 2025 15:25:03 +0900 Subject: [PATCH] Add more tests for Image.getOs() See gh-45152 Signed-off-by: Johnny Lim --- .../platform/docker/type/ImageTests.java | 12 ++++++++ .../platform/docker/type/image-empty-os.json | 30 +++++++++++++++++++ .../docker/type/image-non-default-os.json | 30 +++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/resources/org/springframework/boot/buildpack/platform/docker/type/image-empty-os.json create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/resources/org/springframework/boot/buildpack/platform/docker/type/image-non-default-os.json diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ImageTests.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ImageTests.java index 2bcea073ecda..150c024b7a1f 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ImageTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ImageTests.java @@ -67,6 +67,18 @@ void getOsReturnsOs() throws Exception { assertThat(image.getOs()).isEqualTo("linux"); } + @Test + void getOsWhenOsIsNotDefaultOsReturnsOs() throws Exception { + Image image = Image.of(getContent("image-non-default-os.json")); + assertThat(image.getOs()).isEqualTo("windows"); + } + + @Test + void getOsWhenOsIsEmptyReturnsDefaultOs() throws Exception { + Image image = Image.of(getContent("image-empty-os.json")); + assertThat(image.getOs()).isEqualTo("linux"); + } + @Test void getArchitectureReturnsArchitecture() throws Exception { Image image = getImage(); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/resources/org/springframework/boot/buildpack/platform/docker/type/image-empty-os.json b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/resources/org/springframework/boot/buildpack/platform/docker/type/image-empty-os.json new file mode 100644 index 000000000000..b2c1bea62ef2 --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/resources/org/springframework/boot/buildpack/platform/docker/type/image-empty-os.json @@ -0,0 +1,30 @@ +{ + "Id": "sha256:21635a6b4880772f3fabbf8b660907fa38636558cf787cc26f1779fc4b4e2cba", + "RepoTags": [ + "ghcr.io/spring-io/spring-boot-cnb-test-builder:0.0.1" + ], + "RepoDigests": [ + "ghcr.io/spring-io/spring-boot-cnb-test-builder@sha256:21635a6b4880772f3fabbf8b660907fa38636558cf787cc26f1779fc4b4e2cba" + ], + "Parent": "", + "Comment": "", + "DockerVersion": "", + "Author": "", + "Config": null, + "Architecture": "", + "Os": "", + "Size": 166797518, + "GraphDriver": { + "Data": null, + "Name": "overlayfs" + }, + "RootFS": {}, + "Metadata": { + "LastTagTime": "2025-04-10T22:41:27.520294922Z" + }, + "Descriptor": { + "mediaType": "application/vnd.oci.image.index.v1+json", + "digest": "sha256:21635a6b4880772f3fabbf8b660907fa38636558cf787cc26f1779fc4b4e2cba", + "size": 513 + } +} \ No newline at end of file diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/resources/org/springframework/boot/buildpack/platform/docker/type/image-non-default-os.json b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/resources/org/springframework/boot/buildpack/platform/docker/type/image-non-default-os.json new file mode 100644 index 000000000000..c418002e63e7 --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/resources/org/springframework/boot/buildpack/platform/docker/type/image-non-default-os.json @@ -0,0 +1,30 @@ +{ + "Id": "sha256:21635a6b4880772f3fabbf8b660907fa38636558cf787cc26f1779fc4b4e2cba", + "RepoTags": [ + "ghcr.io/spring-io/spring-boot-cnb-test-builder:0.0.1" + ], + "RepoDigests": [ + "ghcr.io/spring-io/spring-boot-cnb-test-builder@sha256:21635a6b4880772f3fabbf8b660907fa38636558cf787cc26f1779fc4b4e2cba" + ], + "Parent": "", + "Comment": "", + "DockerVersion": "", + "Author": "", + "Config": null, + "Architecture": "", + "Os": "windows", + "Size": 166797518, + "GraphDriver": { + "Data": null, + "Name": "overlayfs" + }, + "RootFS": {}, + "Metadata": { + "LastTagTime": "2025-04-10T22:41:27.520294922Z" + }, + "Descriptor": { + "mediaType": "application/vnd.oci.image.index.v1+json", + "digest": "sha256:21635a6b4880772f3fabbf8b660907fa38636558cf787cc26f1779fc4b4e2cba", + "size": 513 + } +} \ No newline at end of file