-
Notifications
You must be signed in to change notification settings - Fork 11
Add route_request dispatch coverage #689
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
base: main
Are you sure you want to change the base?
Changes from all commits
b801e49
3f7d333
055ce1f
73887d8
56d29cf
372e0b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -621,6 +621,24 @@ fn route_buffered_response( | |
| route_result_to_fastly_response(settings, services, &partner_registry, route_result) | ||
| } | ||
|
|
||
| fn route_with_settings( | ||
| settings: &Settings, | ||
| req: Request, | ||
| expect_message: &str, | ||
| ) -> fastly::Response { | ||
| let (orchestrator, integration_registry) = build_route_stack(settings); | ||
| let services = test_runtime_services(&req); | ||
|
|
||
| route_buffered_response( | ||
| settings, | ||
| &orchestrator, | ||
| &integration_registry, | ||
| &services, | ||
| req, | ||
| expect_message, | ||
| ) | ||
| } | ||
|
|
||
| fn valid_banner_ad_unit_body() -> Vec<u8> { | ||
| serde_json::to_vec(&json!({ | ||
| "adUnits": [ | ||
|
|
@@ -637,6 +655,94 @@ fn valid_banner_ad_unit_body() -> Vec<u8> { | |
| .expect("should serialize valid auction route test body") | ||
| } | ||
|
|
||
| #[test] | ||
| fn static_tsjs_route_serves_unified_bundle() { | ||
| let settings = create_test_settings(); | ||
| let req = Request::get("https://test.com/static/tsjs=tsjs-unified.min.js"); | ||
|
|
||
| let mut response = route_with_settings(&settings, req, "should route static tsjs request"); | ||
|
|
||
| assert_eq!( | ||
| response.get_status(), | ||
| StatusCode::OK, | ||
| "should serve the unified static bundle" | ||
| ); | ||
| assert_eq!( | ||
| response.get_header_str(header::CONTENT_TYPE), | ||
| Some("application/javascript; charset=utf-8"), | ||
| "should serve the unified bundle as JavaScript" | ||
| ); | ||
| assert!( | ||
| response.take_body_str().contains("requestAds"), | ||
| "should serve unified bundle content with the core requestAds API" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn static_tsjs_route_returns_not_found_for_unknown_tsjs_bundle() { | ||
| let settings = create_test_settings(); | ||
| let req = Request::get("https://test.com/static/tsjs=tsjs-doesnotexist.min.js"); | ||
|
|
||
| let response = route_with_settings(&settings, req, "should route static tsjs request"); | ||
|
|
||
| assert_eq!( | ||
| response.get_status(), | ||
| StatusCode::NOT_FOUND, | ||
| "should let the static tsjs branch own unknown bundle paths" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn unknown_route_falls_back_to_publisher_proxy_path() { | ||
| let settings = create_test_settings(); | ||
| let (orchestrator, integration_registry) = build_route_stack(&settings); | ||
|
|
||
| let req = Request::get("https://test.com/articles/example"); | ||
| let http_client = Arc::new(RecordingHttpClient::new(StatusCode::BAD_GATEWAY)); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⛏ nitpick (optional, non-blocking) — Returning |
||
| let services = test_runtime_services_with_http_client( | ||
| &req, | ||
| Arc::new(FixedBackend), | ||
| Arc::clone(&http_client) as Arc<dyn PlatformHttpClient>, | ||
| ); | ||
|
|
||
| let response = route_buffered_response( | ||
| &settings, | ||
| &orchestrator, | ||
| &integration_registry, | ||
| &services, | ||
| req, | ||
| "should route publisher fallback", | ||
| ); | ||
|
|
||
| assert_eq!( | ||
| response.get_status(), | ||
| StatusCode::BAD_GATEWAY, | ||
| "should return the publisher origin response through fallback routing" | ||
| ); | ||
| let calls = http_client | ||
| .calls | ||
| .lock() | ||
| .expect("should lock recorded calls"); | ||
| assert_eq!( | ||
| calls.len(), | ||
| 1, | ||
| "should send exactly one publisher fallback request" | ||
| ); | ||
| assert_eq!( | ||
| calls[0].method, | ||
| Method::GET, | ||
| "should preserve the fallback request method" | ||
| ); | ||
| assert_eq!( | ||
| calls[0].backend_name, "https-origin.test-publisher.com", | ||
| "should dispatch to the publisher origin backend" | ||
| ); | ||
| assert_eq!( | ||
| calls[0].uri, "https://origin.test-publisher.com/articles/example", | ||
| "should send the fallback request to the publisher origin" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn routes_use_request_local_consent() { | ||
| let settings = create_test_settings(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.