diff --git a/Cargo.lock b/Cargo.lock index 1ab5044..a0baca0 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#6e30479fda142cbe49763cba888e20c13383123f" +source = "git+https://github.com/fermyon/conformance-tests?branch=main#db0ee32a825561d35f884a246e1d390134d78823" dependencies = [ "anyhow", "flate2", @@ -2601,7 +2601,7 @@ dependencies = [ [[package]] name = "test-environment" version = "0.1.0" -source = "git+https://github.com/fermyon/conformance-tests?branch=main#6e30479fda142cbe49763cba888e20c13383123f" +source = "git+https://github.com/fermyon/conformance-tests?branch=main#db0ee32a825561d35f884a246e1d390134d78823" dependencies = [ "anyhow", "fslock", diff --git a/conformance-tests/src/main.rs b/conformance-tests/src/main.rs index c0718c2..1e0e764 100644 --- a/conformance-tests/src/main.rs +++ b/conformance-tests/src/main.rs @@ -30,6 +30,7 @@ fn run_test(test: conformance_tests::Test) -> Result<(), anyhow::Error> { conformance_tests::config::Precondition::TcpEcho => {} conformance_tests::config::Precondition::KeyValueStore(_) => {} conformance_tests::config::Precondition::Sqlite => {} + conformance_tests::config::Precondition::Redis => {} } } for invocation in test.config.invocations { @@ -47,8 +48,8 @@ fn run_test(test: conformance_tests::Test) -> Result<(), anyhow::Error> { /// When encountering a magic key-value pair, substitute the value with a different value. fn substitution(key: &str, value: &str) -> Option { match (key, value) { - ("port", "7") => Some(7.to_string()), ("port", "80") => Some(HTTP_PORT.to_string()), + ("port", port) => Some(port.to_owned()), _ => panic!("Unexpected substitution: {} = {}", key, value), } } diff --git a/crates/router/src/lib.rs b/crates/router/src/lib.rs index 06b7833..c621454 100644 --- a/crates/router/src/lib.rs +++ b/crates/router/src/lib.rs @@ -125,10 +125,7 @@ fn apply_request_transformations( let headers_to_add = calculate_default_headers(&request, base, route_match) .context("could not calculate default headers for request")? .into_iter() - .flat_map(|(k, v)| { - k.into_iter() - .map(move |s| (s.to_string(), v.clone().into_bytes())) - }) + .flat_map(|(k, v)| k.into_iter().map(move |s| (s, v.clone().into_bytes()))) .chain(request.headers().entries()); let headers = Headers::new(); for (key, value) in headers_to_add { diff --git a/crates/spin-test-virt/src/lib.rs b/crates/spin-test-virt/src/lib.rs index fcf7eba..a77fb77 100644 --- a/crates/spin-test-virt/src/lib.rs +++ b/crates/spin-test-virt/src/lib.rs @@ -364,11 +364,49 @@ impl redis::GuestConnection for RedisConnection { fn execute( &self, command: String, - arguments: Vec, + mut arguments: Vec, ) -> Result, redis::Error> { - let _ = (command, arguments); - // TODO: implement this by getting input from user - Err(redis::Error::Other("not yet implemented".into())) + let mut get_binary = || match arguments.pop().ok_or(redis::Error::TypeError)? { + redis::RedisParameter::Int64(_) => Err(redis::Error::TypeError), + redis::RedisParameter::Binary(b) => Ok(b), + }; + match command.as_str() { + "incr" => { + let key = get_binary()?; + let key = String::from_utf8(key).map_err(|_| redis::Error::TypeError)?; + self.incr(key).map(|i| vec![redis::RedisResult::Int64(i)]) + } + "set" => { + let value = get_binary()?; + let key = get_binary()?; + let key = String::from_utf8(key).map_err(|_| redis::Error::TypeError)?; + self.set(key, value); + Ok(vec![]) + } + "append" => { + let value = get_binary()?; + let key = get_binary()?; + let key = String::from_utf8(key).map_err(|_| redis::Error::TypeError)?; + let mut current = self.get(key.clone())?.unwrap_or_default(); + current.extend(value); + self.set(key, current); + Ok(vec![]) + } + "get" => { + let key = get_binary()?; + let key = String::from_utf8(key).map_err(|_| redis::Error::TypeError)?; + let value = self.get(key)?; + Ok(value + .map(|v| vec![redis::RedisResult::Binary(v)]) + .unwrap_or_default()) + } + _ => { + // TODO: implement this by getting input from user + Err(redis::Error::Other(format!( + "not able to execute '{command}' command" + ))) + } + } } } diff --git a/crates/spin-test-virt/src/wasi/http.rs b/crates/spin-test-virt/src/wasi/http.rs index a4a46ac..ae9744b 100644 --- a/crates/spin-test-virt/src/wasi/http.rs +++ b/crates/spin-test-virt/src/wasi/http.rs @@ -335,7 +335,7 @@ impl exports::types::GuestFields for Fields { ) -> Result { let mut fields: HashMap>> = HashMap::new(); for (k, v) in entries { - fields.entry(k).or_default().push(v); + fields.entry(k.to_lowercase()).or_default().push(v); } let fields = Fields { fields: RefCell::new(fields), @@ -346,7 +346,8 @@ impl exports::types::GuestFields for Fields { fn get(&self, name: exports::types::FieldKey) -> Vec { self.fields .borrow() - .get(&name) + // Downcase the key to make it case-insensitive + .get(&name.to_lowercase()) .map(Clone::clone) .unwrap_or_default() } @@ -375,7 +376,7 @@ impl exports::types::GuestFields for Fields { // TODO: check for mutability rules self.fields .borrow_mut() - .entry(name) + .entry(name.to_lowercase()) .or_default() .push(value); Ok(())