|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2023 the original author or authors. |
| 2 | + * Copyright 2012-2024 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
39 | 39 | import org.springframework.boot.docker.compose.core.DockerComposeFile;
|
40 | 40 | import org.springframework.boot.docker.compose.core.RunningService;
|
41 | 41 | import org.springframework.boot.docker.compose.lifecycle.DockerComposeProperties.Readiness.Wait;
|
| 42 | +import org.springframework.boot.docker.compose.lifecycle.DockerComposeProperties.Start.Skip; |
42 | 43 | import org.springframework.boot.test.system.CapturedOutput;
|
43 | 44 | import org.springframework.boot.test.system.OutputCaptureExtension;
|
44 | 45 | import org.springframework.context.ApplicationContext;
|
@@ -384,6 +385,38 @@ void shouldNotLogIfThereAreNoServicesRunning(CapturedOutput output) {
|
384 | 385 | assertThat(output).doesNotContain("There are already Docker Compose services running, skipping startup");
|
385 | 386 | }
|
386 | 387 |
|
| 388 | + @Test |
| 389 | + void shouldStartIfSkipModeIsIfRunningAndNoServicesAreRunning() { |
| 390 | + given(this.dockerCompose.hasDefinedServices()).willReturn(true); |
| 391 | + this.properties.getStart().setSkip(Skip.IF_RUNNING); |
| 392 | + this.lifecycleManager.start(); |
| 393 | + then(this.dockerCompose).should().up(any()); |
| 394 | + } |
| 395 | + |
| 396 | + @Test |
| 397 | + void shouldNotStartIfSkipModeIsIfRunningAndServicesAreAlreadyRunning() { |
| 398 | + setUpRunningServices(); |
| 399 | + this.properties.getStart().setSkip(Skip.IF_RUNNING); |
| 400 | + this.lifecycleManager.start(); |
| 401 | + then(this.dockerCompose).should(never()).up(any()); |
| 402 | + } |
| 403 | + |
| 404 | + @Test |
| 405 | + void shouldStartIfSkipModeIsNeverAndNoServicesAreRunning() { |
| 406 | + given(this.dockerCompose.hasDefinedServices()).willReturn(true); |
| 407 | + this.properties.getStart().setSkip(Skip.NEVER); |
| 408 | + this.lifecycleManager.start(); |
| 409 | + then(this.dockerCompose).should().up(any()); |
| 410 | + } |
| 411 | + |
| 412 | + @Test |
| 413 | + void shouldStartIfSkipModeIsNeverAndServicesAreAlreadyRunning() { |
| 414 | + setUpRunningServices(); |
| 415 | + this.properties.getStart().setSkip(Skip.NEVER); |
| 416 | + this.lifecycleManager.start(); |
| 417 | + then(this.dockerCompose).should().up(any()); |
| 418 | + } |
| 419 | + |
387 | 420 | private void setUpRunningServices() {
|
388 | 421 | setUpRunningServices(true);
|
389 | 422 | }
|
|
0 commit comments