Skip to content

Commit 837977c

Browse files
author
Michael-F-Bryan
committed
Added a test
1 parent 99417a2 commit 837977c

File tree

1 file changed

+85
-1
lines changed

1 file changed

+85
-1
lines changed

lib/wasix/src/runtime/resolver/wapm_source.rs

+85-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl WapmSource {
133133
impl Source for WapmSource {
134134
#[tracing::instrument(level = "debug", skip_all, fields(%package))]
135135
async fn query(&self, package: &PackageSpecifier) -> Result<Vec<PackageSummary>, QueryError> {
136-
let (full_name, version_constraint) = match package {
136+
let (package_name, version_constraint) = match package {
137137
PackageSpecifier::Registry { full_name, version } => (full_name, version),
138138
_ => return Err(QueryError::Unsupported),
139139
};
@@ -722,4 +722,88 @@ mod tests {
722722
assert_eq!(summaries.len(), 1);
723723
assert_eq!(summaries[0].pkg.version.to_string(), "3.12.1");
724724
}
725+
726+
#[tokio::test]
727+
async fn query_the_backend_again_if_cached_queries_dont_match() {
728+
let cached_value = serde_json::from_value(serde_json::json! {
729+
{
730+
"data": {
731+
"getPackage": {
732+
"packageName": "python",
733+
"namespace": "wasmer",
734+
"versions": [
735+
{
736+
"version": "3.12.0",
737+
"piritaManifest": "{\"package\": {\"wapm\": {\"name\": \"wasmer/python\", \"version\": \"3.12.0\", \"description\": \"Python\"}}}",
738+
"distribution": {
739+
"piritaDownloadUrl": "https://wasmer.io/wasmer/[email protected]",
740+
"piritaSha256Hash": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
741+
}
742+
},
743+
]
744+
},
745+
"info": {
746+
"defaultFrontend": "https://wasmer.io/",
747+
},
748+
}
749+
}
750+
}).unwrap();
751+
let body = serde_json::json! {
752+
{
753+
"data": {
754+
"getPackage": {
755+
"packageName": "python",
756+
"namespace": "wasmer",
757+
"versions": [
758+
{
759+
"version": "4.0.0",
760+
"piritaManifest": "{\"package\": {\"wapm\": {\"name\": \"wasmer/python\", \"version\": \"4.0.0\", \"description\": \"Python\"}}}",
761+
"distribution": {
762+
"piritaDownloadUrl": "https://wasmer.io/wasmer/[email protected]",
763+
"piritaSha256Hash": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
764+
}
765+
},
766+
{
767+
"version": "3.12.0",
768+
"piritaManifest": "{\"package\": {\"wapm\": {\"name\": \"wasmer/python\", \"version\": \"3.12.0\", \"description\": \"Python\"}}}",
769+
"distribution": {
770+
"piritaDownloadUrl": "https://wasmer.io/wasmer/[email protected]",
771+
"piritaSha256Hash": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
772+
}
773+
},
774+
]
775+
},
776+
"info": {
777+
"defaultFrontend": "https://wasmer.io/",
778+
},
779+
}
780+
}
781+
};
782+
let response = HttpResponse {
783+
body: Some(serde_json::to_vec(&body).unwrap()),
784+
redirected: false,
785+
status: StatusCode::OK,
786+
headers: HeaderMap::new(),
787+
};
788+
let client = Arc::new(DummyClient::new(vec![response]));
789+
let registry_endpoint = WapmSource::WASMER_PROD_ENDPOINT.parse().unwrap();
790+
let request = PackageSpecifier::Registry {
791+
full_name: "wasmer/python".to_string(),
792+
version: "4.0.0".parse().unwrap(),
793+
};
794+
let temp = tempfile::tempdir().unwrap();
795+
let source = WapmSource::new(registry_endpoint, client.clone())
796+
.with_local_cache(temp.path(), Duration::from_secs(0));
797+
source
798+
.cache
799+
.as_ref()
800+
.unwrap()
801+
.update("wasmer/python", &cached_value)
802+
.unwrap();
803+
804+
let summaries = source.query(&request).await.unwrap();
805+
806+
assert_eq!(summaries.len(), 1);
807+
assert_eq!(summaries[0].pkg.version.to_string(), "4.0.0");
808+
}
725809
}

0 commit comments

Comments
 (0)