Search in sources :

Example 6 with TarArchive

use of org.springframework.boot.buildpack.platform.io.TarArchive in project spring-boot by spring-projects.

the class ImageBuildpackTests method withMockLayers.

private Object withMockLayers(InvocationOnMock invocation) {
    try {
        IOBiConsumer<String, TarArchive> consumer = invocation.getArgument(1);
        TarArchive archive = (out) -> {
            try (TarArchiveOutputStream tarOut = new TarArchiveOutputStream(out)) {
                tarOut.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
                writeTarEntry(tarOut, "/cnb/");
                writeTarEntry(tarOut, "/cnb/buildpacks/");
                writeTarEntry(tarOut, "/cnb/buildpacks/example_buildpack/");
                writeTarEntry(tarOut, "/cnb/buildpacks/example_buildpack/0.0.1/");
                writeTarEntry(tarOut, "/cnb/buildpacks/example_buildpack/0.0.1/buildpack.toml");
                writeTarEntry(tarOut, "/cnb/buildpacks/example_buildpack/0.0.1/" + this.longFilePath);
                tarOut.finish();
            }
        };
        consumer.accept("test", archive);
    } catch (IOException ex) {
        fail("Error writing mock layers", ex);
    }
    return null;
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ImageReference(org.springframework.boot.buildpack.platform.docker.type.ImageReference) Random(java.util.Random) ArrayList(java.util.ArrayList) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ByteArrayInputStream(java.io.ByteArrayInputStream) TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry) BDDMockito.given(org.mockito.BDDMockito.given) TarArchive(org.springframework.boot.buildpack.platform.io.TarArchive) Image(org.springframework.boot.buildpack.platform.docker.type.Image) Assertions.tuple(org.assertj.core.api.Assertions.tuple) IOException(java.io.IOException) IOBiConsumer(org.springframework.boot.buildpack.platform.io.IOBiConsumer) BDDMockito.willAnswer(org.mockito.BDDMockito.willAnswer) Test(org.junit.jupiter.api.Test) List(java.util.List) Assertions.fail(org.assertj.core.api.Assertions.fail) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) AbstractJsonTests(org.springframework.boot.buildpack.platform.json.AbstractJsonTests) Mockito.mock(org.mockito.Mockito.mock) TarArchive(org.springframework.boot.buildpack.platform.io.TarArchive) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) IOException(java.io.IOException)

Example 7 with TarArchive

use of org.springframework.boot.buildpack.platform.io.TarArchive in project spring-boot by spring-projects.

the class ContainerContentTests method ofCreatesContainerContent.

@Test
void ofCreatesContainerContent() {
    TarArchive archive = mock(TarArchive.class);
    ContainerContent content = ContainerContent.of(archive);
    assertThat(content.getArchive()).isSameAs(archive);
    assertThat(content.getDestinationPath()).isEqualTo("/");
}
Also used : TarArchive(org.springframework.boot.buildpack.platform.io.TarArchive) Test(org.junit.jupiter.api.Test)

Example 8 with TarArchive

use of org.springframework.boot.buildpack.platform.io.TarArchive in project spring-boot by spring-projects.

the class ContainerContentTests method ofWithDestinationPathCreatesContainerContent.

@Test
void ofWithDestinationPathCreatesContainerContent() {
    TarArchive archive = mock(TarArchive.class);
    ContainerContent content = ContainerContent.of(archive, "/test");
    assertThat(content.getArchive()).isSameAs(archive);
    assertThat(content.getDestinationPath()).isEqualTo("/test");
}
Also used : TarArchive(org.springframework.boot.buildpack.platform.io.TarArchive) Test(org.junit.jupiter.api.Test)

Aggregations

TarArchive (org.springframework.boot.buildpack.platform.io.TarArchive)8 Test (org.junit.jupiter.api.Test)6 IOException (java.io.IOException)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 TarArchiveEntry (org.apache.commons.compress.archivers.tar.TarArchiveEntry)2 TarArchiveOutputStream (org.apache.commons.compress.archivers.tar.TarArchiveOutputStream)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)2 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)2 BDDMockito.given (org.mockito.BDDMockito.given)2 ImageReference (org.springframework.boot.buildpack.platform.docker.type.ImageReference)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 OutputStream (java.io.OutputStream)1