Skip to content

Commit

Permalink
fix #57 map build section
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhoss committed Sep 11, 2020
1 parent 4359e0e commit 4eb0654
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,19 @@ final class DevcontainerOptionsMapper {

static ShellOptions shellOptions(final DevcontainerOptions options, final DevcontainerJson devcontainer) {
final var opts = new ShellOptions();
opts.image = devcontainer.image;
opts.debug = options.debug;
opts.pull = options.pull;
opts.removeImage = options.removeImage;
opts.runtime = options.shellRuntime;
opts.dockerfile = devcontainer.dockerFile;
opts.context = devcontainer.context;
opts.mountProjectDir = options.mountProjectDir;
opts.image = devcontainer.image;
if (null != devcontainer.build) {
opts.dockerfile = devcontainer.build.dockerFile;
opts.context = devcontainer.build.context;
} else {
opts.dockerfile = devcontainer.dockerFile;
opts.context = devcontainer.context;
}
return opts;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static wtf.metio.ilo.devcontainer.DevcontainerOptionsMapper.composeOptions;
import static wtf.metio.ilo.devcontainer.DevcontainerOptionsMapper.shellOptions;
Expand All @@ -23,17 +24,96 @@ class DevcontainerOptionsMapperTest {
class ShellOptionsMapper {

@Test
@DisplayName("returns non-null values")
void shouldReturnNonNullValues() {
assertNotNull(shellOptions(new DevcontainerOptions(), new DevcontainerJson()));
}

@Test
@DisplayName("maps the image field")
void shouldMapImage() {
// given
final var options = new DevcontainerOptions();
final var json = new DevcontainerJson();
json.image = "example:123";

// when
final var shellOptions = shellOptions(options, json);

// then
assertEquals(json.image, shellOptions.image);
}

@Test
@DisplayName("maps the dockerFile field")
void shouldMapDockerfile() {
// given
final var options = new DevcontainerOptions();
final var json = new DevcontainerJson();
json.dockerFile = "some.dockerfile";

// when
final var shellOptions = shellOptions(options, json);

// then
assertEquals(json.dockerFile, shellOptions.dockerfile);
}

@Test
@DisplayName("maps the context field")
void shouldMapContext() {
// given
final var options = new DevcontainerOptions();
final var json = new DevcontainerJson();
json.context = ".";

// when
final var shellOptions = shellOptions(options, json);

// then
assertEquals(json.context, shellOptions.context);
}

@Test
@DisplayName("maps the build.dockerFile field")
void shouldMapBuildDockerfile() {
// given
final var options = new DevcontainerOptions();
final var json = new DevcontainerJson();
json.build = new DevcontainerJson.Build();
json.build.dockerFile = "some.dockerfile";

// when
final var shellOptions = shellOptions(options, json);

// then
assertEquals(json.build.dockerFile, shellOptions.dockerfile);
}

@Test
@DisplayName("maps the build.context field")
void shouldMapBuildContext() {
// given
final var options = new DevcontainerOptions();
final var json = new DevcontainerJson();
json.build = new DevcontainerJson.Build();
json.build.context = ".";

// when
final var shellOptions = shellOptions(options, json);

// then
assertEquals(json.build.context, shellOptions.context);
}

}

@Nested
@DisplayName("compose options")
class ComposeOptionsMapper {

@Test
@DisplayName("returns non-null values")
void shouldReturnNonNullValues() {
assertNotNull(composeOptions(new DevcontainerOptions(), new DevcontainerJson()));
}
Expand Down

0 comments on commit 4eb0654

Please sign in to comment.