From f0cf71ffd42dafeab5f6ea6ef9d1af6fe0fc6c08 Mon Sep 17 00:00:00 2001 From: Edoardo Tenani <526307+endorama@users.noreply.github.com> Date: Thu, 7 Apr 2022 11:23:16 +0200 Subject: [PATCH] Add event data generation to dev docs (#30395) docs: add test data generation info Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Denis Rechkunov Co-authored-by: kaiyan-sheng --- docs/devguide/testing.asciidoc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/devguide/testing.asciidoc b/docs/devguide/testing.asciidoc index 4f8a138beb31..8419944c6ddf 100644 --- a/docs/devguide/testing.asciidoc +++ b/docs/devguide/testing.asciidoc @@ -21,6 +21,15 @@ To run all non integration tests for a beat run `make unit`. This will execute a All Go tests are in the same package as the tested code itself and have the postfix `_test` in the file name. Most of the tests are in the same package as the rest of the code. Some of the tests which should be separate from the rest of the code or should not use private variables go under `{packagename}_test`. +===== Generate sample events + +Go tests support generating sample events to be used as fixtures. + +This generation can be perfomed running `go test --data`. This functionality is supported by packetbeat and Metricbeat. + +In Metricbeat, run the command from within a module like this: `go test --tags integration,azure --data --run "TestData"`. Make sure to add the relevant tags (`integration` is common then add module and metricset specific tags). + +A note about tags: the `--data` flag is a custom flag added by Metricbeat and Packetbeat frameworks. It will not be present in case tags do not match, as the relevant code will not be run and silently skipped (without the tag the test file is ignored by Go compiler so the framework doesn't load). This may happen if there are different tags in the build tags of the metricset under test (i.e. the GCP billing metricset requires the `billing` tag too). ==== Running Python Tests