Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chanseokoh committed Sep 14, 2018
1 parent 6489596 commit 6b01f13
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public class JavaEntrypointConstructor {

public static List<String> makeDefaultEntrypoint(
String appRoot, List<String> jvmFlags, String mainClass) {
Preconditions.checkArgument(appRoot.startsWith("/"));
Preconditions.checkArgument(
appRoot.startsWith("/"), "appRoot should be an absolute path in Unix-style");
appRoot = appRoot.endsWith("/") ? appRoot : appRoot + '/';

return makeEntrypoint(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ private JavaLayerConfigurations(
}

/**
* Returns the Unix-style, absolute path for the application root in the container image. May or
* may not end with a trailing forward slash ('/').
* Returns the Unix-style, absolute path for the application root in the container image. The path
* may or may not end with a forward slash ('/').
*
* @return Unix-style, absolute path for the application root
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

package com.google.cloud.tools.jib.frontend;

import com.google.cloud.tools.jib.configuration.ContainerConfiguration;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
Expand Down Expand Up @@ -54,6 +56,63 @@ public void testMakeEntrypoint() {
entrypoint);
}

@Test
public void testMakeDefaultEntrypoint_classpathString() {
// Checks that this is also the default entrypoint.
List<String> entrypoint = JavaEntrypointConstructor.makeDefaultEntrypoint(
ContainerConfiguration.DEFAULT_APP_ROOT, Collections.emptyList(), "someMainClass");
Assert.assertEquals("/app/resources/:/app/classes/:/app/libs/*", entrypoint.get(2));
}

@Test
public void testMakeDefaultEntrypoint_classpathStringWithNonDefaultAppRoot() {
// Checks that this is also the default entrypoint.
List<String> entrypoint = JavaEntrypointConstructor.makeDefaultEntrypoint(
"/my/app", Collections.emptyList(), "someMainClass");
Assert.assertEquals("/my/app/resources/:/my/app/classes/:/my/app/libs/*", entrypoint.get(2));
}

@Test
public void testMakeDefaultEntrypoint_appRootWithTrailingSlash() {
// Checks that this is also the default entrypoint.
List<String> entrypoint = JavaEntrypointConstructor.makeDefaultEntrypoint(
"/my/root/", Collections.emptyList(), "SomeMainClass");
Assert.assertEquals("/my/root/resources/:/my/root/classes/:/my/root/libs/*", entrypoint.get(2));
}

@Test
public void testMakeDefaultEntrypoint_nonAbsoluteAppRoot() {
try {
JavaEntrypointConstructor.makeDefaultEntrypoint(
"relative/path", Collections.emptyList(), "MainClass");
Assert.fail();
} catch (IllegalArgumentException ex) {
Assert.assertEquals("appRoot should be an absolute path in Unix-style", ex.getMessage());
}
}

@Test
public void testMakeDefaultEntrypoint_windowsAppRootPath() {
try {
JavaEntrypointConstructor.makeDefaultEntrypoint(
"\\windows\\path", Collections.emptyList(), "MyMain");
Assert.fail();
} catch (IllegalArgumentException ex) {
Assert.assertEquals("appRoot should be an absolute path in Unix-style", ex.getMessage());
}
}

@Test
public void testMakeDefaultEntrypoint_windowsPathWithDriveLetter() {
try {
JavaEntrypointConstructor.makeDefaultEntrypoint(
"D:\\windows\\path", Collections.emptyList(), "MyMain");
Assert.fail();
} catch (IllegalArgumentException ex) {
Assert.assertEquals("appRoot should be an absolute path in Unix-style", ex.getMessage());
}
}

@Test
public void testMakeDistrolessJettyEntrypoint() {
List<String> expected = Arrays.asList("java", "-jar", "/jetty/start.jar");
Expand Down

0 comments on commit 6b01f13

Please sign in to comment.