Skip to content

Feature/windows smoke tests #180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
195d9af
Locate docker and docker-compose using the path variable.
Mar 1, 2017
ab078a6
Merge branch 'feature/use-path-to-find-executables' of https://github…
hpryce Mar 7, 2017
a12076d
Reintroduce support for explicitly setting docker-compose location.
hpryce Mar 7, 2017
35ab870
Docker for Mac is not in the path when tests run from IDE.
hpryce Mar 7, 2017
252a88e
Split out finding possible command locations from testing those locat…
hpryce Mar 7, 2017
0a61921
Add jsr dep
hpryce Mar 7, 2017
d39fb31
Refactor to simply logic and improve test coverage by using Environme…
hpryce Mar 8, 2017
19791dd
Add case for Windows path variable "Path"
hpryce Mar 8, 2017
a734f16
Process builder will look for command on the path
hpryce Mar 8, 2017
215f427
Move integ tests into separate source set.
hpryce Mar 8, 2017
a8ce98b
Add very simple windows smoke test.
hpryce Mar 8, 2017
cc06e21
Wire up smoke test for Windows to appveyor.
hpryce Mar 9, 2017
186aba0
Thread.sleep isn't accurate on Windows
hpryce Mar 9, 2017
ed0d9cf
Simply don't run the tes that relies upon Thread.sleep on Windows
hpryce Mar 9, 2017
17a0b3b
Merge branch 'feature/look_in_path' into feature/windows_smoke_tests
hpryce Mar 9, 2017
bc6bdd9
Do we have the latest image?
hpryce Mar 10, 2017
1df8a38
Use Windows Server 2016 image
hpryce Mar 10, 2017
e903dac
Install docker-compose before running tests that need it
hpryce Mar 10, 2017
8c41711
Use image with more up to date docker
hpryce Mar 10, 2017
479efca
Correct appveyor.yml syntax
hpryce Mar 10, 2017
9492fb4
Try cinst
hpryce Mar 10, 2017
eafa3b0
Try installing both docker and docker-compose on old image
hpryce Mar 10, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build_script:
- gradlew.bat compileJava compileTestJava --info --no-daemon

test_script:
- gradlew.bat dependencies --info --no-daemon
- gradlew.bat test windowsSmokeTest --info --no-daemon

branches:
only:
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ subprojects {
apply plugin: 'com.palantir.baseline-eclipse'
apply plugin: 'com.palantir.baseline-findbugs'
apply plugin: 'com.palantir.baseline-idea'
apply from: "${rootDir}/gradle/integTest.gradle"
apply from: "${rootDir}/gradle/publish.gradle"

apply plugin: 'org.inferred.processors'
Expand Down
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test:
override:
- ? >
case $CIRCLE_NODE_INDEX in
0) ./gradlew test --info ;;
0) ./gradlew test integTest --info ;;
1) ./gradlew findbugsMain findbugsTest checkstyleMain checkstyleTest javadoc --info ;;
esac
:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ContainerIntegrationTests {
@Test
public void testStateChanges_withoutHealthCheck() throws IOException, InterruptedException {
DockerCompose dockerCompose = new DefaultDockerCompose(
DockerComposeFiles.from("src/test/resources/no-healthcheck.yaml"),
DockerComposeFiles.from("src/integTest/resources/no-healthcheck.yaml"),
dockerMachine,
ProjectName.random());

Expand All @@ -60,7 +60,7 @@ public void testStateChanges_withHealthCheck() throws IOException, InterruptedEx
assumeThat("docker-compose version", DockerCompose.version(), new GreaterOrEqual<>(Version.forIntegers(1, 10, 0)));

DockerCompose dockerCompose = new DefaultDockerCompose(
DockerComposeFiles.from("src/test/resources/native-healthcheck.yaml"),
DockerComposeFiles.from("src/integTest/resources/native-healthcheck.yaml"),
dockerMachine,
ProjectName.random());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.Collection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.SystemUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -35,7 +34,7 @@ public class Docker {
private static final Logger log = LoggerFactory.getLogger(Docker.class);

// Without java escape characters: ^(\d+)\.(\d+)\.(\d+)(?:-.*)?$
private static final Pattern VERSION_PATTERN = Pattern.compile("^Docker version (\\d+)\\.(\\d+)\\.(\\d+)(?:-.*)?$");
private static final Pattern VERSION_PATTERN = Pattern.compile("^Docker version (\\d+)\\.(\\d+)\\.(\\d+)(?:(-|,).*)?$");
private static final String HEALTH_STATUS_FORMAT =
"--format="
+ "{{if not .State.Running}}DOWN"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void call_docker_network_ls() throws IOException, InterruptedException {

@Test
public void understand_old_version_format() throws IOException, InterruptedException {
when(executedProcess.getInputStream()).thenReturn(toInputStream("Docker version 1.7.2"));
when(executedProcess.getInputStream()).thenReturn(toInputStream("Docker version 1.7.2, build abcdef"));

Version version = docker.configuredVersion();
assertThat(version, is(Version.valueOf("1.7.2")));
Expand Down
12 changes: 12 additions & 0 deletions docker-compose-rule-junit4/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,15 @@ dependencies {
if (System.env.CIRCLE_TEST_REPORTS) {
test.reports.junitXml.destination = file(System.env.CIRCLE_TEST_REPORTS)
}

task windowsSmokeTest(type: Test) {
testClassesDir = sourceSets.integTest.output.classesDir
classpath = sourceSets.integTest.runtimeClasspath

reports.html.destination = "${project.buildDir}/reports/integTest"
reports.junitXml.destination = "${project.buildDir}/integTest-results"
binResultsDir = file("${project.buildDir}/integTest-results/binary/integTest")

include '**/windows/**'
}

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class AggressiveShutdownStrategyIntegrationTest {
@Test
public void shut_down_multiple_containers_immediately() throws Exception {
DockerComposeRule rule = DockerComposeRule.builder()
.file("src/test/resources/shutdown-strategy.yaml")
.file("src/integTest/resources/shutdown-strategy.yaml")
.logCollector(new DoNothingLogCollector())
.retryAttempts(0)
.shutdownStrategy(ShutdownStrategy.AGGRESSIVE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
public class AggressiveShutdownWithNetworkCleanupStrategyIntegrationTest {

private final DockerComposeRule rule = DockerComposeRule.builder()
.file("src/test/resources/shutdown-strategy-with-network.yaml")
.file("src/integTest/resources/shutdown-strategy-with-network.yaml")
.logCollector(new DoNothingLogCollector())
.retryAttempts(0)
.shutdownStrategy(ShutdownStrategy.AGGRESSIVE_WITH_NETWORK_CLEANUP)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class DockerComposeRuleIntegrationTest {

@Rule
public final DockerComposeRule docker = DockerComposeRule.builder()
.files(DockerComposeFiles.from("src/test/resources/docker-compose.yaml"))
.files(DockerComposeFiles.from("src/integTest/resources/docker-compose.yaml"))
.waitingForService("db", toHaveAllPortsOpen())
.waitingForService("db2", toHaveAllPortsOpen())
.waitingForServices(ImmutableList.of("db3", "db4"), toAllHaveAllPortsOpen())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void dockerComposeRuleWaitsUntilHealthcheckPasses()
assumeThat("docker-compose version", DockerCompose.version(), new GreaterOrEqual<>(Version.forIntegers(1, 10, 0)));

rule = DockerComposeRule.builder()
.file("src/test/resources/native-healthcheck.yaml")
.file("src/integTest/resources/native-healthcheck.yaml")
.build();
Future<?> beforeFuture = pool.submit(() -> {
rule.before();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class DockerComposeRuleUpContainerIntegrationTest {
public final DockerComposeRule dockerComposeRule = DockerComposeRule
.builder()
.shutdownStrategy(AGGRESSIVE)
.file("src/test/resources/up-integration-test.yaml")
.file("src/integTest/resources/up-integration-test.yaml")
.build();

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.palantir.docker.compose.connection.DockerPort;
import com.palantir.docker.compose.connection.waiting.HealthCheck;
import com.palantir.docker.compose.connection.waiting.SuccessOrFailure;

import org.apache.commons.lang3.SystemUtils;
import org.junit.Test;

Expand All @@ -40,7 +39,7 @@ private static HealthCheck<DockerPort> toBeOpen() {
assumeTrue("Host ports are only accessible on linux", SystemUtils.IS_OS_LINUX);

DockerComposeRule docker = DockerComposeRule.builder()
.file("src/test/resources/host-networked-docker-compose.yaml")
.file("src/integTest/resources/host-networked-docker-compose.yaml")
.waitingForHostNetworkedPort(5432, toBeOpen())
.build();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

public class RemoveConflictingContainersIntegrationTest {

private static final String DOCKER_COMPOSE_YAML_PATH = "src/test/resources/named-containers-docker-compose.yaml";
private static final String DOCKER_COMPOSE_YAML_PATH = "src/integTest/resources/named-containers-docker-compose.yaml";

@Rule
public ExpectedException exception = ExpectedException.none();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void docker_compose_gets_environment_variables_from_docker_machine_and_pa
.build();

DockerComposeRule dockerComposition = DockerComposeRule.builder()
.file("src/test/resources/environment/docker-compose.yaml")
.file("src/integTest/resources/environment/docker-compose.yaml")
.machine(dockerMachine)
.waitingForService("env-test", toHaveAllPortsOpen())
.saveLogsTo(temporaryFolder.getRoot().getAbsolutePath())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class LoggingIntegrationTest {
@Before
public void setUp() {
dockerComposeRule = DockerComposeRule.builder()
.file("src/test/resources/docker-compose.yaml")
.file("src/integTest/resources/docker-compose.yaml")
.waitingForService("db", toHaveAllPortsOpen())
.waitingForService("db2", toHaveAllPortsOpen())
.saveLogsTo(logFolder.getRoot().getAbsolutePath())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2016 Palantir Technologies, Inc. All rights reserved.
*/

package com.palantir.docker.compose.windows;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.junit.Assume.assumeTrue;

import com.palantir.docker.compose.DockerComposeRule;
import com.palantir.docker.compose.configuration.DockerComposeFiles;
import com.palantir.docker.compose.connection.State;
import java.io.IOException;
import org.apache.commons.lang3.SystemUtils;
import org.junit.Test;

public class WindowsIntegrationTest {

@Test
public void can_execute_docker_commands() throws IOException, InterruptedException {
assumeTrue("Running on Windows", SystemUtils.IS_OS_WINDOWS);

DockerComposeRule docker = DockerComposeRule.builder()
.files(DockerComposeFiles.from("src/integTest/resources/windows-docker-compose.yaml"))
.build();
docker.before();

try {
assertThat(docker.containers().container("hello-world").state(), is(State.DOWN));
} finally {
docker.after();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
hello-world:
image: microsoft/windowsservercore
command: echo "Server started"

67 changes: 67 additions & 0 deletions gradle/integTest.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// From https://raw.githubusercontent.com/spring-io/sagan/master/gradle/integTest.gradle
Copy link
Contributor

@iamdanfox iamdanfox Mar 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hpryce Please use https://github.com/unbroken-dome/gradle-testsets-plugin instead of copying and pasting gradle!!

You shouldn't have to do any custom reports.html.destination = stuff

import org.gradle.api.tasks.testing.Test

/**
* This script adds a dedicated integration testing source set (src/integTest) and task
* (integTest) when applied to any Java project.
*
* Configuration:
* apply from: path/to/integTest.gradle
*
* Usage:
* gradle integTest
* - or -
* gradle check
*/

sourceSets {
integTest {
java.srcDir 'src/integTest/java'
resources.srcDir 'src/integTest/resources'
}
}

task integTest(type: Test) {
description = "Runs integration tests."

testClassesDir = sourceSets.integTest.output.classesDir
classpath = sourceSets.integTest.runtimeClasspath

maxHeapSize = '1024m'

// ensure we don't overwrite default report directories used by 'test' task
reports.html.destination = "${project.buildDir}/reports/integTest"
reports.junitXml.destination = "${project.buildDir}/integTest-results"
binResultsDir = file("${project.buildDir}/integTest-results/binary/integTest")

// always run integration tests after unit tests in order to fail fast
mustRunAfter test
}

dependencies {
integTestCompile sourceSets.main.output
integTestCompile sourceSets.test.output
integTestCompile configurations.compile
integTestCompile configurations.testCompile
integTestRuntime configurations.runtime
integTestRuntime configurations.testRuntime
}

// Ensure unit test tasks (named 'test') always run before integration tests in
// order to fail as fast as possible
gradle.projectsEvaluated {
def unitTestTasks = []
gradle.rootProject.allprojects { project ->
unitTestTasks.addAll(project.tasks.findAll { it.name == 'test' })
}
unitTestTasks.each { unitTestTask ->
project.integTest.mustRunAfter unitTestTask
}
}

// Add integration test source directories to IDEA .iml files
if (project.plugins.hasPlugin('idea')) {
idea.module {
testSourceDirs += (sourceSets.integTest.java.srcDirs + sourceSets.integTest.resources.srcDirs)
}
}