Skip to content

Commit 163fa4d

Browse files
refactor(testkit): tighten error helpers and document test scope
Read errors in gateway.rs and the image test use .context(..) now that the error types convert. Error::from_error and from_display are crate-private. Document why the global-setting helpers take &Cli, why the template test names and adopts its sandbox by hand, SandboxBuilder::restart_policy, and that the --no-keep test checks only gateway-visible removal. Signed-off-by: Matthew Grossman <[email protected]>
1 parent 1ed49ce commit 163fa4d

7 files changed

Lines changed: 16 additions & 7 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
//! Sandbox image suite: a sandbox runs the image it is created from.
55
6-
use testkit::{Context, Sandbox};
6+
use testkit::{Context, ResultExt as _, Sandbox};
77

88
/// A sandbox created with an explicit image runs that image.
99
#[testkit::test]
@@ -17,7 +17,7 @@ async fn explicit_image_is_used(cx: &mut Context) -> testkit::Result {
1717
.await?;
1818
expect_ubuntu(&sandbox)
1919
.await
20-
.map_err(|error| error.context(format!("sandbox from image {image}")))
20+
.context(format!("sandbox from image {image}"))
2121
}
2222

2323
/// Fail unless the sandbox's `/etc/os-release` names Ubuntu and a version,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,10 @@ const EPHEMERAL_CLEANUP_TIMEOUT: Duration = Duration::from_secs(60);
492492

493493
/// A detached sandbox created with `--no-keep` is removed once its main
494494
/// command exits, whether the command succeeds or fails.
495+
///
496+
/// This checks only what the gateway shows: get and list stop returning the
497+
/// sandbox. It doesn't check that the driver removed its containers, pods or
498+
/// VM state; conformance can't see driver resources.
495499
#[testkit::test]
496500
async fn detached_no_keep_sandbox_is_removed_after_main_exits(cx: &mut Context) -> testkit::Result {
497501
let mut sandboxes = Vec::new();

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ async fn expect_sandbox_setting(
137137
.await
138138
}
139139

140+
// The global-setting helpers take `&Cli` rather than `&Context` because the
141+
// cleanup hook that restores the setting calls them after the test body,
142+
// when the context can no longer be borrowed.
143+
140144
/// The gateway-global value of `key` as the CLI shows it, [`UNSET`] if none.
141145
async fn read_global_setting(cli: &testkit::Cli, key: &str) -> testkit::Result<String> {
142146
let settings: Value = cli

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ async fn sandbox_from_template_uses_its_workload(cx: &mut Context) -> testkit::R
106106
"template list does not include {template_name}"
107107
);
108108

109+
// `SandboxBuilder` can't create from a template, so name, track and adopt by hand.
109110
let sandbox_name = cx.name("ts");
110111
cx.track(&sandbox_name);
111112
cx.client()

‎tests/testkit/testkit/src/context.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ impl SandboxBuilder {
314314
self
315315
}
316316

317+
/// Whether the sandbox restarts when its main command exits: never, on
318+
/// failure, or always.
317319
pub fn restart_policy(mut self, policy: SandboxRestartPolicy) -> Self {
318320
self.spec.restart_policy = policy;
319321
self

‎tests/testkit/testkit/src/error.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ impl Error {
3131
self.code
3232
}
3333

34-
pub fn from_display(error: impl fmt::Display) -> Self {
34+
pub(crate) fn from_display(error: impl fmt::Display) -> Self {
3535
Self::msg(error.to_string())
3636
}
3737

3838
/// An error with its sources, so a wrapper such as tonic's
3939
/// "transport error" still says what went wrong underneath.
40-
pub fn from_error(error: &(dyn std::error::Error + 'static)) -> Self {
40+
pub(crate) fn from_error(error: &(dyn std::error::Error + 'static)) -> Self {
4141
let mut message = error.to_string();
4242
let mut source = error.source();
4343
while let Some(cause) = source {

‎tests/testkit/testkit/src/gateway.rs‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,7 @@ fn env(name: &str) -> Option<String> {
231231
}
232232

233233
fn read(path: &Path) -> Result<Vec<u8>> {
234-
std::fs::read(path)
235-
.map_err(Error::from_display)
236-
.context(format!("read {}", path.display()))
234+
std::fs::read(path).context(format!("read {}", path.display()))
237235
}
238236

239237
#[cfg(test)]

0 commit comments

Comments
 (0)