Skip to content

Commit

Permalink
add: tests for wai tar gz
Browse files Browse the repository at this point in the history
  • Loading branch information
dynamite-bud committed Oct 24, 2023
1 parent fe3613e commit fbb4355
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions lib/registry/src/package/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,4 +781,63 @@ runner = "https://webc.org/runner/wcgi"

pretty_assertions::assert_eq!(map, expected);
}

#[test]
fn test_construct_wai_package_tar_gz() {
let manifest_str = r#"[package]
name = "dynamite-bud/crumsort-wasm"
version = "0.2.4"
description = "Crumsort from Google made for WASM"
[[module]]
name = "crumsort-wasm"
source = "crumsort_wasm.wasm"
[module.bindings]
wai-version = "0.2.0"
exports = "crum-sort.wai"
"#;

let archive_dir = tempfile::tempdir().unwrap();

let manifest_dir = tempfile::tempdir().unwrap();

let mp = manifest_dir.path();
let manifest_path = mp.join("wasmer.toml");

std::fs::write(&manifest_path, manifest_str).unwrap();
std::fs::write(mp.join("crumsort_wasm.wasm"), "()").unwrap();
std::fs::write(mp.join("crum-sort.wai"), "/// crum-sort.wai").unwrap();

let manifest = wasmer_toml::Manifest::parse(&manifest_str).unwrap();
let meta = construct_tar_gz(&archive_dir.path(), &manifest, &manifest_path).unwrap();

let mut data = std::io::Cursor::new(std::fs::read(&meta.archive_path).unwrap());

let gz = flate2::read::GzDecoder::new(&mut data);
let mut archive = tar::Archive::new(gz);

let map = archive
.entries()
.unwrap()
.map(|res| {
let mut entry = res.unwrap();
let name = entry.path().unwrap().to_str().unwrap().to_string();
let mut contents = String::new();
entry.read_to_string(&mut contents).unwrap();
eprintln!("{name}:\n{contents}\n\n");
(name, contents)
})
.collect::<std::collections::HashMap<String, String>>();

let expected: std::collections::HashMap<String, String> = [
("wapm.toml".to_string(), manifest_str.to_string()),
("crum-sort.wai".to_string(), "/// crum-sort.wai".to_string()),
("crumsort_wasm.wasm".to_string(), "()".to_string()),
]
.into_iter()
.collect();

pretty_assertions::assert_eq!(map, expected);
}
}

0 comments on commit fbb4355

Please sign in to comment.