use of org.eclipse.jkube.kit.common.AssemblyConfiguration in project jkube by eclipse.
the class AssemblyFileUtilsTest method getAssemblyFileOutputDirectoryWithRelativeDirectoryShouldReturnComputedPath.
@Test
public void getAssemblyFileOutputDirectoryWithRelativeDirectoryShouldReturnComputedPath() throws IOException {
// Given
final AssemblyFile af = AssemblyFile.builder().outputDirectory(new File("target")).build();
final File outputDirectoryForRelativePaths = temporaryFolder.newFolder("output");
final Assembly layer = new Assembly();
final AssemblyConfiguration ac = AssemblyConfiguration.builder().targetDir("/project").build();
// When
final File result = getAssemblyFileOutputDirectory(af, outputDirectoryForRelativePaths, layer, ac);
// Then
final String expectedPath = outputDirectoryForRelativePaths.toPath().resolve("project").resolve("target").toAbsolutePath().toString();
assertEquals(expectedPath, result.getAbsolutePath());
}
use of org.eclipse.jkube.kit.common.AssemblyConfiguration in project jkube by eclipse.
the class AssemblyConfigurationUtilsTest method getAssemblyConfigurationOrCreateDefaultWithConfigurationShouldReturnConfiguration.
@Test
public void getAssemblyConfigurationOrCreateDefaultWithConfigurationShouldReturnConfiguration(@Injectable final BuildConfiguration buildConfiguration) {
// Given
final AssemblyConfiguration configuration = AssemblyConfiguration.builder().user("OtherUser").name("ImageName").build();
// @formatter:off
new Expectations() {
{
buildConfiguration.getAssembly();
result = configuration;
}
};
// @formatter:on
// When
final AssemblyConfiguration result = getAssemblyConfigurationOrCreateDefault(buildConfiguration);
// Then
assertThat(result).hasFieldOrPropertyWithValue("name", "ImageName").hasFieldOrPropertyWithValue("targetDir", "/ImageName").hasFieldOrPropertyWithValue("user", "OtherUser");
}
use of org.eclipse.jkube.kit.common.AssemblyConfiguration in project jkube by eclipse.
the class AssemblyConfigurationUtilsTest method createDockerFileBuilder_withAssemblyAndFilesInSingleLayer_shouldReturnTransformedContent.
@Test
public void createDockerFileBuilder_withAssemblyAndFilesInSingleLayer_shouldReturnTransformedContent() {
// Given
final BuildConfiguration buildConfig = BuildConfiguration.builder().user("1000").maintainer("Alex").build();
final AssemblyConfiguration assemblyConfiguration = AssemblyConfiguration.builder().targetDir("/deployments").layer(Assembly.builder().id("layer-with-id").build()).layer(new Assembly()).build();
final Map<Assembly, List<AssemblyFileEntry>> layers = assemblyConfiguration.getLayers().stream().collect(Collectors.toMap(Function.identity(), a -> Collections.singletonList(new AssemblyFileEntry(new File(""), new File(""), null))));
layers.put(new Assembly(), Collections.emptyList());
// When
final String result = createDockerFileBuilder(buildConfig, assemblyConfiguration, layers).content();
// Then
assertThat(result).isEqualTo("FROM busybox\n" + "MAINTAINER Alex\n" + "COPY /layer-with-id/deployments /deployments/\n" + "VOLUME [\"/deployments\"]\n" + "USER 1000\n");
}
use of org.eclipse.jkube.kit.common.AssemblyConfiguration in project jkube by eclipse.
the class AssemblyConfigurationUtilsTest method createDockerFileBuilder_withAssemblyAndFiles_shouldReturnTransformedContent.
@Test
public void createDockerFileBuilder_withAssemblyAndFiles_shouldReturnTransformedContent() {
// Given
final BuildConfiguration buildConfig = BuildConfiguration.builder().putEnv("ENV_VAR", "VALUE").label("LABEL", "LABEL_VALUE").port("8080").user("1000").volume("VOLUME").runCmd("chown -R 1000:1000 /opt").maintainer("Alex").cmd(Arguments.builder().execArgument("sh").execArgument("-c").execArgument("server").build()).build();
final AssemblyConfiguration assemblyConfiguration = AssemblyConfiguration.builder().targetDir("/deployments").layer(Assembly.builder().id("layer-with-id").build()).layer(Assembly.builder().build()).build();
final Map<Assembly, List<AssemblyFileEntry>> layers = assemblyConfiguration.getLayers().stream().collect(Collectors.toMap(Function.identity(), a -> Collections.singletonList(new AssemblyFileEntry(new File(""), new File(""), null))));
// When
final String result = createDockerFileBuilder(buildConfig, assemblyConfiguration, layers).content();
// Then
assertThat(result).isEqualTo("FROM busybox\n" + "MAINTAINER Alex\n" + "ENV ENV_VAR=VALUE\n" + "LABEL LABEL=LABEL_VALUE\n" + "EXPOSE 8080\n" + "COPY /layer-with-id/deployments /deployments/\n" + "COPY /deployments /deployments/\n" + "RUN chown -R 1000:1000 /opt\n" + "VOLUME [\"/deployments\"]\n" + "VOLUME [\"VOLUME\"]\n" + "CMD [\"sh\",\"-c\",\"server\"]\n" + "USER 1000\n");
}
use of org.eclipse.jkube.kit.common.AssemblyConfiguration in project jkube by eclipse.
the class AssemblyConfigurationUtilsTest method getAssemblyConfigurationOrCreateDefaultNoConfigurationShouldReturnDefault.
@Test
public void getAssemblyConfigurationOrCreateDefaultNoConfigurationShouldReturnDefault(@Injectable final BuildConfiguration buildConfiguration) {
// Given
// @formatter:off
new Expectations() {
{
buildConfiguration.getAssembly();
result = null;
}
};
// @formatter:on
// When
final AssemblyConfiguration result = getAssemblyConfigurationOrCreateDefault(buildConfiguration);
// Then
assertThat(result).hasFieldOrPropertyWithValue("name", "maven").hasFieldOrPropertyWithValue("targetDir", "/maven").hasFieldOrPropertyWithValue("user", null);
}
Aggregations