-
-
Notifications
You must be signed in to change notification settings - Fork 944
test(vfox): replace flaky external HTTP tests with local mock server #6354
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
Changes from all commits
7012e75
3d91cc1
f97d821
4d65bf2
4c4fe3d
6de7ccc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -75,14 +75,34 @@ fn get_headers(lua: &Lua, headers: &reqwest::header::HeaderMap) -> Result<Table> | |||||
| mod tests { | ||||||
| use super::*; | ||||||
| use std::fs; | ||||||
| use wiremock::matchers::{method, path}; | ||||||
| use wiremock::{Mock, MockServer, ResponseTemplate}; | ||||||
|
|
||||||
| #[tokio::test] | ||||||
| async fn test_get() { | ||||||
| // Start a local mock server | ||||||
| let server = MockServer::start().await; | ||||||
|
|
||||||
| // Create a mock endpoint | ||||||
| Mock::given(method("GET")) | ||||||
| .and(path("/get")) | ||||||
| .respond_with( | ||||||
| ResponseTemplate::new(200) | ||||||
| .set_body_json(serde_json::json!({ | ||||||
| "message": "test response" | ||||||
| })) | ||||||
| .insert_header("content-type", "application/json"), | ||||||
| ) | ||||||
| .mount(&server) | ||||||
| .await; | ||||||
|
|
||||||
| let lua = Lua::new(); | ||||||
| mod_http(&lua).unwrap(); | ||||||
|
|
||||||
| let url = server.uri() + "/get"; | ||||||
| lua.load(mlua::chunk! { | ||||||
| local http = require("http") | ||||||
| local resp = http.get({ url = "https://httpbin.org/get" }) | ||||||
| local resp = http.get({ url = $url }) | ||||||
| assert(resp.status_code == 200) | ||||||
| assert(type(resp.body) == "string") | ||||||
| }) | ||||||
|
|
@@ -93,15 +113,29 @@ mod tests { | |||||
|
|
||||||
| #[tokio::test] | ||||||
| async fn test_head() { | ||||||
| let server = MockServer::start().await; | ||||||
|
|
||||||
| Mock::given(method("HEAD")) | ||||||
| .and(path("/get")) | ||||||
| .respond_with( | ||||||
| ResponseTemplate::new(200) | ||||||
| .insert_header("content-type", "application/json") | ||||||
| .insert_header("x-test-header", "test-value"), | ||||||
| ) | ||||||
| .mount(&server) | ||||||
| .await; | ||||||
|
|
||||||
| let lua = Lua::new(); | ||||||
| mod_http(&lua).unwrap(); | ||||||
|
|
||||||
| let url = server.uri() + "/get"; | ||||||
|
||||||
| let url = server.uri() + "/get"; | |
| let url = format!("{}/get", server.uri()); |
Copilot
AI
Sep 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String concatenation using + creates temporary String allocations. Consider using format! macro for better performance: format!(\"{}/index.json\", server.uri())
| let url = server.uri() + "/index.json"; | |
| let url = format!("{}/index.json", server.uri()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String concatenation using
+creates temporary String allocations. Consider usingformat!macro for better performance:format!(\"{}/get\", server.uri())