Skip to content

Commit 5e4342e

Browse files
committed
Add ShellFactory get shell test
1 parent c368f7f commit 5e4342e

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ dependencies {
1919
provided "org.embulk:embulk-core:0.7.0"
2020
// compile "YOUR_JAR_DEPENDENCY_GROUP:YOUR_JAR_DEPENDENCY_MODULE:YOUR_JAR_DEPENDENCY_VERSION"
2121
testCompile "junit:junit:4.+"
22+
testCompile 'org.embulk:embulk-core:0.7.+:tests'
2223
}
2324

2425
task classpath(type: Copy, dependsOn: ["jar"]) {

src/main/java/org/embulk/output/CommandFileOutputPlugin.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import java.io.OutputStream;
66
import java.io.FilterOutputStream;
77
import java.io.IOException;
8+
9+
import com.google.common.annotations.VisibleForTesting;
810
import org.slf4j.Logger;
911
import com.google.common.base.Throwables;
1012
import com.google.common.collect.ImmutableList;
@@ -73,7 +75,8 @@ public TransactionalFileOutput open(TaskSource taskSource, final int taskIndex)
7375
return new PluginFileOutput(cmdline, taskIndex);
7476
}
7577

76-
private static class ShellFactory
78+
@VisibleForTesting
79+
static class ShellFactory
7780
{
7881
private List<String> shell;
7982

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,39 @@
11
package org.embulk.output;
22

3+
import com.google.common.collect.ImmutableList;
4+
import org.junit.Before;
5+
import org.junit.Rule;
6+
import org.junit.Test;
7+
import org.embulk.EmbulkTestRuntime;
8+
import org.embulk.output.CommandFileOutputPlugin.ShellFactory;
9+
10+
import java.util.List;
11+
12+
import static org.junit.Assert.assertEquals;
13+
314
public class TestCommandFileOutputPlugin
415
{
16+
@Rule
17+
public EmbulkTestRuntime runtime = new EmbulkTestRuntime();
18+
19+
private ShellFactory shellFactory;
20+
21+
@Before
22+
public void createResources()
23+
{
24+
shellFactory = new ShellFactory().build();
25+
}
26+
27+
@Test
28+
public void testShell() {
29+
List<String> shell = shellFactory.get();
30+
String osName = System.getProperty("os.name");
31+
List<String> actualShellCmd;
32+
if (osName.contains("Windows")) {
33+
actualShellCmd = ImmutableList.of("PowerShell.exe", "-Command");
34+
} else {
35+
actualShellCmd = ImmutableList.of("sh", "-c");
36+
}
37+
assertEquals(actualShellCmd, shell);
38+
}
539
}

0 commit comments

Comments
 (0)