- add examples/ with a ready-to-import self-test: environment, credential, snippets and a scenario that creates, runs and checks another scenario through the liqa REST API and UI, then cleans up - add test/examples.spec.ts: imports every example and parses its code - link the examples from README, docs/scenario.md and CLAUDE.md Closes #6 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
56 lines
4.1 KiB
Markdown
56 lines
4.1 KiB
Markdown
# Self-test
|
|
|
|
A scenario that tests the liqa instance it runs on. It drives liqa through its own REST API and web UI: it creates a small scenario, runs it, checks the result and deletes it again. It shows the main liqa features in one place:
|
|
|
|
- an **environment** with the URLs and test values the steps read with `context.getEnv()`
|
|
- a **credential**, assigned to the scenario as `fixture` and read with `context.getCredential()`
|
|
- three **snippets**, called with `context.runSnippet()`, one of them from the other two
|
|
- **assertions** (`context.assert()` and Playwright's `expect`), step outputs (`context.getStepOutput()`) and run logs
|
|
|
|
Everything is in [self-test.yaml](self-test.yaml).
|
|
|
|
## Run it
|
|
|
|
1. Start liqa with the default docker compose deployment (`docker compose up -d --build` at the repo root). It's served at http://localhost:13000.
|
|
2. Import [self-test.yaml](self-test.yaml): open **Import** in the UI and pick the file, or run
|
|
|
|
```bash
|
|
curl -X POST http://localhost:13000/api/v1/import \
|
|
-H 'Content-Type: application/yaml' \
|
|
--data-binary @examples/self-test/self-test.yaml
|
|
```
|
|
|
|
Every item has a fixed id, so importing the file again updates the same resources instead of adding copies.
|
|
3. Open the **liqa self-test** scenario and click **Run**. Its default environment, `liqa-self-test`, is preselected.
|
|
|
|
The run takes a few seconds. The run page shows every assertion as a log entry, and the target scenario's run while it exists.
|
|
|
|
## What's in the file
|
|
|
|
| Kind | Name | Purpose |
|
|
|---|---|---|
|
|
| Environment | `liqa-self-test` | `liqa_url` (REST API base), `ui_url` (web UI base), `temp_prefix` (name prefix of the temporary resources), `greeting` (test value) |
|
|
| Credential | `liqa-self-test-fixture` | Test data (`username`, `token`) that the self-test passes on to the scenario it creates. It's not a real secret |
|
|
| Snippet | `liqa-api` | `runSnippet("liqa-api", method, path, body?)`: calls `liqa_url` + `/api/v1` + `path`, returns the parsed JSON and throws on an error status |
|
|
| Snippet | `liqa-run-and-wait` | `runSnippet("liqa-run-and-wait", scenarioId, environmentId)`: starts a run and returns it once it has finished. Uses `liqa-api` |
|
|
| Snippet | `self-test-cleanup` | Deletes every scenario, credential and environment whose name starts with `temp_prefix` and returns how many it deleted. Uses `liqa-api` |
|
|
| Scenario | `liqa self-test` | The self-test itself (below) |
|
|
|
|
The scenario's steps:
|
|
|
|
1. **Check the instance is up**: checks `GET /health`, then runs `self-test-cleanup` to remove anything a failed earlier run left behind (and logs a warning if it found some).
|
|
2. **Create the target scenario**: creates a temporary environment, a temporary credential (holding the `fixture` credential's data) and the target scenario `[self-test] target scenario`, and assigns the credential to it as `secret`. The target has two steps: one reads `greeting` and the `secret` token, the other renders the greeting on a page and checks it with `expect`.
|
|
3. **Run the target scenario**: runs it with `liqa-run-and-wait` and checks the result: the run and both steps passed, the step outputs hold the greeting and the token's length, and the target logged its passing assertion.
|
|
4. **Check the run in the UI**: opens the target's run page at `ui_url` and checks that it shows the scenario name and the assertion.
|
|
5. **Clean up**: runs `self-test-cleanup` again, and checks that it deleted the three temporary resources and that the target scenario is gone.
|
|
|
|
## Addresses
|
|
|
|
Steps run inside the liqa server, so `liqa_url` and `ui_url` are addresses as seen from the server, not from your machine. In the docker compose deployment the server listens on port 3000 inside the container, published as 13000 on the host, so both are `http://localhost:3000`.
|
|
|
|
When running the server locally (`npm run start:dev`, see [docs/development.md](../../docs/development.md)), `liqa_url` stays `http://localhost:3000`. The UI is then served by the Vite dev server: set `ui_url` to `http://localhost:5173`.
|
|
|
|
## When it fails
|
|
|
|
A failed step stops the run, so the temporary resources (named `[self-test] ...`) are left in place to inspect. The next self-test run deletes them in its first step.
|