-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add Store::list integration test
Signed-off-by: Fabrizio Sestito <[email protected]>
- Loading branch information
1 parent
41e940f
commit edd3bb2
Showing
2 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use std::path::Path; | ||
|
||
use anyhow::Result; | ||
use policy_fetcher::policy::Policy; | ||
use policy_fetcher::store::{path, Store}; | ||
use tempfile::tempdir; | ||
|
||
#[test] | ||
fn test_list() -> Result<()> { | ||
let store_root = tempdir()?; | ||
|
||
let mut expected_policies = vec![ | ||
Policy { | ||
uri: "https://internal.host.company/some/path/to/1.0.0/wasm-module.wasm".to_owned(), | ||
local_path: store_root.path().join(path::encode_path( | ||
"https/internal.host.company/some/path/to/1.0.0/wasm-module.wasm", | ||
)), | ||
}, | ||
Policy { | ||
uri: "registry://ghcr.io/some/path/to/wasm-module.wasm:1.0.0".to_owned(), | ||
local_path: store_root.path().join(path::encode_path( | ||
"registry/ghcr.io/some/path/to/wasm-module.wasm:1.0.0", | ||
)), | ||
}, | ||
Policy { | ||
uri: "registry://internal.host.company:5000/some/path/to/wasm-module.wasm:1.0.0" | ||
.to_owned(), | ||
local_path: store_root.path().join(path::encode_path( | ||
"registry/internal.host.company:5000/some/path/to/wasm-module.wasm:1.0.0", | ||
)), | ||
}, | ||
]; | ||
|
||
setup_store(&expected_policies)?; | ||
|
||
let store = Store::new(store_root.path()); | ||
let mut list = store.list()?; | ||
|
||
expected_policies.sort_by_key(|p| p.uri.clone()); | ||
list.sort_by_key(|p| p.uri.clone()); | ||
|
||
assert_eq!(expected_policies, list); | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Setup a temporary store with the given policies. | ||
/// By using tempdir, the store will be cleaned up automatically when the TempDir struct is dropped. | ||
fn setup_store(policies: &[Policy]) -> Result<()> { | ||
for policy in policies { | ||
std::fs::create_dir_all(policy.local_path.parent().unwrap())?; | ||
|
||
std::fs::copy( | ||
Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/test_data/simple.wasm"), | ||
&policy.local_path, | ||
)?; | ||
} | ||
|
||
Ok(()) | ||
} |