Skip to content

Commit 1ae288d

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

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
@@ -94,3 +94,49 @@ fn single_file_manifest(
9494

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

0 commit comments

Comments
 (0)