Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support on.fail.exec actions #13

Merged
merged 2 commits into from
Aug 9, 2023
Merged

support on.fail.exec actions #13

merged 2 commits into from
Aug 9, 2023

Conversation

jaypipes
Copy link
Member

@jaypipes jaypipes commented Aug 8, 2023

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:

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

Following commits will add the ability to reference an exec plugin
Action from a nested Spec `on.fail` field, so we simply separate out the
Action bit from the Spec in the exec plugin here.

Signed-off-by: Jay Pipes <[email protected]>
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]>
@jaypipes jaypipes requested a review from a-hilaly August 8, 2023 23:08
# --- FAIL: TestOnFail/on-fail-exec (0.00s)
on:
fail:
exec: echo "bad kitty"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐈

@a-hilaly a-hilaly merged commit 13c1ecd into main Aug 9, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants