Skip to content
This repository has been archived by the owner on Apr 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #11 from rossdylan/bump-wasm-bindgen
Browse files Browse the repository at this point in the history
chore: update wasm-bindgen to latest version
  • Loading branch information
zebp authored Mar 8, 2023
2 parents b1082de + 20e4856 commit c36cac4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ js-sys = "0.3.50"
serde = { version = "1.0.125", features = ["derive"] }
serde_json = "1.0.64"
thiserror = "1.0.29"
wasm-bindgen = "0.2.73"
wasm-bindgen = "0.2.84"
wasm-bindgen-futures = "0.4.23"
gloo-utils = { version = "0.1.5", features = ["serde"] }

Expand Down
2 changes: 1 addition & 1 deletion tests/worker_kv_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ default = ["console_error_panic_hook"]

[dependencies]
cfg-if = "0.1.2"
worker = "0.0.4"
worker = "0.0.13"
worker-kv = { path = "../../" }
serde_json = "1.0.67"

Expand Down
21 changes: 9 additions & 12 deletions tests/worker_kv_test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ macro_rules! kv_assert_eq {
}

#[event(fetch)]
pub async fn main(req: Request, env: Env) -> Result<Response> {
pub async fn main(req: Request, env: Env, _ctx: Context) -> Result<Response> {
// Optionally, get more helpful error messages written to the console in the case of a panic.
utils::set_panic_hook();

// Create the KV store directly from `worker_kv` as the rust worker sdk uses a published version.
let store = KvStore::from_this(&env, "test").expect("test kv store not bound");

Router::new(store)
Router::with_data(store)
.get_async("/get", |req, ctx| wrap(req, ctx, get))
.get_async("/get-not-found", |req, ctx| wrap(req, ctx, get_not_found))
.get_async("/list-keys", |req, ctx| wrap(req, ctx, list_keys))
Expand All @@ -39,7 +39,7 @@ pub async fn main(req: Request, env: Env) -> Result<Response> {
}

async fn get(_: Request, ctx: RouteContext<KvStore>) -> TestResult {
let store = ctx.data().unwrap();
let store = ctx.data;
store
.get("simple")
.text()
Expand All @@ -52,7 +52,7 @@ async fn get(_: Request, ctx: RouteContext<KvStore>) -> TestResult {
}

async fn get_not_found(_: Request, ctx: RouteContext<KvStore>) -> TestResult {
let store = ctx.data().unwrap();
let store = ctx.data;
let value = store.get("not_found").text().await;

value.map_err(TestError::from).and_then(|v| match v {
Expand All @@ -62,7 +62,7 @@ async fn get_not_found(_: Request, ctx: RouteContext<KvStore>) -> TestResult {
}

async fn list_keys(_: Request, ctx: RouteContext<KvStore>) -> TestResult {
let store = ctx.data().unwrap();
let store = ctx.data;
let list_res = store.list().execute().await?;

// TODO: Test cursor and things.
Expand All @@ -72,7 +72,7 @@ async fn list_keys(_: Request, ctx: RouteContext<KvStore>) -> TestResult {
}

async fn put_simple(_: Request, ctx: RouteContext<KvStore>) -> TestResult {
let store = ctx.data().unwrap();
let store = ctx.data;
store.put("put_a", "test")?.execute().await?;

let val = store.get("put_a").text().await?.unwrap();
Expand All @@ -82,13 +82,10 @@ async fn put_simple(_: Request, ctx: RouteContext<KvStore>) -> TestResult {
}

async fn put_metadata(_: Request, ctx: RouteContext<KvStore>) -> TestResult {
let store = ctx.data().unwrap();
let store = ctx.data;
store.put("put_b", "test")?.metadata(100)?.execute().await?;

let (val, meta) = store
.get("put_b")
.text_with_metadata::<usize>()
.await?;
let (val, meta) = store.get("put_b").text_with_metadata::<usize>().await?;
kv_assert_eq!(val.unwrap(), "test")?;
kv_assert_eq!(meta.unwrap(), 100)?;

Expand All @@ -97,7 +94,7 @@ async fn put_metadata(_: Request, ctx: RouteContext<KvStore>) -> TestResult {

async fn put_expiration(_: Request, ctx: RouteContext<KvStore>) -> TestResult {
const EXPIRATION: u64 = 2000000000;
let store = ctx.data().unwrap();
let store = ctx.data;
store
.put("put_c", "test")?
.expiration(EXPIRATION)
Expand Down

0 comments on commit c36cac4

Please sign in to comment.