Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libtest-mimic #11

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 159 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions components/key-value/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ impl Guest for Component {
fn handle(request: IncomingRequest, response_out: ResponseOutparam) {
let result = handle(request)
.map(|r| match r {
Some(e) => response(500, format!("{e}").as_bytes()),
None => response(200, b""),
Err(e) => response(500, format!("{e}").as_bytes()),
Ok(()) => response(200, b""),
})
.map_err(|e| ErrorCode::InternalError(Some(e.to_string())));
ResponseOutparam::set(response_out, result)
}
}

fn handle(_req: IncomingRequest) -> anyhow::Result<Option<Error>> {
fn handle(_req: IncomingRequest) -> anyhow::Result<Result<(), Error>> {
anyhow::ensure!(matches!(Store::open("forbidden"), Err(Error::AccessDenied)));
let store = match Store::open("default") {
Ok(s) => s,
Err(e) => return Ok(Some(e)),
Err(e) => return Ok(Err(e)),
};

// Ensure nothing set in `bar` key
Expand Down Expand Up @@ -71,7 +71,7 @@ fn handle(_req: IncomingRequest) -> anyhow::Result<Option<Error>> {
anyhow::ensure!(matches!(store.get("qux"), Ok(None)));
anyhow::ensure!(matches!(store.get_keys().as_deref(), Ok(&[])));

Ok(None)
Ok(Ok(()))
}

fn response(status: u16, body: &[u8]) -> OutgoingResponse {
Expand Down
3 changes: 2 additions & 1 deletion crates/conformance-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ edition = "2021"
[dependencies]
anyhow = "1.0"
flate2 = "1.0"
json5 = "0.4.1"
json5 = "0.4"
libtest-mimic = "0.7"
reqwest = { version = "0.12", features = ["blocking"] }
serde = { version = "1.0", features = ["derive"] }
tar = "0.4.40"
Expand Down
Loading