Skip to content

Commit

Permalink
wrap StorageSettings...: unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
mvidner committed Feb 25, 2025
1 parent 027465f commit e5cd13d
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion rust/agama-lib/src/storage/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ mod test {
let url = server.url("/api");

let store = storage_store(url);
let settings = store.load().await?;
let opt_settings = store.load().await?;
assert!(opt_settings.is_some());
let settings = opt_settings.unwrap();

// main assertion
assert_eq!(settings.storage.unwrap().get(), r#"{ "some": "stuff" }"#);
Expand All @@ -91,6 +93,28 @@ mod test {
Ok(())
}

#[test]
async fn test_getting_storage_null() -> Result<(), Box<dyn Error>> {
let server = MockServer::start();
let storage_mock = server.mock(|when, then| {
when.method(GET).path("/api/storage/config");
then.status(200)
.header("content-type", "application/json")
.body("null");
});
let url = server.url("/api");

let store = storage_store(url);
let opt_settings = store.load().await?;

// main assertion
assert!(opt_settings.is_none());

// Ensure the specified mock was called exactly one time (or fail with a detailed error description).
storage_mock.assert();
Ok(())
}

#[test]
async fn test_setting_storage_ok() -> Result<(), Box<dyn Error>> {
let server = MockServer::start();
Expand Down

0 comments on commit e5cd13d

Please sign in to comment.