Skip to content

Commit cada6df

Browse files
docs(testkit): describe what testkit provides today
Signed-off-by: Matthew Grossman <mgrossman@nvidia.com>
1 parent faa52fe commit cada6df

2 files changed

Lines changed: 21 additions & 65 deletions

File tree

‎TESTING.md‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,11 @@ driver configuration boundary.
132132

133133
### testkit (`tests/testkit/`)
134134

135-
`testkit` is the support library for SDK-driven end-to-end suites under
136-
`tests/suites/`. Tests are `#[testkit::test]` functions with a required stable
137-
`id`, a required doc comment, and optional `requires = [...]` capabilities.
138-
They run against the gateway described by the target file named in
139-
`OPENSHELL_TEST_TARGET`. No suite uses it yet. See
140-
[tests/testkit/README.md](tests/testkit/README.md) for how to write tests, what
141-
a conformance test may assert, and how to run against a hand-written target
142-
file.
135+
`testkit` is the support library for SDK-driven end-to-end suites. Tests are
136+
`#[testkit::test]` functions with a required doc comment. They run against the
137+
gateway described by the target file named in `OPENSHELL_TEST_TARGET`. See
138+
[tests/testkit/README.md](tests/testkit/README.md) for how to write and run
139+
tests.
143140

144141
### Python E2E (`e2e/python/`)
145142

‎tests/testkit/README.md‎

Lines changed: 16 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
# testkit
22

3-
Shared support for end-to-end test suites under `tests/suites/`. Suites test
4-
a running OpenShell gateway through the Rust SDK and the installed `openshell`
5-
CLI. No suite uses testkit yet; existing suites move to it one at a time.
3+
Shared support for end-to-end test suites. Suites test a running OpenShell
4+
gateway through the Rust SDK and the installed `openshell` CLI.
65

76
This is a separate Cargo workspace with its own lockfile:
87

98
| Crate | Purpose |
109
|---|---|
1110
| `testkit` | Reads the target file, connects to the gateway, creates and cleans up sandboxes, runs the CLI. Also builds `testkit-ready`. |
1211
| `testkit-macros` | The `#[testkit::test]` attribute. |
13-
| `testkit-spec` | Parses `#[testkit::test]` functions, shared by the attribute and tools that list tests. |
1412

1513
## Writing a test
1614

@@ -22,7 +20,7 @@ use testkit::Context;
2220

2321
/// A long-running sandbox becomes ready, runs a command with exec, and is gone
2422
/// from get and list after delete.
25-
#[testkit::test(id = "t-3tfdx240")]
23+
#[testkit::test]
2624
async fn long_running_exec_delete(cx: &mut Context) -> testkit::Result {
2725
let sandbox = cx.sandbox("lr").command(["sleep", "infinity"]).create().await?;
2826
sandbox.wait_ready().await?;
@@ -31,44 +29,25 @@ async fn long_running_exec_delete(cx: &mut Context) -> testkit::Result {
3129
}
3230
```
3331

34-
- **`id` is required.** Use `t-` followed by eight random lowercase letters or
35-
digits. Results and coverage records refer to tests by this ID, so never
36-
change or reuse it, including when you rename or move the test. Omit `id`
37-
on a new test and the compile error suggests a fresh one.
3832
- **The doc comment is required.** It is the test's description.
39-
- **`requires` declares capabilities** the test needs, for example
40-
`#[testkit::test(id = "...", requires = [service_exposure])]`. The names are
41-
the boolean fields of `capabilities` in the target file. An unknown name
42-
fails to compile. If the target lacks a required capability, the test
43-
fails rather than passing untested. See
44-
[Excluding tests by capability](#excluding-tests-by-capability).
45-
- **The function name is the nextest test name.** Rename it freely; the ID
46-
keeps the history.
33+
- **The function name is the nextest test name.**
4734

4835
Cleanup runs after every test, whether it passes, fails, or panics. It only
4936
deletes sandboxes created through `cx.sandbox(...)`. Delete anything else a
5037
test creates, such as providers, in the test itself.
5138

52-
## What a conformance test may assert
53-
54-
A conformance test asserts only what the public contract promises: the
55-
comments in `proto/` and the published docs, such as the sandbox lifecycle in
56-
`docs/how-it-works/sandboxes/overview.mdx`. Do not encode gateway behavior
57-
the contract does not state; file an issue to document it instead.
58-
59-
- Assert on a sandbox's `phase` and `exit_code`, not condition reasons, which
60-
the API leaves to the platform.
61-
- To check that something did not happen, read state (for example,
62-
`restart_count` is 0 and a second read shows the same phase) instead of
63-
sleeping and watching.
64-
- Behavior the docs leave to the compute driver needs a capability in
65-
`requires`.
66-
- Act through the interface that makes the promise. Upload, download,
67-
connect, and port forwarding exist only in the CLI, so call
68-
`cx.cli([...])` and rely on its exit code and `--output json`, not its
69-
table text.
70-
- For API calls the SDK does not wrap yet, add a testkit helper over the
71-
generated gRPC client rather than calling it from tests.
39+
## What a test can do
40+
41+
`Context` currently provides:
42+
43+
- `cx.sandbox(suffix)` to build and create a sandbox with a run-unique name.
44+
The returned `Sandbox` can wait for ready or finished, stop, start, exec,
45+
read its config and draft policy, set a setting, and delete.
46+
- `cx.expect_listed` and `cx.expect_absent` to check a sandbox in list and get.
47+
- `cx.cli([...])` to run the installed CLI against the same gateway, with
48+
`success()`, `failure()`, and `json()` on the output.
49+
- `cx.client()` for SDK calls testkit does not wrap.
50+
- `poll_until` for waiting on other state.
7251

7352
## Running against a gateway
7453

@@ -88,11 +67,6 @@ cli: # needed by tests that call cx.cli
8867
binary: /usr/bin/openshell # default: `openshell` on PATH
8968
gateway: local # default: the CLI's active gateway
9069
workspace: default
91-
capabilities:
92-
compute_driver: docker
93-
service_exposure: true
94-
persistent_workspace: false
95-
gpu: false
9670
```
9771
9872
Wait for the gateway, then run a suite. Run tests that share a gateway one at
@@ -107,21 +81,6 @@ cargo nextest run --manifest-path <suite>/Cargo.toml --test-threads 1
10781
`testkit-ready [TIMEOUT_SECS]` exits non-zero if the gateway is not healthy in
10882
time or the target's CLI does not report it connected.
10983

110-
### Excluding tests by capability
111-
112-
Nothing selects tests by capability yet, so a test whose `requires` the target
113-
does not provide fails with `requires <capability>, which the target does not
114-
provide`. Find those tests and exclude them by name with a nextest filter:
115-
116-
```shell
117-
grep -rn 'requires = \[' <suite>/tests
118-
cargo nextest run --manifest-path <suite>/Cargo.toml --test-threads 1 \
119-
-E 'not test(=stopped_sandbox_keeps_workspace)'
120-
```
121-
122-
Combine names with `or` inside the parentheses, for example
123-
`-E 'not (test(=a) or test(=b))'`.
124-
12584
## Checks
12685

12786
```shell

0 commit comments

Comments
 (0)