mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2024-12-22 12:57:57 +01:00
Add test for unsupported subcommands
This commit is contained in:
parent
61c5eb2962
commit
ffc5b26c0d
2 changed files with 59 additions and 1 deletions
|
@ -141,7 +141,7 @@ public abstract class AbstractExternalSOPTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String readSopBackendFromProperties() {
|
static String readSopBackendFromProperties() {
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
try {
|
try {
|
||||||
InputStream resourceIn = AbstractExternalSOPTest.class.getResourceAsStream("backend.local.properties");
|
InputStream resourceIn = AbstractExternalSOPTest.class.getResourceAsStream("backend.local.properties");
|
||||||
|
|
58
external-sop/src/test/java/sop/external/UnsupportedSubcommandTest.java
vendored
Normal file
58
external-sop/src/test/java/sop/external/UnsupportedSubcommandTest.java
vendored
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package sop.external;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.condition.EnabledIf;
|
||||||
|
import sop.exception.SOPGPException;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||||
|
|
||||||
|
@EnabledIf("sop.external.AbstractExternalSOPTest#isExternalSopInstalled")
|
||||||
|
public class UnsupportedSubcommandTest extends AbstractExternalSOPTest {
|
||||||
|
|
||||||
|
private final UnsupportedSubcommandExternal unsupportedSubcommand;
|
||||||
|
|
||||||
|
public UnsupportedSubcommandTest() {
|
||||||
|
String backend = readSopBackendFromProperties();
|
||||||
|
assumeTrue(backend != null);
|
||||||
|
Properties environment = readBackendEnvironment();
|
||||||
|
unsupportedSubcommand = new UnsupportedSubcommandExternal(backend, environment);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUnsupportedSubcommand() {
|
||||||
|
// "sop unsupported" returns error code UNSUPPORTED_SUBCOMMAND
|
||||||
|
assertThrows(SOPGPException.UnsupportedSubcommand.class,
|
||||||
|
unsupportedSubcommand::executeUnsupportedSubcommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class UnsupportedSubcommandExternal {
|
||||||
|
|
||||||
|
private final Runtime runtime = Runtime.getRuntime();
|
||||||
|
private final String binary;
|
||||||
|
private final Properties environment;
|
||||||
|
|
||||||
|
public UnsupportedSubcommandExternal(String binaryName, Properties environment) {
|
||||||
|
this.binary = binaryName;
|
||||||
|
this.environment = environment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void executeUnsupportedSubcommand() {
|
||||||
|
String[] command = new String[] {binary, "unsupported"}; // ~$ sop unsupported
|
||||||
|
String[] env = ExternalSOP.propertiesToEnv(environment).toArray(new String[0]);
|
||||||
|
try {
|
||||||
|
Process process = runtime.exec(command, env);
|
||||||
|
ExternalSOP.finish(process);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue