-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attach build to docker daemon functionality to maven goal (#266)
- Loading branch information
Showing
2 changed files
with
182 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/BuildDockerMojoIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright 2018 Google LLC. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package com.google.cloud.tools.jib.maven; | ||
|
||
import com.google.cloud.tools.jib.Command; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import org.apache.maven.it.VerificationException; | ||
import org.apache.maven.it.Verifier; | ||
import org.junit.Assert; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
|
||
/** Integration tests for {@link BuildDockerMojo}. */ | ||
public class BuildDockerMojoIT { | ||
|
||
@ClassRule public static final TestPlugin testPlugin = new TestPlugin(); | ||
|
||
@ClassRule | ||
public static final TestProject simpleTestProject = new TestProject(testPlugin, "simple"); | ||
|
||
@ClassRule | ||
public static final TestProject emptyTestProject = new TestProject(testPlugin, "empty"); | ||
|
||
/** | ||
* Builds and runs jib:buildDocker on a project at {@code projectRoot} pushing to {@code | ||
* imageReference}. | ||
*/ | ||
private static String buildToDockerDaemonAndRun(Path projectRoot, String imageReference) | ||
throws VerificationException, IOException, InterruptedException { | ||
Verifier verifier = new Verifier(projectRoot.toString()); | ||
verifier.setAutoclean(false); | ||
verifier.executeGoal("package"); | ||
|
||
// Builds twice, and checks if the second build took less time. | ||
verifier.executeGoal("jib:buildDocker"); | ||
verifier.verifyErrorFreeLog(); | ||
|
||
return new Command("docker", "run", imageReference).run(); | ||
} | ||
|
||
@Test | ||
public void testExecute_simple() throws VerificationException, IOException, InterruptedException { | ||
Assert.assertEquals( | ||
"Hello, world\n", | ||
buildToDockerDaemonAndRun( | ||
simpleTestProject.getProjectRoot(), | ||
"gcr.io/jib-integration-testing/simpleimage:maven")); | ||
} | ||
|
||
@Test | ||
public void testExecute_empty() throws InterruptedException, IOException, VerificationException { | ||
Assert.assertEquals( | ||
"", | ||
buildToDockerDaemonAndRun( | ||
emptyTestProject.getProjectRoot(), "gcr.io/jib-integration-testing/emptyimage:maven")); | ||
} | ||
} |