Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to conformance test for key-value #95

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

13 changes: 9 additions & 4 deletions conformance-tests/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn main() -> anyhow::Result<()> {
for test in conformance_tests::tests(&tests_dir)? {
println!("Test: {}", test.name);
let mut manifest =
test_environment::manifest_template::EnvTemplate::from_file(&test.manifest).unwrap();
test_environment::manifest_template::EnvTemplate::from_file(&test.manifest)?;
let env_config = test_environment::TestEnvironmentConfig {
create_runtime: Box::new(|_env| {
manifest.substitute_value("port", |port| {
Expand All @@ -24,9 +24,14 @@ fn main() -> anyhow::Result<()> {
services_config: test_environment::services::ServicesConfig::none(),
};
let mut env = test_environment::TestEnvironment::up(env_config, |_| Ok(())).unwrap();
if test.config.services.iter().any(|s| s == "http-echo") {
env.runtime_mut()
.set_echo_response(format!("http://localhost:{HTTP_PORT}").as_str())?;
for precondition in &test.config.preconditions {
match precondition {
conformance_tests::config::Precondition::HttpEcho => {
env.runtime_mut()
.set_echo_response(format!("http://localhost:{HTTP_PORT}").as_str())?;
}
conformance_tests::config::Precondition::KeyValueStore(_) => {}
}
}
for invocation in test.config.invocations {
let conformance_tests::config::Invocation::Http(mut invocation) = invocation;
Expand Down
11 changes: 8 additions & 3 deletions crates/router/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,10 @@ fn calculate_default_headers(
base: &str,
route_match: &RouteMatch,
) -> anyhow::Result<Vec<([String; 2], String)>> {
fn convert(s: &str) -> String {
s.to_owned().replace('_', "-").to_ascii_lowercase()
}
fn owned(strs: &[&'static str; 2]) -> [String; 2] {
let convert = |s: &str| s.to_owned().replace('_', "-").to_ascii_lowercase();
[convert(strs[0]), convert(strs[1])]
}

Expand Down Expand Up @@ -205,8 +207,11 @@ fn calculate_default_headers(
res.push((owned_client_addr, "127.0.0.1:0".to_owned()));

for (wild_name, wild_value) in route_match.named_wildcards() {
let wild_header = format!("SPIN_PATH_MATCH_{}", wild_name.to_ascii_uppercase());
let wild_wagi_header = format!("X_PATH_MATCH_{}", wild_name.to_ascii_uppercase());
let wild_header = convert(&format!(
"SPIN_PATH_MATCH_{}",
wild_name.to_ascii_uppercase()
));
let wild_wagi_header = convert(&format!("X_PATH_MATCH_{}", wild_name.to_ascii_uppercase()));
res.push(([wild_header, wild_wagi_header], wild_value.clone()));
}

Expand Down