Skip to content

Commit decf0cc

Browse files
committed
move test to loader
Signed-off-by: Aminu Oluwaseun Joshua <[email protected]>
1 parent ffc2b3f commit decf0cc

File tree

2 files changed

+46
-38
lines changed

2 files changed

+46
-38
lines changed

crates/factors-test/src/lib.rs

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -104,41 +104,3 @@ pub async fn build_locked_app(manifest: &toml::Table) -> anyhow::Result<LockedAp
104104
std::fs::write(&path, toml_str).context("failed writing manifest")?;
105105
spin_loader::from_file(&path, FilesMountStrategy::Direct, None).await
106106
}
107-
108-
#[cfg(test)]
109-
mod test {
110-
use std::collections::HashSet;
111-
112-
use spin_app::retain_components;
113-
114-
use super::*;
115-
116-
fn does_nothing_validator(_: &App, _: &[&str]) -> anyhow::Result<()> {
117-
Ok(())
118-
}
119-
120-
#[tokio::test]
121-
async fn test_retain_components_filtering_for_only_component_works() {
122-
let manifest = toml::toml! {
123-
spin_manifest_version = 2
124-
125-
[application]
126-
name = "test-app"
127-
128-
[[trigger.test-trigger]]
129-
component = "empty"
130-
131-
[component.empty]
132-
source = "does-not-exist.wasm"
133-
};
134-
let mut locked_app = build_locked_app(&manifest).await.unwrap();
135-
locked_app = retain_components(locked_app, &["empty"], &[&does_nothing_validator]).unwrap();
136-
let components = locked_app
137-
.components
138-
.iter()
139-
.map(|c| c.id.to_string())
140-
.collect::<HashSet<_>>();
141-
assert!(components.contains("empty"));
142-
assert!(components.len() == 1);
143-
}
144-
}

crates/loader/src/lib.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,49 @@ fn single_file_manifest(
9191

9292
Ok(manifest)
9393
}
94+
95+
#[cfg(test)]
96+
mod test {
97+
use std::collections::HashSet;
98+
99+
use spin_app::{retain_components, App};
100+
101+
use super::*;
102+
103+
pub async fn build_locked_app(manifest: &toml::Table) -> anyhow::Result<LockedApp> {
104+
let toml_str = toml::to_string(manifest).context("failed serializing manifest")?;
105+
let dir = tempfile::tempdir().context("failed creating tempdir")?;
106+
let path = dir.path().join("spin.toml");
107+
std::fs::write(&path, toml_str).context("failed writing manifest")?;
108+
from_file(&path, FilesMountStrategy::Direct, None).await
109+
}
110+
111+
fn does_nothing_validator(_: &App, _: &[&str]) -> anyhow::Result<()> {
112+
Ok(())
113+
}
114+
115+
#[tokio::test]
116+
async fn test_retain_components_filtering_for_only_component_works() {
117+
let manifest = toml::toml! {
118+
spin_manifest_version = 2
119+
120+
[application]
121+
name = "test-app"
122+
123+
[[trigger.test-trigger]]
124+
component = "empty"
125+
126+
[component.empty]
127+
source = "does-not-exist.wasm"
128+
};
129+
let mut locked_app = build_locked_app(&manifest).await.unwrap();
130+
locked_app = retain_components(locked_app, &["empty"], &[&does_nothing_validator]).unwrap();
131+
let components = locked_app
132+
.components
133+
.iter()
134+
.map(|c| c.id.to_string())
135+
.collect::<HashSet<_>>();
136+
assert!(components.contains("empty"));
137+
assert!(components.len() == 1);
138+
}
139+
}

0 commit comments

Comments
 (0)