MCPcopy Create free account
hub / github.com/clawshell/clawshell / test_proxy_forwards_upstream_errors

Function test_proxy_forwards_upstream_errors

src/app/tests.rs:189–221  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

187
188#[tokio::test]
189async fn test_proxy_forwards_upstream_errors() {
190 let mock_server = MockServer::start().await;
191
192 Mock::given(method("POST"))
193 .and(path("/v1/chat/completions"))
194 .respond_with(ResponseTemplate::new(400).set_body_json(serde_json::json!({
195 "error": {"message": "Invalid model", "type": "invalid_request_error"}
196 })))
197 .mount(&mock_server)
198 .await;
199
200 let app = make_app(&mock_server.uri());
201 let body = r#"{"model":"nonexistent"}"#;
202 let req = Request::builder()
203 .method("POST")
204 .uri("/v1/chat/completions")
205 .header("authorization", "Bearer vk-test-1")
206 .header("content-type", "application/json")
207 .body(Body::from(body))
208 .unwrap();
209
210 let resp = app.oneshot(req).await.unwrap();
211 assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
212
213 let body = resp.into_body().collect().await.unwrap().to_bytes();
214 let json: serde_json::Value = serde_json::from_slice(&body).unwrap();
215 assert!(
216 json["error"]["message"]
217 .as_str()
218 .unwrap()
219 .contains("Invalid model")
220 );
221}
222
223#[tokio::test]
224async fn test_real_key_injected_correctly() {

Callers

nothing calls this directly

Calls 1

make_appFunction · 0.85

Tested by

no test coverage detected