Skip to content
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

Added remaining routes and fixed tests #473

Merged
merged 25 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3de8494
Added test script to package.json.
spigaz Mar 8, 2024
757bcd5
Added worker-sandbox r2 routes.
spigaz Mar 8, 2024
367af94
Added worker-build to the npm test script.
spigaz Mar 8, 2024
d35f20b
Added worker-sandbox r2 routes - cleanup.
spigaz Mar 8, 2024
847bb15
Added worker-sandbox queue routes.
spigaz Mar 8, 2024
3392238
Added worker-sandbox service-bindings routes - implied porting and ad…
spigaz Mar 8, 2024
e488c9f
Added worker-sandbox service-bindings routes - implied porting and ad…
spigaz Mar 8, 2024
22f2997
Added worker-sandbox cache stream route - Implied porting some more r…
spigaz Mar 9, 2024
2be670e
Added worker-sandbox remaining cache routes.
spigaz Mar 9, 2024
7dadcee
Added worker-sandbox init called route.
spigaz Mar 9, 2024
6076eb2
Added worker-sandbox custom-response-body route.
spigaz Mar 9, 2024
42edfa0
Added worker-sandbox now route.
spigaz Mar 9, 2024
4e8b0dd
Added worker-sandbox redirect-307 route.
spigaz Mar 9, 2024
15e2955
Added worker-sandbox redirect-default route.
spigaz Mar 9, 2024
5960f0a
Added worker-sandbox subrequests routes and fetch helpers that were r…
spigaz Mar 9, 2024
f759c8d
Added worker-sandbox subrequests fetch-timeout to be shorter.
spigaz Mar 9, 2024
d451c62
Added worker-sandbox request catchall fixed test case.
spigaz Mar 9, 2024
7135ce3
Added worker-sandbox request xor route.
spigaz Mar 9, 2024
9a7769f
Added worker-sandbox request xor route.
spigaz Mar 9, 2024
591f9c1
Added worker-sandbox websocket route.
spigaz Mar 9, 2024
f11e41c
worker-sandbox queue routes clean up.
spigaz Mar 9, 2024
1e46bcf
worker unused dependencies clean up.
spigaz Mar 9, 2024
4579e7a
worker-sandbox: Added missing d1 routes and improved d1 tests to use …
spigaz Mar 10, 2024
0d8d4da
worker-sandbox: Clippy.
spigaz Mar 10, 2024
124ea82
worker-sandbox: fmt.
spigaz Mar 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
"vitest": "^0.32.0"
},
"scripts": {
"test": ""
"test": "cd worker-sandbox && worker-build --dev && vitest"
}
}
9 changes: 6 additions & 3 deletions worker-sandbox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ default = ["console_error_panic_hook"]

[dependencies]
blake2 = "0.10.6"
bytes = "1.4.0"
chrono = { version = "0.4.26", default-features = false, features = [
"wasmbind",
"clock",
Expand All @@ -26,19 +27,21 @@ http = "0.2.9"
regex = "1.8.4"
serde = { version = "1.0.164", features = ["derive"] }
serde_json = "1.0.96"
worker = { path = "../worker", version = "0.0.17", features= ["queue", "d1"] }
worker = { path = "../worker", version = "0.0.17", features = ["queue", "d1"] }
futures-channel = "0.3.28"
futures-util = { version = "0.3.28", default-features = false }
rand = "0.8.5"
uuid = {version = "1.3.3", features = ["v4", "serde"]}
uuid = { version = "1.3.3", features = ["v4", "serde"] }
serde-wasm-bindgen = "0.5.0"
md5 = "0.7.0"
router-service = { git = "https://github.com/zebp/router-service", version = "0.1.0" }
tower = "0.4.13"

[dev-dependencies]
futures-channel = { version = "0.3.28", features = ["sink"] }
futures-util = { version = "0.3.28", default-features = false, features = ["sink"] }
futures-util = { version = "0.3.28", default-features = false, features = [
"sink",
] }
reqwest = { version = "0.11.18", features = [
"blocking",
"json",
Expand Down
18 changes: 9 additions & 9 deletions worker-sandbox/src/d1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ struct Person {
age: u32,
}

pub async fn prepared_statement(
_req: http::Request<Body>,
env: Env,
) -> Result<http::Response<Body>> {
pub async fn prepared_statement(env: &Env) -> Result<http::Response<Body>> {
let db = env.d1("DB")?;
let stmt = worker::query!(&db, "SELECT * FROM people WHERE name = ?", "Ryan Upton")?;

Expand Down Expand Up @@ -47,7 +44,7 @@ pub async fn prepared_statement(
Ok(http::Response::new("ok".into()))
}

pub async fn batch(_req: http::Request<Body>, env: Env) -> Result<http::Response<Body>> {
pub async fn batch(env: &Env) -> Result<http::Response<Body>> {
let db = env.d1("DB")?;
let mut results = db
.batch(vec![
Expand All @@ -71,7 +68,7 @@ pub async fn batch(_req: http::Request<Body>, env: Env) -> Result<http::Response
Ok(http::Response::new("ok".into()))
}

pub async fn exec(req: http::Request<Body>, env: Env) -> Result<http::Response<Body>> {
pub async fn exec(req: http::Request<Body>, env: &Env) -> Result<http::Response<Body>> {
let db = env.d1("DB")?;

let result = db
Expand All @@ -84,21 +81,24 @@ pub async fn exec(req: http::Request<Body>, env: Env) -> Result<http::Response<B
))
}

pub async fn dump(_req: http::Request<Body>, env: Env) -> Result<http::Response<Body>> {
pub async fn dump(env: &Env) -> Result<http::Response<Body>> {
let db = env.d1("DB")?;
let bytes = db.dump().await?;
Ok(http::Response::new(bytes.into()))
}

pub async fn error(_req: http::Request<Body>, env: Env) -> Result<http::Response<Body>> {
pub async fn error(env: &Env) -> Result<http::Response<Body>> {
let db = env.d1("DB")?;
let error = db
.exec("THIS IS NOT VALID SQL")
.await
.expect_err("did not get error");

if let Error::D1(error) = error {
assert_eq!(error.cause(), "Error in line 1: THIS IS NOT VALID SQL: ERROR 9009: SQL prepare error: near \"THIS\": syntax error in THIS IS NOT VALID SQL at offset 0")
assert_eq!(
error.cause(),
"Error in line 1: THIS IS NOT VALID SQL: SqliteError: near \"THIS\": syntax error"
)
} else {
panic!("expected D1 error");
}
Expand Down
Loading
Loading