Functional test for Docker commit image when container is invalid
@@ -2,6 +2,7 @@ package com.bmuschko.gradle.docker.tasks.image
import com.bmuschko.gradle.docker.AbstractGroovyDslFunctionalTest
import org.gradle.testkit.runner.BuildResult
+import org.gradle.testkit.runner.UnexpectedBuildFailure
class DockerCommitImageFunctionalTest extends AbstractGroovyDslFunctionalTest {
@@ -11,6 +12,8 @@ class DockerCommitImageFunctionalTest extends AbstractGroovyDslFunctionalTest {
task commitImage(type: DockerCommitImage) {
dependsOn startContainer
targetContainerId createContainer.getContainerId()
+ author = "john doe"
+ message = "My image created"
tag = "myimage:latest"
}
"""
@@ -24,6 +27,46 @@ class DockerCommitImageFunctionalTest extends AbstractGroovyDslFunctionalTest {
result.output.contains("Commiting image for container")
}
+ def "cannot commit image without container"() {
+ given:
+ String commitImage = """
+ task commitImage(type: DockerCommitImage) {
+ dependsOn startContainer
+ finalizedBy removeContainer
+ }
+ """
+
+ buildFile << containerStart(commitImage)
+
+ when:
+ BuildResult result = build('commitImage')
+
+ then:
+ def e = thrown(UnexpectedBuildFailure)
+ e.message.contains('No value has been specified for property \'containerId\'.')
+ }
+
+ def "cannot commit image with invalid container"() {
+ given:
+ String commitImage = """
+ task commitImage(type: DockerCommitImage) {
+ dependsOn startContainer
+ finalizedBy removeContainer
+ targetContainerId "idonotexist"
+ }
+ """
+
+ buildFile << containerStart(commitImage)
+
+ when:
+ BuildResult result = build('commitImage')
+
+ then:
+ def e = thrown(UnexpectedBuildFailure)
+ e.message.contains('{"message":"No such container: idonotexist"}')
+ }
+
+
static String containerStart(containerCommitImageExecutionTask) {
"""
import com.bmuschko.gradle.docker.tasks.container.DockerCreateContainer
