Skip to content

Commit

Permalink
yegor256#633 added test for dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
krzyk authored and krzyk committed Nov 9, 2014
1 parent dd30453 commit 322f460
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/main/resources/com/rultor/agents/req/_head.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,13 @@ function docker_when_possible {
done
cd ..
if [ -n "${directory}" ]; then
# @todo #633 For some reason the pipes inside use_image are giving non-zero
# exit code although the result filename is correct. Find out why it is
# happening and remove unsetting of pipefail below
set +o pipefail
use_image="yegor256/rultor-$(cat /dev/urandom | tr -cd 'a-z0-9' | head -c 8)"
docker build "${directory}" -t ${use_image}
set -o pipefail
docker build "${directory}" -t "${use_image}"
else
use_image="${image}"
docker pull "${use_image}"
Expand Down
57 changes: 55 additions & 2 deletions src/test/java/com/rultor/agents/req/StartsRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.hamcrest.Matcher;
import org.hamcrest.MatcherAssert;
Expand All @@ -58,8 +59,6 @@
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
* @checkstyle MultipleStringLiteralsCheck (500 lines)
* @todo #565 Add a test for stop command.
* @todo #594 Add a test for case where dockerfile is specified instead of
* image in configuration (docker: directory some/directory).
*/
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public final class StartsRequestTest {
Expand Down Expand Up @@ -226,6 +225,60 @@ public void startsMergeRequest() throws Exception {
this.exec(talk);
}

/**
* StartsRequest can run release with dockerfile.
* @throws Exception In case of error.
*/
@Test
public void runsReleaseWithDockerfile() throws Exception {
final File repo = this.repo();
final File dir = this.temp.newFolder();
FileUtils.write(new File(dir, "Dockerfile"), "FROM yegor256/rultor");
final Agent agent = new StartsRequest(
new Profile.Fixed(
new XMLDocument(
StringUtils.join(
"<p><entry key='release'><entry key='script'>",
"echo HEY</entry></entry><entry key='docker'>",
String.format("<entry key='directory'>%s</entry>", dir),
"</entry></p>"
)
)
)
);
final Talk talk = new Talk.InFile();
talk.modify(
new Directives().xpath("/talk")
.add("request").attr("id", "a8b9c0")
.add("type").set("release").up()
.add("args")
.add("arg").attr("name", "head").set(repo.toString()).up()
.add("arg").attr("name", "head_branch").set("master").up()
.add("arg").attr("name", "tag").set("1.0-beta").up()
);
agent.execute(talk);
MatcherAssert.assertThat(
this.exec(talk),
Matchers.allOf(
new Array<Matcher<? super String>>()
.with(
Matchers.containsString(
String.format(
"docker build %s -t yegor256/rultor-", dir
)
)
)
.with(Matchers.containsString("docker run"))
.with(
Matchers.containsString(
"docker rmi yegor256/rultor-"
)
)
.with(Matchers.containsString("low enough to run a"))
)
);
}

/**
* StartsRequest can take decryption instructions into account.
* @throws Exception In case of error.
Expand Down

0 comments on commit 322f460

Please sign in to comment.