Home / Class/ DockerCliIntegrationTests Class — spring-boot Architecture

DockerCliIntegrationTests Class — spring-boot Architecture

Architecture documentation for the DockerCliIntegrationTests class in DockerCliIntegrationTests.java from the spring-boot codebase.

Entity Profile

Relationship Graph

Source Code

core/spring-boot-docker-compose/src/dockerTest/java/org/springframework/boot/docker/compose/core/DockerCliIntegrationTests.java lines 57–161

@DisabledIfDockerUnavailable
@DisabledIfProcessUnavailable({ "docker", "compose" })
class DockerCliIntegrationTests {

	@TempDir
	@SuppressWarnings("NullAway.Init")
	private static Path tempDir;

	@Test
	void runBasicCommand() {
		DockerCli cli = new DockerCli(null, null);
		List<DockerCliContextResponse> context = cli.run(new DockerCliCommand.Context());
		assertThat(context).isNotEmpty();
	}

	@Test
	void runLifecycle() throws IOException {
		File composeFile = createComposeFile("redis-compose.yaml");
		String projectName = UUID.randomUUID().toString();
		DockerCli cli = new DockerCli(null, new DockerComposeOptions(DockerComposeFile.of(composeFile),
				Collections.emptySet(), List.of("--project-name=" + projectName)));
		try {
			// Verify that no services are running (this is a fresh compose project)
			List<DockerCliComposePsResponse> ps = cli.run(new ComposePs());
			assertThat(ps).isEmpty();
			// List the config and verify that redis is there
			DockerCliComposeConfigResponse config = cli.run(new ComposeConfig());
			assertThat(config.services()).containsOnlyKeys("redis");
			assertThat(config.name()).isEqualTo(projectName);
			// Run up
			cli.run(new ComposeUp(LogLevel.INFO, Collections.emptyList()));
			// Run ps and use id to run inspect on the id
			ps = cli.run(new ComposePs());
			assertThat(ps).hasSize(1);
			String id = ps.get(0).id();
			List<DockerCliInspectResponse> inspect = cli.run(new Inspect(List.of(id)));
			assertThat(inspect).isNotEmpty();
			assertThat(inspect.get(0).id()).startsWith(id);
			// Run stop, then run ps and verify the services are stopped
			cli.run(new ComposeStop(Duration.ofSeconds(10), Collections.emptyList()));
			ps = cli.run(new ComposePs());
			assertThat(ps).isEmpty();
			// Run start, verify service is there, then run down and verify they are gone
			cli.run(new ComposeStart(LogLevel.INFO, Collections.emptyList()));
			ps = cli.run(new ComposePs());
			assertThat(ps).hasSize(1);
			cli.run(new ComposeDown(Duration.ofSeconds(10), Collections.emptyList()));
			ps = cli.run(new ComposePs());
			assertThat(ps).isEmpty();
		}
		finally {
			// Clean up in any case
			quietComposeDown(cli);
		}
	}

	@Test
	void shouldWorkWithMultipleComposeFiles() throws IOException {
		List<File> composeFiles = createComposeFiles();
		DockerCli cli = new DockerCli(null,
				new DockerComposeOptions(DockerComposeFile.of(composeFiles), Set.of("dev"), Collections.emptyList()));
		try {
			// List the config and verify that both redis are there
			DockerCliComposeConfigResponse config = cli.run(new ComposeConfig());
			assertThat(config.services()).containsOnlyKeys("redis1", "redis2");
			// Run up
			cli.run(new ComposeUp(LogLevel.INFO, Collections.emptyList()));
			// Run ps and use id to run inspect on the id
			List<DockerCliComposePsResponse> ps = cli.run(new ComposePs());
			assertThat(ps).hasSize(2);
		}
		finally {
			// Clean up in any case
			quietComposeDown(cli);
		}
	}

	private static void quietComposeDown(DockerCli cli) {
		try {
			cli.run(new ComposeDown(Duration.ZERO, Collections.emptyList()));
		}
		catch (RuntimeException ex) {
			// Ignore
		}
	}

	private static File createComposeFile(String resource) throws IOException {
		File source = new ClassPathResource(resource, DockerCliIntegrationTests.class).getFile();
		File target = Path.of(tempDir.toString(), source.getName()).toFile();
		String content = FileCopyUtils.copyToString(new FileReader(source));
		content = content.replace("{imageName}", TestImage.REDIS.toString());
		try (FileWriter writer = new FileWriter(target)) {
			FileCopyUtils.copy(content, writer);
		}
		return target;
	}

	private static List<File> createComposeFiles() throws IOException {
		File file1 = createComposeFile("1.yaml");
		File file2 = createComposeFile("2.yaml");
		File file3 = createComposeFile("3.yaml");
		return List.of(file1, file2, file3);
	}

}

Domain

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free