-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
additional testing to preserve behavior
- Loading branch information
Showing
3 changed files
with
194 additions
and
2 deletions.
There are no files selected for viewing
122 changes: 121 additions & 1 deletion
122
src/test/java/io/hyperfoil/tools/qdup/cmd/impl/JsCmdIT.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 |
---|---|---|
@@ -1,4 +1,124 @@ | ||
package io.hyperfoil.tools.qdup.cmd.impl; | ||
|
||
public class JsCmdIT { | ||
import io.hyperfoil.tools.qdup.Run; | ||
import io.hyperfoil.tools.qdup.SshTestBase; | ||
import io.hyperfoil.tools.qdup.State; | ||
import io.hyperfoil.tools.qdup.cmd.Dispatcher; | ||
import io.hyperfoil.tools.qdup.config.RunConfig; | ||
import io.hyperfoil.tools.qdup.config.RunConfigBuilder; | ||
import io.hyperfoil.tools.qdup.config.yaml.Parser; | ||
import org.junit.Test; | ||
|
||
import java.util.stream.Collectors; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class JsCmdIT extends SshTestBase { | ||
|
||
@Test() | ||
public void run_repl_boolean_javascript_prefix(){ | ||
Parser parser = Parser.getInstance(); | ||
RunConfigBuilder builder = getBuilder(); | ||
builder.loadYaml(parser.loadFile("signal", | ||
""" | ||
scripts: | ||
sig: | ||
- js: ${{=VARIABLE}} | ||
then: | ||
- set-state: RUN.FOUND true | ||
else: | ||
- set-state: RUN.FOUND false | ||
hosts: | ||
test: TEST_HOST | ||
roles: | ||
role: | ||
hosts: [test] | ||
run-scripts: | ||
- sig | ||
""".replaceAll("TEST_HOST",getHost().toString()) | ||
)); | ||
builder.getState().set("VARIABLE",true); | ||
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(); | ||
|
||
State state = config.getState(); | ||
assertTrue(state.has("FOUND")); | ||
assertEquals("true",state.get("FOUND")); | ||
} | ||
|
||
@Test() | ||
public void run_repl_boolean(){ | ||
Parser parser = Parser.getInstance(); | ||
RunConfigBuilder builder = getBuilder(); | ||
builder.loadYaml(parser.loadFile("signal", | ||
""" | ||
scripts: | ||
sig: | ||
- js: ${{VARIABLE}} | ||
then: | ||
- set-state: RUN.FOUND true | ||
else: | ||
- set-state: RUN.FOUND false | ||
hosts: | ||
test: TEST_HOST | ||
roles: | ||
role: | ||
hosts: [test] | ||
run-scripts: | ||
- sig | ||
""".replaceAll("TEST_HOST",getHost().toString()) | ||
)); | ||
builder.getState().set("VARIABLE",true); | ||
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(); | ||
|
||
State state = config.getState(); | ||
assertTrue(state.has("FOUND")); | ||
assertEquals("true",state.get("FOUND")); | ||
} | ||
@Test() | ||
public void run_function_return_boolean(){ | ||
Parser parser = Parser.getInstance(); | ||
RunConfigBuilder builder = getBuilder(); | ||
builder.loadYaml(parser.loadFile("signal", | ||
""" | ||
scripts: | ||
sig: | ||
- js: (input)=>{ return ${{VARIABLE}} } | ||
then: | ||
- set-state: RUN.FOUND true | ||
else: | ||
- set-state: RUN.FOUND false | ||
hosts: | ||
test: TEST_HOST | ||
roles: | ||
role: | ||
hosts: [test] | ||
run-scripts: | ||
- sig | ||
""".replaceAll("TEST_HOST",getHost().toString()) | ||
)); | ||
builder.getState().set("VARIABLE",true); | ||
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(); | ||
|
||
State state = config.getState(); | ||
assertTrue(state.has("FOUND")); | ||
assertEquals("true",state.get("FOUND")); | ||
} | ||
} |
19 changes: 18 additions & 1 deletion
19
src/test/java/io/hyperfoil/tools/qdup/cmd/impl/ParseTest.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 |
---|---|---|
@@ -1,12 +1,29 @@ | ||
package io.hyperfoil.tools.qdup.cmd.impl; | ||
|
||
import io.hyperfoil.tools.qdup.SshTestBase; | ||
import io.hyperfoil.tools.qdup.cmd.SpyContext; | ||
import io.hyperfoil.tools.yaup.json.Json; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class ParseTest extends SshTestBase { | ||
|
||
@Test | ||
public void fromYaml(){ | ||
public void match_decimal(){ | ||
Json cfg = Json.fromString("[{\"pattern\": \"(?<decimal>\\\\d+\\\\.\\\\d+{0,3})\" }]"); | ||
ParseCmd cmd = new ParseCmd(cfg.toString(0)); | ||
SpyContext spyContext = new SpyContext(); | ||
|
||
cmd.run("6.001",spyContext); | ||
assertTrue("context should call next",spyContext.hasNext()); | ||
String next = spyContext.getNext(); | ||
assertTrue("next should be json",Json.isJsonLike(next)); | ||
Json js = Json.fromString(next); | ||
assertNotNull("next should convert to json",js); | ||
assertTrue("response should have matched pattern",js.has("decimal")); | ||
//have to convert with parseDouble because it apparently uses BigDecimal? | ||
assertEquals(6.001,Double.parseDouble(js.get("decimal").toString()),0.0001); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/test/java/io/hyperfoil/tools/qdup/cmd/impl/ReadStateIT.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,55 @@ | ||
package io.hyperfoil.tools.qdup.cmd.impl; | ||
|
||
import io.hyperfoil.tools.qdup.Run; | ||
import io.hyperfoil.tools.qdup.SshTestBase; | ||
import io.hyperfoil.tools.qdup.State; | ||
import io.hyperfoil.tools.qdup.cmd.Dispatcher; | ||
import io.hyperfoil.tools.qdup.config.RunConfig; | ||
import io.hyperfoil.tools.qdup.config.RunConfigBuilder; | ||
import io.hyperfoil.tools.qdup.config.yaml.Parser; | ||
import org.junit.Test; | ||
|
||
import java.util.stream.Collectors; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class ReadStateIT extends SshTestBase { | ||
|
||
@Test() | ||
public void run_read_boolean_for_regex(){ | ||
Parser parser = Parser.getInstance(); | ||
RunConfigBuilder builder = getBuilder(); | ||
builder.loadYaml(parser.loadFile("signal", | ||
""" | ||
scripts: | ||
sig: | ||
- read-state: ${{VARIABLE}} | ||
regex: true | ||
then: | ||
- set-state: RUN.FOUND true | ||
else: | ||
- set-state: RUN.FOUND false | ||
hosts: | ||
test: TEST_HOST | ||
roles: | ||
role: | ||
hosts: [test] | ||
run-scripts: | ||
- sig | ||
""".replaceAll("TEST_HOST",getHost().toString()) | ||
)); | ||
builder.getState().set("VARIABLE",true); | ||
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(); | ||
|
||
State state = config.getState(); | ||
assertTrue(state.has("FOUND")); | ||
assertEquals("true",state.get("FOUND")); | ||
|
||
} | ||
} |