|
| 1 | +Running tests |
| 2 | +============= |
| 3 | + |
| 4 | +The Datadog Go API client has 2 sorts of tests: regular tests and BDD tests. |
| 5 | +Both are using recodings to store HTTP interactions, allowing to run the tests without |
| 6 | +talking to the API. We also store the test time to be able to freeze. |
| 7 | + |
| 8 | +You can control the behavior with the `RECORD` environment variable: |
| 9 | + - `RECORD=false`, the default value, means replaying HTTP requests from recordings. |
| 10 | + - `RECORD=true` creates or updates recordings. This will need valid credentials in `DD_TEST_CLIENT_API_KEY` |
| 11 | + and `DD_TEST_CLIENT_APP_KEY`. |
| 12 | + - `RECORD=none` ignores recordings. This will also runs tests that we call `integration-only`, i.e. |
| 13 | + tests that we don't record for security reasons. It also needs valid credentials. |
| 14 | + |
| 15 | +Recording and freeze files are stored in `cassettes` directory in each test package with one file per tests |
| 16 | +(e.g. `tests/api/v1/datadog/cassettes/`). |
| 17 | + |
| 18 | +To run the tests, navigate to the `tests` directory and run: |
| 19 | + |
| 20 | +```shell |
| 21 | +go test $(go list ./...) |
| 22 | +``` |
| 23 | + |
| 24 | +You can get more verbose information with the `-v` flag, and run a specific |
| 25 | +test with the `-run` argument. For example: |
| 26 | + |
| 27 | +```shell |
| 28 | +go test $(go list ./...) -run TestSLOEventLifecycle -v |
| 29 | +``` |
| 30 | + |
| 31 | +This takes a regular expression, so you don't have to specify the whole exact |
| 32 | +string. |
| 33 | + |
| 34 | +The first time you run a test that needs recordings, it will fail with: |
| 35 | +`time file 'cassettes/$TEST_NAME.freeze' not found: create one setting 'RECORD=true' or ignore it using 'RECORD=none'`. |
| 36 | + |
| 37 | +BDD tests are triggered by a parent test named `TestScenarios`. To run a specific test, you need to specify |
| 38 | +the parent feature name in the `-run` argument, to look like `TestScenarios/$VERSION/Feature_$NAME/$TEST_NAME`. |
| 39 | +For example: |
| 40 | + |
| 41 | +```shell |
| 42 | +go test ./scenarios -run TestScenarios/v2/Feature_Users/Scenario_Send_invitation_emails |
| 43 | +``` |
| 44 | + |
| 45 | +Again we don't need to pass the full test name as it's a regular expression, |
| 46 | +but we do need to pass the full prefix. |
| 47 | + |
| 48 | +To get a better output you can use `gotestsum` in place of `go test`, with the `--format` option to customize |
| 49 | +the output. For example: |
| 50 | + |
| 51 | +```shell |
| 52 | +gotestsum --format testname ./scenarios -run TestScenarios/Feature_Users/Scenario_Send_invitation_emails |
| 53 | +``` |
0 commit comments