From 99453385f60db4618d07280595c56284ec9f651b Mon Sep 17 00:00:00 2001 From: Zeb Piasecki Date: Thu, 17 Nov 2022 10:17:20 -0500 Subject: [PATCH] chore: add integration testing for service bindings Adds integration testing for service bindings by creating a new worker in the worker-sandbox directory and mounting it with Miniflare. --- worker-sandbox/remote-service/package.json | 3 +++ worker-sandbox/remote-service/service.js | 3 +++ worker-sandbox/remote-service/wrangler.toml | 2 ++ worker-sandbox/src/lib.rs | 11 +++++++++++ worker-sandbox/tests/requests.rs | 9 +++++++++ worker-sandbox/wrangler.toml | 7 +++++++ worker/src/fetcher.rs | 8 ++++---- worker/src/router.rs | 2 +- 8 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 worker-sandbox/remote-service/package.json create mode 100644 worker-sandbox/remote-service/service.js create mode 100644 worker-sandbox/remote-service/wrangler.toml diff --git a/worker-sandbox/remote-service/package.json b/worker-sandbox/remote-service/package.json new file mode 100644 index 00000000..8f5067aa --- /dev/null +++ b/worker-sandbox/remote-service/package.json @@ -0,0 +1,3 @@ +{ + "main": "./service.js" +} diff --git a/worker-sandbox/remote-service/service.js b/worker-sandbox/remote-service/service.js new file mode 100644 index 00000000..27d56bf8 --- /dev/null +++ b/worker-sandbox/remote-service/service.js @@ -0,0 +1,3 @@ +addEventListener('fetch', event => { + event.respondWith(new Response('hello world')) +}) diff --git a/worker-sandbox/remote-service/wrangler.toml b/worker-sandbox/remote-service/wrangler.toml new file mode 100644 index 00000000..19e9f373 --- /dev/null +++ b/worker-sandbox/remote-service/wrangler.toml @@ -0,0 +1,2 @@ +name = "remote-service" +type = "javascript" diff --git a/worker-sandbox/src/lib.rs b/worker-sandbox/src/lib.rs index 4781d04e..2d57b69b 100644 --- a/worker-sandbox/src/lib.rs +++ b/worker-sandbox/src/lib.rs @@ -646,6 +646,17 @@ pub async fn main(req: Request, env: Env, _ctx: worker::Context) -> Result, + url: impl Into, init: Option, ) -> Result { - let path = path.into(); + let path = url.into(); let promise = match init { Some(ref init) => self.0.fetch_with_str_and_init(&path, &init.into()), None => self.0.fetch_with_str(&path), diff --git a/worker/src/router.rs b/worker/src/router.rs index a38a8322..8eca726d 100644 --- a/worker/src/router.rs +++ b/worker/src/router.rs @@ -10,7 +10,7 @@ use crate::{ http::Method, request::Request, response::Response, - Result, Fetcher, + Fetcher, Result, }; type HandlerFn = fn(Request, RouteContext) -> Result;