Skip to content

Commit

Permalink
map more devcontainer.json fields
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhoss committed Feb 18, 2023
1 parent 3e98f6c commit 491cb76
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import wtf.metio.devcontainer.Devcontainer;
import wtf.metio.ilo.compose.ComposeOptions;
import wtf.metio.ilo.shell.ShellOptions;
import wtf.metio.ilo.shell.ShellVolumeBehavior;

import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -22,6 +23,8 @@ final class DevcontainerOptionsMapper {

static ShellOptions shellOptions(final DevcontainerOptions options, final Devcontainer devcontainer) {
final var opts = new ShellOptions();
opts.interactive = true;
opts.missingVolumes = ShellVolumeBehavior.CREATE;
opts.debug = options.debug;
opts.pull = options.pull;
opts.removeImage = options.removeImage;
Expand All @@ -38,11 +41,13 @@ static ShellOptions shellOptions(final DevcontainerOptions options, final Devcon
.flatMap(Collection::stream)
.map(port -> port + ":" + port)
.toList();
opts.runtimeRunOptions = devcontainer.runArgs();
return opts;
}

static ComposeOptions composeOptions(final DevcontainerOptions options, final Devcontainer devcontainer, final Path devcontainerJson) {
final var opts = new ComposeOptions();
opts.interactive = true;
opts.file = Stream.ofNullable(devcontainer.dockerComposeFile())
.flatMap(Collection::stream)
.map(Paths::get)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.junit.jupiter.api.Test;
import wtf.metio.devcontainer.BuildBuilder;
import wtf.metio.devcontainer.DevcontainerBuilder;
import wtf.metio.ilo.shell.ShellVolumeBehavior;

import java.nio.file.Paths;
import java.util.List;
Expand Down Expand Up @@ -89,6 +90,48 @@ void shouldMapForwardPorts() {
assertIterableEquals(List.of("123:123", "456:456"), shellOptions.ports);
}

@Test
@DisplayName("maps the runArgs field")
void shouldMapRunArgs() {
// given
final var options = new DevcontainerOptions();
final var json = DevcontainerBuilder.builder().runArgs(List.of("--cap-add=SYS_PTRACE", "--security-opt")).create();

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

// then
assertIterableEquals(List.of("--cap-add=SYS_PTRACE", "--security-opt"), shellOptions.runtimeRunOptions);
}

@Test
@DisplayName("--interactive is set to true")
void shouldEnableInteractiveMode() {
// given
final var options = new DevcontainerOptions();
final var json = DevcontainerBuilder.builder().create();

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

// then
assertTrue(shellOptions.interactive);
}

@Test
@DisplayName("--missing-volumes is set to CREATE")
void shouldCreateMissingVolumes() {
// given
final var options = new DevcontainerOptions();
final var json = DevcontainerBuilder.builder().create();

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

// then
assertEquals(ShellVolumeBehavior.CREATE, shellOptions.missingVolumes);
}

@Test
@DisplayName("sets the default context in case none is specified")
void shouldUseDefaultForMissingContext() {
Expand Down Expand Up @@ -157,6 +200,20 @@ void shouldMapService() {
assertEquals(json.service(), composeOptions.service);
}

@Test
@DisplayName("--interactive is set to true")
void shouldEnableInteractiveMode() {
// given
final var options = new DevcontainerOptions();
final var json = DevcontainerBuilder.builder().create();

// when
final var composeOptions = composeOptions(options, json, Paths.get("."));

// then
assertTrue(composeOptions.interactive);
}

}

}

0 comments on commit 491cb76

Please sign in to comment.