diff --git a/Cargo.lock b/Cargo.lock index f195383..b014fbc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -374,7 +374,7 @@ checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" [[package]] name = "conformance-tests" version = "0.1.0" -source = "git+https://github.com/fermyon/conformance-tests?branch=main#e846bcebdaaccb317e46387de4dbbc2e39a7199d" +source = "git+https://github.com/fermyon/conformance-tests?rev=387b7f375df59e6254a7c29cf4a53507a9f46d32#387b7f375df59e6254a7c29cf4a53507a9f46d32" dependencies = [ "anyhow", "flate2", @@ -2604,7 +2604,7 @@ dependencies = [ [[package]] name = "test-environment" version = "0.1.0" -source = "git+https://github.com/fermyon/conformance-tests?branch=main#e846bcebdaaccb317e46387de4dbbc2e39a7199d" +source = "git+https://github.com/fermyon/conformance-tests?rev=387b7f375df59e6254a7c29cf4a53507a9f46d32#387b7f375df59e6254a7c29cf4a53507a9f46d32" dependencies = [ "anyhow", "fslock", diff --git a/conformance-tests/Cargo.toml b/conformance-tests/Cargo.toml index 8a95da3..a6ba1d9 100644 --- a/conformance-tests/Cargo.toml +++ b/conformance-tests/Cargo.toml @@ -5,8 +5,8 @@ edition = "2021" [dependencies] anyhow = "1.0" -conformance-tests = { git = "https://github.com/fermyon/conformance-tests", branch = "main" } -test-environment = { git = "https://github.com/fermyon/conformance-tests", branch = "main" } +conformance-tests = { git = "https://github.com/fermyon/conformance-tests", rev = "387b7f375df59e6254a7c29cf4a53507a9f46d32" } +test-environment = { git = "https://github.com/fermyon/conformance-tests", rev = "387b7f375df59e6254a7c29cf4a53507a9f46d32" } spin-test = { path = ".." } wasmtime = "22.0" wasmtime-wasi = "22.0" diff --git a/conformance-tests/src/main.rs b/conformance-tests/src/main.rs index 4e0a4ea..4f4bc25 100644 --- a/conformance-tests/src/main.rs +++ b/conformance-tests/src/main.rs @@ -7,7 +7,7 @@ use runtime::SpinTest; const HTTP_PORT: u16 = 1234; fn main() -> anyhow::Result<()> { - conformance_tests::run_tests(run_test) + conformance_tests::run_tests("v0.1.0", run_test) } fn run_test(test: conformance_tests::Test) -> Result<(), anyhow::Error> { diff --git a/crates/spin-test-virt/src/lib.rs b/crates/spin-test-virt/src/lib.rs index e440162..88fadd5 100644 --- a/crates/spin-test-virt/src/lib.rs +++ b/crates/spin-test-virt/src/lib.rs @@ -669,7 +669,7 @@ impl variables::Guest for Component { let name = key.as_str().to_owned(); let fut = resolver .as_ref() - .map_err(|e| e.clone())? + .map_err(|e| variables::Error::Other(e.to_string()))? .resolve(component_id.as_ref(), key); futures::executor::block_on(fut).map_err(|_| variables::Error::Undefined(name)) }) @@ -678,7 +678,7 @@ impl variables::Guest for Component { thread_local! { /// The global variable resolver. - static VARIABLE_RESOLVER: LazyCell> = LazyCell::new(|| { + static VARIABLE_RESOLVER: LazyCell> = LazyCell::new(|| { let variables = manifest::AppManifest::get() .variables .into_iter() @@ -689,8 +689,7 @@ thread_local! { }; (k.to_string(), v) }); - let mut resolver = spin_expressions::ProviderResolver::new(variables) - .map_err(|e| variables::Error::Other(e.to_string()))?; + let mut resolver = spin_expressions::ProviderResolver::new(variables)?; let component = manifest::AppManifest::get_component().expect("no component set"); let component_id = manifest::AppManifest::get_component_id().expect("no component id set"); resolver @@ -700,8 +699,7 @@ thread_local! { .variables .into_iter() .map(|(k, v)| (k.to_string(), v)), - ) - .unwrap(); + )?; resolver.add_provider(Box::new(UserGivenProvider)); Ok(resolver) diff --git a/crates/spin-test-virt/src/manifest.rs b/crates/spin-test-virt/src/manifest.rs index 7b9018e..3df30ea 100644 --- a/crates/spin-test-virt/src/manifest.rs +++ b/crates/spin-test-virt/src/manifest.rs @@ -1,16 +1,33 @@ -use std::sync::{OnceLock, RwLock}; +use std::{ + cell::LazyCell, + sync::{OnceLock, RwLock}, +}; + +use crate::VARIABLE_RESOLVER; /// The manifest for the current Spin app. pub struct AppManifest; +thread_local! { + /// A fully resolved and prepared resolver from the manifest. + static PREPARED_RESOLVER: LazyCell> = LazyCell::new(|| { + VARIABLE_RESOLVER.with(|resolver| { + let resolver = resolver.as_ref().map_err(|e| anyhow::anyhow!("{e}"))?.prepare(); + Ok(futures::executor::block_on(resolver)?) + }) + }); +} + impl AppManifest { /// Returns the allowed hosts configuration for the current component. pub fn allowed_hosts() -> anyhow::Result { let allowed_outbound_hosts = Self::get_component() .expect("internal error: component id not yet set") .normalized_allowed_outbound_hosts()?; - let resolver = spin_expressions::PreparedResolver::default(); - spin_outbound_networking::AllowedHostsConfig::parse(&allowed_outbound_hosts, &resolver) + PREPARED_RESOLVER.with(|resolver| { + let resolver = resolver.as_ref().map_err(|e| anyhow::anyhow!("{e}"))?; + spin_outbound_networking::AllowedHostsConfig::parse(&allowed_outbound_hosts, resolver) + }) } /// Returns whether the given URL is allowed by the manifest.