Skip to content

Commit 4396ca4

Browse files
authored
Merge pull request #115 from fermyon/versioned-conformance
Use the versioned conformance tests.
2 parents 9304231 + 8311382 commit 4396ca4

File tree

5 files changed

+29
-14
lines changed

5 files changed

+29
-14
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

conformance-tests/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ edition = "2021"
55

66
[dependencies]
77
anyhow = "1.0"
8-
conformance-tests = { git = "https://github.com/fermyon/conformance-tests", branch = "main" }
9-
test-environment = { git = "https://github.com/fermyon/conformance-tests", branch = "main" }
8+
conformance-tests = { git = "https://github.com/fermyon/conformance-tests", rev = "387b7f375df59e6254a7c29cf4a53507a9f46d32" }
9+
test-environment = { git = "https://github.com/fermyon/conformance-tests", rev = "387b7f375df59e6254a7c29cf4a53507a9f46d32" }
1010
spin-test = { path = ".." }
1111
wasmtime = "22.0"
1212
wasmtime-wasi = "22.0"

conformance-tests/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use runtime::SpinTest;
77
const HTTP_PORT: u16 = 1234;
88

99
fn main() -> anyhow::Result<()> {
10-
conformance_tests::run_tests(run_test)
10+
conformance_tests::run_tests("v0.1.0", run_test)
1111
}
1212

1313
fn run_test(test: conformance_tests::Test) -> Result<(), anyhow::Error> {

crates/spin-test-virt/src/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ impl variables::Guest for Component {
669669
let name = key.as_str().to_owned();
670670
let fut = resolver
671671
.as_ref()
672-
.map_err(|e| e.clone())?
672+
.map_err(|e| variables::Error::Other(e.to_string()))?
673673
.resolve(component_id.as_ref(), key);
674674
futures::executor::block_on(fut).map_err(|_| variables::Error::Undefined(name))
675675
})
@@ -678,7 +678,7 @@ impl variables::Guest for Component {
678678

679679
thread_local! {
680680
/// The global variable resolver.
681-
static VARIABLE_RESOLVER: LazyCell<Result<spin_expressions::ProviderResolver, variables::Error>> = LazyCell::new(|| {
681+
static VARIABLE_RESOLVER: LazyCell<Result<spin_expressions::ProviderResolver, spin_expressions::Error>> = LazyCell::new(|| {
682682
let variables = manifest::AppManifest::get()
683683
.variables
684684
.into_iter()
@@ -689,8 +689,7 @@ thread_local! {
689689
};
690690
(k.to_string(), v)
691691
});
692-
let mut resolver = spin_expressions::ProviderResolver::new(variables)
693-
.map_err(|e| variables::Error::Other(e.to_string()))?;
692+
let mut resolver = spin_expressions::ProviderResolver::new(variables)?;
694693
let component = manifest::AppManifest::get_component().expect("no component set");
695694
let component_id = manifest::AppManifest::get_component_id().expect("no component id set");
696695
resolver
@@ -700,8 +699,7 @@ thread_local! {
700699
.variables
701700
.into_iter()
702701
.map(|(k, v)| (k.to_string(), v)),
703-
)
704-
.unwrap();
702+
)?;
705703
resolver.add_provider(Box::new(UserGivenProvider));
706704
Ok(resolver)
707705

crates/spin-test-virt/src/manifest.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,33 @@
1-
use std::sync::{OnceLock, RwLock};
1+
use std::{
2+
cell::LazyCell,
3+
sync::{OnceLock, RwLock},
4+
};
5+
6+
use crate::VARIABLE_RESOLVER;
27

38
/// The manifest for the current Spin app.
49
pub struct AppManifest;
510

11+
thread_local! {
12+
/// A fully resolved and prepared resolver from the manifest.
13+
static PREPARED_RESOLVER: LazyCell<anyhow::Result<spin_expressions::PreparedResolver>> = LazyCell::new(|| {
14+
VARIABLE_RESOLVER.with(|resolver| {
15+
let resolver = resolver.as_ref().map_err(|e| anyhow::anyhow!("{e}"))?.prepare();
16+
Ok(futures::executor::block_on(resolver)?)
17+
})
18+
});
19+
}
20+
621
impl AppManifest {
722
/// Returns the allowed hosts configuration for the current component.
823
pub fn allowed_hosts() -> anyhow::Result<spin_outbound_networking::AllowedHostsConfig> {
924
let allowed_outbound_hosts = Self::get_component()
1025
.expect("internal error: component id not yet set")
1126
.normalized_allowed_outbound_hosts()?;
12-
let resolver = spin_expressions::PreparedResolver::default();
13-
spin_outbound_networking::AllowedHostsConfig::parse(&allowed_outbound_hosts, &resolver)
27+
PREPARED_RESOLVER.with(|resolver| {
28+
let resolver = resolver.as_ref().map_err(|e| anyhow::anyhow!("{e}"))?;
29+
spin_outbound_networking::AllowedHostsConfig::parse(&allowed_outbound_hosts, resolver)
30+
})
1431
}
1532

1633
/// Returns whether the given URL is allowed by the manifest.

0 commit comments

Comments
 (0)