Skip to content

Commit

Permalink
fix(tests): Nassun baseline tests (#196)
Browse files Browse the repository at this point in the history
Fixes: #155
  • Loading branch information
DerNamenlose committed Mar 20, 2023
1 parent 49ed83b commit 58e7685
Show file tree
Hide file tree
Showing 7 changed files with 544 additions and 4 deletions.
116 changes: 113 additions & 3 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Expand Up @@ -81,6 +81,7 @@ js-sys = "0.3.61"
kdl = "5.0.0-alpha.0"
maplit = "1.0.2"
miette = "5.5.0"
mockito = "1.0.0"
node-semver = "2.1.0"
nom = "7.1.3"
once_cell = "1.17.1"
Expand All @@ -104,6 +105,7 @@ tar = "0.4.38"
tempfile = "3.3.0"
term_grid = "0.1.7"
term_size = "0.3.2"
test-case = "3.0.0"
thiserror = "1.0.38"
tracing = "0.1.37"
tracing-appender = "0.2.2"
Expand Down
10 changes: 9 additions & 1 deletion crates/nassun/Cargo.toml
Expand Up @@ -15,7 +15,11 @@ oro-client = { version = "=0.3.11", path = "../oro-client" }
oro-package-spec = { version = "=0.3.11", path = "../oro-package-spec" }

async-compression = { workspace = true, features = ["gzip", "futures-io"] }
async-std = { workspace = true, features = ["attributes", "unstable"] }
async-std = { workspace = true, features = [
"attributes",
"unstable",
"tokio1",
] }
async-trait = { workspace = true }
bincode = { workspace = true }
dashmap = { workspace = true }
Expand All @@ -31,6 +35,10 @@ tracing = { workspace = true }
tsify = { workspace = true, default-features = false, features = ["js"] }
url = { workspace = true }

[dev-dependencies]
mockito = { workspace = true }
test-case = { workspace = true }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
async-tar-wasm = "0.4.2-wasm.1"
async-process = { workspace = true }
Expand Down
57 changes: 57 additions & 0 deletions crates/nassun/src/fetch/dir.rs
Expand Up @@ -234,3 +234,60 @@ impl Manifest {
Ok(packument)
}
}

#[cfg(test)]
mod test {
use super::*;
use std::{fs::File, io::Write, path::PathBuf};

use tempfile::{tempdir, TempDir};

fn setup_dirs() -> Result<(impl PackageFetcher, PackageSpec, TempDir, PathBuf, PathBuf)> {
let tmp = tempdir()?;
let package_path = tmp.path().join("oro-test");
let cache_path = tmp.path().join("cache");
std::fs::create_dir_all(&package_path)?;
std::fs::create_dir_all(&cache_path)?;
let mut package_file = File::create(package_path.join("package.json"))?;
package_file.write_all(
r#"{
"name": "oro-test",
"version": "1.4.2"
}"#
.as_bytes(),
)?;
let dir_fetcher = DirFetcher;

let package_spec = PackageSpec::Dir {
path: PathBuf::new().join(&package_path),
};

Ok((dir_fetcher, package_spec, tmp, package_path, cache_path))
}

#[async_std::test]
async fn read_name() -> Result<()> {
let (fetcher, package_spec, _tmp, _package_path, cache_path) = setup_dirs()?;
let name = fetcher.name(&package_spec, &cache_path).await?;
assert_eq!(name, "oro-test");
Ok(())
}

#[async_std::test]
async fn read_packument() -> miette::Result<()> {
let (fetcher, package_spec, _tmp, _package_path, cache_path) = setup_dirs()?;
let packument = fetcher.packument(&package_spec, &cache_path).await?;
assert_eq!(packument.versions.len(), 1);
assert!(packument.versions.contains_key(&"1.4.2".parse()?));
assert_eq!(
packument
.versions
.get(&"1.4.2".parse()?)
.unwrap()
.dist
.file_count,
None
);
Ok(())
}
}

0 comments on commit 58e7685

Please sign in to comment.