Skip to content

Commit fea144c

Browse files
test(conformance): port workspace lifecycle tests to testkit (#4607)
Move e2e/rust workspace_lifecycle into a conformance workspaces suite on #[testkit::test], split into workspace_full_crud_lifecycle, template_is_scoped_to_its_workspace and workspace_terminating_rejects_creates. Use a sandbox template as the scoped resource so no provider profile is needed, and assert on exit status and listed state rather than message text. A refused workspace delete is checked to leave the workspace Terminating, so the failure is the resource guard rather than an unrelated error. Add Context::cli_find_listed to testkit to find an entry in a paginated --output json listing, erroring when the collection key is missing. Use it in the workspaces suite and in conformance/src/cli.rs, and list it in the testkit README. Drop the legacy test, its Cargo target, and its Podman archive exclusion. Signed-off-by: Evan Lezar <elezar@nvidia.com> Signed-off-by: politerealism <burdcat17@gmail.com>
1 parent ab14373 commit fea144c

9 files changed

Lines changed: 275 additions & 329 deletions

File tree

‎e2e/rust/Cargo.toml‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,6 @@ name = "forward_proxy_jsonrpc_l7"
226226
path = "tests/forward_proxy_jsonrpc_l7.rs"
227227
required-features = ["e2e-host-gateway"]
228228

229-
[[test]]
230-
name = "workspace_lifecycle"
231-
path = "tests/workspace_lifecycle.rs"
232-
required-features = ["e2e"]
233-
234229
[[test]]
235230
name = "supervisor_middleware_http_hooks"
236231
path = "tests/supervisor_middleware_http_hooks.rs"

‎e2e/rust/tests/workspace_lifecycle.rs‎

Lines changed: 0 additions & 278 deletions
This file was deleted.

‎tests/suites/conformance/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ nextest run the tests as the library's unit tests. The crate also builds the
2323
| `labels` | Labels are stored and select sandboxes in `sandbox list` |
2424
| `templates` | A sandbox created from a template uses its workload; duplicate, deleted and missing templates return the right errors |
2525
| `settings` | Sandbox-scoped settings |
26+
| `workspaces` | Workspace create, get, list and delete; a template is scoped to its workspace; a workspace holding a resource goes Terminating, rejects creates and deletes once empty |
2627
| `process` | Core dumps are disabled for sandbox processes |
2728
| `filesystem-policy` | Landlock: a hard requirement accepts added device paths; a replaced policy path rejects the next launch |
2829

‎tests/suites/conformance/src/cli.rs‎

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@
1111
use serde_json::Value;
1212
use testkit::Context;
1313

14-
const PAGE_SIZE: &str = "1000";
15-
/// More pages than any test gateway should have; stops a repeated token from
16-
/// looping forever.
17-
const MAX_PAGES: usize = 1000;
18-
1914
/// Delay before an attached main prints and exits, so the CLI attaches while
2015
/// the sandbox is Ready. On a multi-replica gateway, attaching after the main
2116
/// has exited fails unless the request reaches the replica holding the
@@ -226,44 +221,10 @@ async fn wait_unlisted(cx: &Context, name: &str) -> testkit::Result {
226221
.await
227222
}
228223

229-
/// The phase of the sandbox in `sandbox list`, if it is listed. Follows every
230-
/// page.
224+
/// The phase of the sandbox in `sandbox list`, if it is listed.
231225
async fn find_listed(cx: &Context, name: &str) -> testkit::Result<Option<String>> {
232-
let mut token = String::new();
233-
for _ in 0..MAX_PAGES {
234-
let page: Value = cx
235-
.cli([
236-
"sandbox",
237-
"list",
238-
"--page-size",
239-
PAGE_SIZE,
240-
"--page-token",
241-
&token,
242-
"--output",
243-
"json",
244-
])
245-
.await?
246-
.success()?
247-
.json()?;
248-
if let Some(entry) = page["sandboxes"]
249-
.as_array()
250-
.into_iter()
251-
.flatten()
252-
.find(|entry| entry["name"] == name)
253-
{
254-
return Ok(Some(
255-
entry["phase"].as_str().unwrap_or_default().to_string(),
256-
));
257-
}
258-
token = page["next_page_token"]
259-
.as_str()
260-
.unwrap_or_default()
261-
.to_string();
262-
if token.is_empty() {
263-
return Ok(None);
264-
}
265-
}
266-
Err(testkit::Error::msg(format!(
267-
"sandbox list has more than {MAX_PAGES} pages"
268-
)))
226+
let entry = cx
227+
.cli_find_listed(&["sandbox", "list"], "sandboxes", name)
228+
.await?;
229+
Ok(entry.map(|entry| entry["phase"].as_str().unwrap_or_default().to_string()))
269230
}

‎tests/suites/conformance/src/lib.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ mod settings;
2525
mod smoke;
2626
mod ssh;
2727
mod templates;
28+
mod workspaces;

0 commit comments

Comments
 (0)