-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Users would like to be able to execute commands, collect log information, grep for errors in output and other actions when a test assertion fails. For instance, if an application is deployed using Kubernetes and network connectivity doesn't work for the application, the test author might want to call kubectl logs in the event of a test failure. Another example might be if you wanted to grep a log file in the event that no connectivity on a particular IP:PORT combination could be made you might do this: ```yaml tests: - exec: nc -z $HOST $PORT on: fail: exec: grep ERROR /var/log/myapp.log ``` The grep ERROR /var/log/myapp.log command will only be executed if there is no connectivity to $HOST:$PORT and the results of that grep will be directed to the test's output. You can use the gdt.WithDebug() function to configure additional io.Writers to direct this output to. This patch adds support for the exec plugin's `on.fail` field, hopefully in a way that is extensible for other plugins to use as an example (and possible embed the `plugin/exec.Action` struct). Addresses Issue #12 Signed-off-by: Jay Pipes <[email protected]>
- Loading branch information
Showing
8 changed files
with
230 additions
and
47 deletions.
There are no files selected for viewing
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
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
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
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
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,29 @@ | ||
// Use and distribution licensed under the Apache license version 2. | ||
// | ||
// See the COPYING file in the root project directory for full text. | ||
|
||
package exec | ||
|
||
// On describes actions that can be taken upon certain conditions. | ||
type On struct { | ||
// Fail contains one or more actions to take if any of a Spec's assertions | ||
// fail. | ||
// | ||
// For example, if you wanted to grep a log file in the event that no | ||
// connectivity on a particular IP:PORT combination could be made you might | ||
// do this: | ||
// | ||
// ```yaml | ||
// tests: | ||
// - exec: nc -z $HOST $PORT | ||
// on: | ||
// fail: | ||
// exec: grep ERROR /var/log/myapp.log | ||
// ``` | ||
// | ||
// The `grep ERROR /var/log/myapp.log` command will only be executed if | ||
// there is no connectivity to $HOST:$PORT and the results of that grep | ||
// will be directed to the test's output. You can use the `gdt.WithDebug()` | ||
// function to configure additional `io.Writer`s to direct this output to. | ||
Fail *Action `yaml:"fail,omitempty"` | ||
} |
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
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
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,31 @@ | ||
name: on-fail-exec | ||
description: a scenario that has an on.fail.exec clause | ||
tests: | ||
- exec: echo "cat" | ||
assert: | ||
out: | ||
is: cat | ||
# Unfortunately there's not really any good way of testing things like this | ||
# except by manually causing an assertion to fail in the test case and checking | ||
# to see if the `on.fail` action was taken and debug output emitted to the | ||
# console. | ||
# | ||
# When I change `assert.out.is` above to "dat" instead of "cat", I get the | ||
# correct behaviour: | ||
# | ||
# === RUN TestOnFail | ||
# === RUN TestOnFail/on-fail-exec | ||
# action.go:59: exec: echo [cat] | ||
# eval.go:35: assertion failed: not equal: expected dat but got cat | ||
# action.go:59: exec: echo [bad kitty] | ||
# eval.go:46: on.fail.exec: stdout: bad kitty | ||
# === NAME TestOnFail | ||
# eval_test.go:256: | ||
# Error Trace: /home/jaypipes/src/github.com/gdt-dev/gdt/plugin/exec/eval_test.go:256 | ||
# Error: Should be false | ||
# Test: TestOnFail | ||
# --- FAIL: TestOnFail (0.00s) | ||
# --- FAIL: TestOnFail/on-fail-exec (0.00s) | ||
on: | ||
fail: | ||
exec: echo "bad kitty" |