Skip to content

Commit a3fcf75

Browse files
test(testkit): add a typed provider profile builder
Signed-off-by: Matthew Grossman <mgrossman@nvidia.com>
1 parent 8cf7e3e commit a3fcf75

9 files changed

Lines changed: 400 additions & 2 deletions

File tree

‎tests/suites/conformance/Cargo.lock‎

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tests/suites/drivers/podman/Cargo.lock‎

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tests/support/Cargo.lock‎

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tests/testkit/Cargo.lock‎

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tests/testkit/README.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,10 @@ fails. A killed test process skips cleanup, so names are unique to the run.
136136
`id`, and `cx.create_provider(name, type, credentials)` to create a
137137
provider, each with cleanup. `cx.install_provider(name, profile,
138138
credentials)` does both. Chain `.config(key, value)` before the `.await`
139-
to set provider config.
139+
to set provider config. Build the profile with `testkit::Profile` and
140+
`testkit::Credential`, whose setters are named after the profile YAML
141+
fields; `policy::Endpoint` configures its endpoints. `profile.to_yaml()`
142+
renders it for these calls.
140143
- `testkit::YamlFile` for YAML a CLI command reads from a file.
141144
- `cx.client()` for SDK calls testkit does not wrap.
142145
- In `tests/support`: `host-server` starts servers on the machine that runs

‎tests/testkit/testkit/Cargo.toml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ name = "testkit"
1818
openshell-bootstrap = { path = "../../../crates/openshell-bootstrap" }
1919
openshell-core = { path = "../../../crates/openshell-core", default-features = false }
2020
openshell-policy = { path = "../../../crates/openshell-policy" }
21+
openshell-providers = { path = "../../../crates/openshell-providers" }
2122
openshell-sdk = { path = "../../../crates/openshell-sdk" }
2223
openshell-testkit-macros = { path = "../testkit-macros" }
2324
clap = { version = "4", features = ["derive"] }
@@ -37,6 +38,9 @@ tonic = "0.14"
3738
[target.'cfg(unix)'.dependencies]
3839
libc = "0.2"
3940

41+
[dev-dependencies]
42+
prost-types = "0.14"
43+
4044
# A test program, run by `cargo test` and nextest through `testkit::main`'s
4145
# libtest interface, that checks the program's own subcommands.
4246
[[test]]

‎tests/testkit/testkit/src/lib.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ mod logs;
3838
mod output;
3939
pub mod policy;
4040
mod poll;
41+
pub mod profile;
4142
pub mod program;
4243
mod provider;
4344
mod ready;
@@ -59,6 +60,7 @@ pub use image::{PYTHON_BINARIES, base_image, python_image};
5960
pub use logs::{LOGS_TIMEOUT, Logs};
6061
pub use openshell_sdk as sdk;
6162
pub use poll::{Poll, poll_until, with_deadline};
63+
pub use profile::{Credential, Profile};
6264
pub use program::main;
6365
pub use provider::ProviderBuilder;
6466
pub use ready::check as check_ready;

‎tests/testkit/testkit/src/policy.rs‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ pub trait Endpoint {
150150
fn credential_binding(&mut self, provider: &str) -> &mut Self;
151151
/// `allow_uninspected_credentials: true`.
152152
fn allow_uninspected_credentials(&mut self) -> &mut Self;
153+
/// `enforcement: enforce`.
154+
fn enforce(&mut self) -> &mut Self;
155+
/// `path: <path>`.
156+
fn path(&mut self, path: &str) -> &mut Self;
153157
}
154158

155159
impl Endpoint for proto::NetworkEndpoint {
@@ -186,6 +190,16 @@ impl Endpoint for proto::NetworkEndpoint {
186190
self.allow_uninspected_credentials = true;
187191
self
188192
}
193+
194+
fn enforce(&mut self) -> &mut Self {
195+
self.enforcement = proto::NetworkEnforcementMode::Enforce as i32;
196+
self
197+
}
198+
199+
fn path(&mut self, path: &str) -> &mut Self {
200+
self.path = path.to_string();
201+
self
202+
}
189203
}
190204

191205
#[cfg(test)]
@@ -216,7 +230,9 @@ mod tests {
216230
&["/usr/bin/python*"],
217231
)
218232
.websocket(Access::ReadWrite)
219-
.allow_uninspected_credentials();
233+
.allow_uninspected_credentials()
234+
.enforce()
235+
.path("/ws");
220236

221237
let yaml = format!(
222238
"{BASE}network_policies:
@@ -235,6 +251,8 @@ mod tests {
235251
protocol: websocket
236252
access: read-write
237253
allow_uninspected_credentials: true
254+
enforcement: enforce
255+
path: /ws
238256
binaries:
239257
- path: /usr/bin/python*
240258
"

0 commit comments

Comments
 (0)