Skip to content

Commit

Permalink
Added testing the container name to the integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinAhrer committed Apr 5, 2015
1 parent 231030b commit f22a2f2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ task inspectImage(type: DockerInspectImage) {
File imageDir = createDir(new File(projectDir, 'images/minimal'))
createDockerfile(imageDir)

def uniqueContainerName = createUniqueContainerName()

buildFile << """
import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
import com.bmuschko.gradle.docker.tasks.container.DockerCreateContainer
Expand All @@ -109,16 +111,23 @@ task buildImage(type: DockerBuildImage) {
task createContainer(type: DockerCreateContainer) {
dependsOn buildImage
targetImageId { buildImage.getImageId() }
containerName = "$uniqueContainerName}"
}
task startContainer(type: DockerStartContainer) {
dependsOn createContainer
targetContainerId { createContainer.getContainerId() }
portBindings = ['8080:8080']
}
task inspectImage(type: DockerInspectImage) {
dependsOn buildImage
targetImageId { buildImage.getImageId() }
}
"""
expect:
runTasks('startContainer')
GradleInvocationResult result = runTasks('startContainer', 'inspectImage')
result.output.contains("""Name": "/$uniqueContainerName""")
}

@Requires({ TestPrecondition.DOCKERHUB_CREDENTIALS_AVAILABLE })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,8 @@ repositories {
protected String createUniqueImageId() {
"gradle/${UUID.randomUUID().toString().replaceAll('-', '')}"
}

protected String createUniqueContainerName() {
"gradle/${UUID.randomUUID().toString().replaceAll('-', '')}"
}
}

0 comments on commit f22a2f2

Please sign in to comment.