summaryrefslogtreecommitdiff
path: root/test_util/src/servers/registry.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-12-14 17:52:12 +0100
committerGitHub <noreply@github.com>2023-12-14 16:52:12 +0000
commit8d269efbc2826955d853421a6d52cdcdcaf8e577 (patch)
treeb8de0b1bd5db7700170cac010ffe28c5853e69b1 /test_util/src/servers/registry.rs
parentac04787c30b67ba9c7fb800eae8361ba419e7f4e (diff)
refactor(test_util): move servers to a separate module (#21577)
This commit has no functional changes, just moves all the testing servers to "test_util::servers" module to make "test_util/src/lib.rs" shorter.
Diffstat (limited to 'test_util/src/servers/registry.rs')
-rw-r--r--test_util/src/servers/registry.rs54
1 files changed, 54 insertions, 0 deletions
diff --git a/test_util/src/servers/registry.rs b/test_util/src/servers/registry.rs
new file mode 100644
index 000000000..6bb2cf1fc
--- /dev/null
+++ b/test_util/src/servers/registry.rs
@@ -0,0 +1,54 @@
+// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+
+use hyper::server::Server;
+use hyper::service::make_service_fn;
+use hyper::service::service_fn;
+use hyper::Body;
+use hyper::Request;
+use hyper::Response;
+use hyper::StatusCode;
+use serde_json::json;
+use std::convert::Infallible;
+use std::net::SocketAddr;
+
+pub async fn registry_server(port: u16) {
+ let registry_server_addr = SocketAddr::from(([127, 0, 0, 1], port));
+ let registry_server_svc = make_service_fn(|_| async {
+ Ok::<_, Infallible>(service_fn(registry_server_handler))
+ });
+ let registry_server =
+ Server::bind(&registry_server_addr).serve(registry_server_svc);
+ if let Err(e) = registry_server.await {
+ eprintln!("Registry server error: {:?}", e);
+ }
+}
+
+async fn registry_server_handler(
+ req: Request<Body>,
+) -> Result<Response<Body>, hyper::http::Error> {
+ let path = req.uri().path();
+
+ if path.starts_with("/scopes/") {
+ let body = serde_json::to_string_pretty(&json!({
+ "id": "sdfwqer-sffg-qwerasdf",
+ "status": "success",
+ "error": null
+ }))
+ .unwrap();
+ let res = Response::new(Body::from(body));
+ return Ok(res);
+ } else if path.starts_with("/publish_status/") {
+ let body = serde_json::to_string_pretty(&json!({
+ "id": "sdfwqer-qwer-qwerasdf",
+ "status": "success",
+ "error": null
+ }))
+ .unwrap();
+ let res = Response::new(Body::from(body));
+ return Ok(res);
+ }
+
+ Response::builder()
+ .status(StatusCode::NOT_FOUND)
+ .body(Body::empty())
+}