Skip to content

Commit

Permalink
update tests and remove unintented files
Browse files Browse the repository at this point in the history
  • Loading branch information
willr3 committed Sep 13, 2024
1 parent 42e2d34 commit 2962558
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 7 deletions.
31 changes: 31 additions & 0 deletions src/test/java/io/hyperfoil/tools/qdup/RunTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1622,6 +1622,37 @@ public void regex_empty() {

}

//uses timeout because this test prevents an infite loop that previously prevented system exit
@Test(timeout = 60_000)
public void abort_in_timer() {
Parser parser = Parser.getInstance();
RunConfigBuilder builder = getBuilder();

builder.loadYaml(parser.loadFile("json", stream("" +
"scripts:",
" foo:",
" - sh: sleep 120s",
" timer:",
" 10s:",
" - abort: too long",
"hosts:",
" local: " + getHost(),
"roles:",
" doit:",
" hosts: [local]",
" run-scripts: [foo]"
)));
RunConfig config = builder.buildConfig(parser);
assertFalse("runConfig errors:\n" + config.getErrorStrings().stream().collect(Collectors.joining("\n")), config.hasErrors());

Dispatcher dispatcher = new Dispatcher();
Run doit = new Run(tmpDir.toString(), config, dispatcher);

doit.run();
dispatcher.shutdown();
}


@Test(timeout = 45_000)
public void abort_callsCleanup() {
StringBuilder setup = new StringBuilder();
Expand Down
48 changes: 48 additions & 0 deletions src/test/java/io/hyperfoil/tools/qdup/StateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ public void has_jsonpath_search_found(){
assertTrue(found);
}
@Test
public void has_jsonpath_search_contains_found(){
State s = new State("");
s.set("key",Json.fromString("[ {\"key\":\"uno-uno\",\"value\":\"one\"}, {\"key\":\"dos-dos\",\"value\":\"two\"}]"));
boolean found = s.has("key[?(@.key contains \"uno\")]");
assertTrue(found);
}
@Test
public void get_jsonpath_search_contains_found(){
State s = new State("");
s.set("key",Json.fromString("[ {\"key\":\"uno-uno\",\"value\":\"one\"}, {\"key\":\"dos-dos\",\"value\":\"two\"}]"));

String found = s.get("key[?(@.key contains \"uno\")].value").toString();
assertEquals("one",found);
}
@Test
public void has_jsonpath_search_missing(){
State s = new State("");
s.set("key",Json.fromString("[ {\"key\":\"uno-uno\",\"value\":\"one\"}, {\"key\":\"dos-dos\",\"value\":\"two\"}]"));
Expand All @@ -48,6 +63,39 @@ public void get_jsonpath_search_missing(){
Object found = s.get("key[?(@.key == \"uno-dos\")]");
}

@Test
public void set_state_contains(){
Parser parser = Parser.getInstance();
RunConfigBuilder builder = getBuilder();
builder.loadYaml(parser.loadFile("",stream(""+
"scripts:",
" buz:",
" - set-state: RUN.found ${{response.items[?(@.name contains \"uno\" && @.name contains \"o-u\")]}}",
"hosts:",
" local: " + getHost(),
"roles:",
" doit:",
" hosts: [local]",
" setup-scripts: [buz]",
"states:",
" response:",
" items:",
" - key: one",
" name: uno-uno",
" - key: two",
" name: dos-dos"
)));
RunConfig config = builder.buildConfig(parser);
Dispatcher dispatcher = new Dispatcher();
Run doit = new Run(tmpDir.toString(), config, dispatcher);
doit.run();
dispatcher.shutdown();
assertTrue("state should have found\n"+config.getState().toJson().toString(2),config.getState().has("found"));
Object found = config.getState().get("found");
assertTrue(found instanceof Json);
Json json = (Json)found;
}


@Test
public void run_read_in_cleanup_from_host_insetup(){
Expand Down
4 changes: 0 additions & 4 deletions src/test/java/io/hyperfoil/tools/qdup/TestPB.java

This file was deleted.

3 changes: 3 additions & 0 deletions src/test/java/io/hyperfoil/tools/qdup/cmd/CmdTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ public void populateStateVariable_jsonpath_not_found(){
State state = new State("");
state.set("FOO", Json.fromString("[{\"key\":\"foo-bar\",\"value\":\"one\"},{\"key\":\"foo-biz\",\"value\":\"one\"}]"));
String response = Cmd.populateStateVariables("${{FOO[?(@.key == \"foo-buz\")]}}",null,state,null,null);
//TODO do we want an empty array or to indicate the pattern failed to populate?
assertEquals("response should be an empty array","[]",response);

}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public void getShell_localShell(){
}

@Test
public void getShell_containerShell(){
Host host = new Host("","",null,22,null,true,"podman","quay.io/wreicher/omb");
public void getShell_podman_containerShell(){
Host host = new Host("","",null,22,null,true,"podman","quay.io/fedora/fedora");
AbstractShell shell = AbstractShell.getShell(host,new ScheduledThreadPoolExecutor(2),new SecretFilter(),false);
try{
assertNotNull("shell should not be null",shell);
Expand Down
21 changes: 20 additions & 1 deletion src/test/java/io/hyperfoil/tools/qdup/shell/LocalShellTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void sh_without_connect(){
}
}
@Test
public void sh_rsync(){
public void shSync_rsync(){
Host host = new Host();
AbstractShell shell = new LocalShell(
host,
Expand All @@ -49,6 +49,25 @@ public void sh_rsync(){
String exec = shell.shSync("rsync");
assertFalse("rsync should be found by the local shell",exec.contains("command not found"));
}
@Test
public void shSync_podman(){
Host host = new Host();
AbstractShell shell = new LocalShell(
host,
"",
new ScheduledThreadPoolExecutor(2),
new SecretFilter(),
false
);
boolean connected = shell.connect();
if(!connected){
fail("failed to connect shell");
}
assertTrue("shell should be open",shell.isOpen());
assertTrue("shell should be ready",shell.isReady());
String exec = shell.shSync("docker");
assertFalse("command should be found by the local shell: "+exec,exec.contains("command not found"));
}

@Test
public void sh_createFile(){
Expand Down

0 comments on commit 2962558

Please sign in to comment.