Skip to content

Commit

Permalink
Use the versioned conformance tests.
Browse files Browse the repository at this point in the history
Also fix how variables are being interpolated in the allowed outbound
hosts.

Signed-off-by: Ryan Levick <[email protected]>
  • Loading branch information
rylev committed Aug 1, 2024
1 parent 9304231 commit 8311382
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions conformance-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion conformance-tests/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
10 changes: 4 additions & 6 deletions crates/spin-test-virt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
Expand All @@ -678,7 +678,7 @@ impl variables::Guest for Component {

thread_local! {
/// The global variable resolver.
static VARIABLE_RESOLVER: LazyCell<Result<spin_expressions::ProviderResolver, variables::Error>> = LazyCell::new(|| {
static VARIABLE_RESOLVER: LazyCell<Result<spin_expressions::ProviderResolver, spin_expressions::Error>> = LazyCell::new(|| {
let variables = manifest::AppManifest::get()
.variables
.into_iter()
Expand All @@ -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
Expand All @@ -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)

Expand Down
23 changes: 20 additions & 3 deletions crates/spin-test-virt/src/manifest.rs
Original file line number Diff line number Diff line change
@@ -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<anyhow::Result<spin_expressions::PreparedResolver>> = 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<spin_outbound_networking::AllowedHostsConfig> {
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.
Expand Down

0 comments on commit 8311382

Please sign in to comment.