Skip to content

Commit

Permalink
--local by default for wrangler kv & wrangler r2 (#7392)
Browse files Browse the repository at this point in the history
  • Loading branch information
penalosa authored Dec 6, 2024
1 parent ec4cdee commit 4d92e0b
Show file tree
Hide file tree
Showing 9 changed files with 340 additions and 194 deletions.
5 changes: 5 additions & 0 deletions .changeset/funny-pets-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": major
---

Use `--local` by default for KV & R2
7 changes: 3 additions & 4 deletions packages/wrangler/e2e/dev-with-resources.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,7 @@ describe.sequential.each(RUNTIMES)("Core: $flags", ({ runtime, flags }) => {

describe.sequential.each(RUNTIMES)("Bindings: $flags", ({ runtime, flags }) => {
const isLocal = runtime === "local";
const resourceFlags = isLocal ? "--local" : "";
const d1ResourceFlags = isLocal ? "" : "--remote";
const resourceFlags = isLocal ? "" : "--remote";

let helper: WranglerE2ETestHelper;
beforeEach(() => {
Expand Down Expand Up @@ -478,7 +477,7 @@ describe.sequential.each(RUNTIMES)("Bindings: $flags", ({ runtime, flags }) => {
});

const result = await helper.run(
`wrangler d1 execute ${d1ResourceFlags} DB --file schema.sql`
`wrangler d1 execute ${resourceFlags} DB --file schema.sql`
);
// D1 defaults to `--local`, so we deliberately use `flags`, not `resourceFlags`
const worker = helper.runLongLived(`wrangler dev ${flags}`);
Expand All @@ -490,7 +489,7 @@ describe.sequential.each(RUNTIMES)("Bindings: $flags", ({ runtime, flags }) => {
}

const result2 = await helper.run(
`wrangler d1 execute ${d1ResourceFlags} DB --command "SELECT * FROM entries WHERE key = 'key2'"`
`wrangler d1 execute ${resourceFlags} DB --command "SELECT * FROM entries WHERE key = 'key2'"`
);
expect(result2.stdout).toContain("value2");
if (isLocal) {
Expand Down
10 changes: 5 additions & 5 deletions packages/wrangler/e2e/r2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe("r2", () => {
"test-r2.txt": fileContents,
});
const output = await helper.run(
`wrangler r2 object put ${bucketName}/testr2 --file test-r2.txt --content-type text/html`
`wrangler r2 object put ${bucketName}/testr2 --file test-r2.txt --content-type text/html --remote`
);
expect(normalize(output.stdout)).toMatchInlineSnapshot(`
"Creating object "testr2" in bucket "tmp-e2e-r2-00000000-0000-0000-0000-000000000000".
Expand All @@ -49,7 +49,7 @@ describe("r2", () => {

it("download object", async () => {
const output = await helper.run(
`wrangler r2 object get ${bucketName}/testr2 --file test-r2o.txt`
`wrangler r2 object get ${bucketName}/testr2 --file test-r2o.txt --remote`
);
expect(normalize(output.stdout)).toMatchInlineSnapshot(`
"Downloading "testr2" from "tmp-e2e-r2-00000000-0000-0000-0000-000000000000".
Expand All @@ -64,7 +64,7 @@ describe("r2", () => {

it("delete object", async () => {
const output = await helper.run(
`wrangler r2 object delete ${bucketName}/testr2`
`wrangler r2 object delete ${bucketName}/testr2 --remote`
);
expect(normalize(output.stdout)).toMatchInlineSnapshot(`
"Deleting object "testr2" from bucket "tmp-e2e-r2-00000000-0000-0000-0000-000000000000".
Expand All @@ -74,7 +74,7 @@ describe("r2", () => {

it("check object deleted", async () => {
const output = await helper.run(
`wrangler r2 object get ${bucketName}/testr2 --file test-r2o.txt`
`wrangler r2 object get ${bucketName}/testr2 --file test-r2o.txt --remote`
);
expect(output.stderr).toContain("The specified key does not exist");
});
Expand All @@ -92,7 +92,7 @@ describe("r2", () => {
"test-r2.txt": fileContents,
});
const output = await helper.run(
`wrangler r2 object put ${bucketName}/testr2 --file test-r2.txt --content-type text/html`
`wrangler r2 object put ${bucketName}/testr2 --file test-r2.txt --content-type text/html --remote`
);
expect(output.stderr).toContain("The specified bucket does not exist");
});
Expand Down
52 changes: 25 additions & 27 deletions packages/wrangler/src/__tests__/kv.local.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ describe("wrangler", () => {
describe("local", () => {
it("should put local kv storage", async () => {
await runWrangler(
`kv key get val --namespace-id some-namespace-id --local --text`
`kv key get val --namespace-id some-namespace-id --text`
);
expect(std.out).toMatchInlineSnapshot(`"Value not found"`);

await runWrangler(
`kv key put val value --namespace-id some-namespace-id --local`
`kv key put val value --namespace-id some-namespace-id `
);
expect(std.out).toMatchInlineSnapshot(`
"Value not found
Writing the value \\"value\\" to key \\"val\\" on namespace some-namespace-id."
`);

await runWrangler(
`kv key get val --namespace-id some-namespace-id --local --text`
`kv key get val --namespace-id some-namespace-id --text`
);
expect(std.out).toMatchInlineSnapshot(`
"Value not found
Expand All @@ -36,7 +36,7 @@ describe("wrangler", () => {
});

it("should list local kv storage", async () => {
await runWrangler(`kv key list --namespace-id some-namespace-id --local`);
await runWrangler(`kv key list --namespace-id some-namespace-id`);
expect(std.out).toMatchInlineSnapshot(`"[]"`);
const keyValues = [
{
Expand All @@ -58,10 +58,10 @@ describe("wrangler", () => {
];
writeFileSync("./keys.json", JSON.stringify(keyValues));
await runWrangler(
`kv bulk put keys.json --namespace-id some-namespace-id --local`
`kv bulk put keys.json --namespace-id some-namespace-id`
);

await runWrangler(`kv key list --namespace-id some-namespace-id --local`);
await runWrangler(`kv key list --namespace-id some-namespace-id`);
expect(std.out).toMatchInlineSnapshot(`
"[]
Success!
Expand All @@ -82,13 +82,13 @@ describe("wrangler", () => {
`);

await runWrangler(
`kv key list --namespace-id some-namespace-id --local --prefix a`
`kv key list --namespace-id some-namespace-id --prefix a`
);
await runWrangler(
`kv key list --namespace-id some-namespace-id --local --prefix a/b`
`kv key list --namespace-id some-namespace-id --prefix a/b`
);
await runWrangler(
`kv key list --namespace-id some-namespace-id --local --prefix abc`
`kv key list --namespace-id some-namespace-id --prefix abc`
);

expect(std.out).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -130,26 +130,24 @@ describe("wrangler", () => {

it("should delete local kv storage", async () => {
await runWrangler(
`kv key put val value --namespace-id some-namespace-id --local`
`kv key put val value --namespace-id some-namespace-id`
);
await runWrangler(
`kv key get val --namespace-id some-namespace-id --local --text`
`kv key get val --namespace-id some-namespace-id --text`
);
expect(std.out).toMatchInlineSnapshot(`
"Writing the value \\"value\\" to key \\"val\\" on namespace some-namespace-id.
value"
`);
await runWrangler(
`kv key delete val --namespace-id some-namespace-id --local`
);
await runWrangler(`kv key delete val --namespace-id some-namespace-id`);
expect(std.out).toMatchInlineSnapshot(`
"Writing the value \\"value\\" to key \\"val\\" on namespace some-namespace-id.
value
Deleting the key \\"val\\" on namespace some-namespace-id."
`);

await runWrangler(
`kv key get val --namespace-id some-namespace-id --local --text`
`kv key get val --namespace-id some-namespace-id --text`
);
expect(std.out).toMatchInlineSnapshot(`
"Writing the value \\"value\\" to key \\"val\\" on namespace some-namespace-id.
Expand All @@ -160,7 +158,7 @@ describe("wrangler", () => {
});

it("should put local bulk kv storage", async () => {
await runWrangler(`kv key list --namespace-id bulk-namespace-id --local`);
await runWrangler(`kv key list --namespace-id bulk-namespace-id`);
expect(std.out).toMatchInlineSnapshot(`"[]"`);

const keyValues = [
Expand All @@ -175,23 +173,23 @@ describe("wrangler", () => {
];
writeFileSync("./keys.json", JSON.stringify(keyValues));
await runWrangler(
`kv bulk put keys.json --namespace-id bulk-namespace-id --local`
`kv bulk put keys.json --namespace-id bulk-namespace-id`
);
expect(std.out).toMatchInlineSnapshot(`
"[]
Success!"
`);

await runWrangler(
`kv key get test --namespace-id bulk-namespace-id --local --text`
`kv key get test --namespace-id bulk-namespace-id --text`
);
expect(std.out).toMatchInlineSnapshot(`
"[]
Success!
value"
`);

await runWrangler(`kv key list --namespace-id bulk-namespace-id --local`);
await runWrangler(`kv key list --namespace-id bulk-namespace-id`);
expect(std.out).toMatchInlineSnapshot(`
"[]
Success!
Expand Down Expand Up @@ -220,9 +218,9 @@ describe("wrangler", () => {
];
writeFileSync("./keys.json", JSON.stringify(keyValues));
await runWrangler(
`kv bulk put keys.json --namespace-id bulk-namespace-id --local`
`kv bulk put keys.json --namespace-id bulk-namespace-id`
);
await runWrangler(`kv key list --namespace-id bulk-namespace-id --local`);
await runWrangler(`kv key list --namespace-id bulk-namespace-id`);
expect(std.out).toMatchInlineSnapshot(`
"Success!
[
Expand All @@ -237,7 +235,7 @@ describe("wrangler", () => {
const keys = ["hello", "test"];
writeFileSync("./keys.json", JSON.stringify(keys));
await runWrangler(
`kv bulk delete keys.json --namespace-id bulk-namespace-id --local --force`
`kv bulk delete keys.json --namespace-id bulk-namespace-id --force`
);
expect(std.out).toMatchInlineSnapshot(`
"Success!
Expand All @@ -252,7 +250,7 @@ describe("wrangler", () => {
Success!"
`);

await runWrangler(`kv key list --namespace-id bulk-namespace-id --local`);
await runWrangler(`kv key list --namespace-id bulk-namespace-id`);
expect(std.out).toMatchInlineSnapshot(`
"Success!
[
Expand All @@ -270,19 +268,19 @@ describe("wrangler", () => {

it("should follow persist-to for local kv storage", async () => {
await runWrangler(
`kv key put val value --namespace-id some-namespace-id --local`
`kv key put val value --namespace-id some-namespace-id`
);

await runWrangler(
`kv key put val persistValue --namespace-id some-namespace-id --local --persist-to ./persistdir`
`kv key put val persistValue --namespace-id some-namespace-id --persist-to ./persistdir`
);
expect(std.out).toMatchInlineSnapshot(`
"Writing the value \\"value\\" to key \\"val\\" on namespace some-namespace-id.
Writing the value \\"persistValue\\" to key \\"val\\" on namespace some-namespace-id."
`);

await runWrangler(
`kv key get val --namespace-id some-namespace-id --local --text`
`kv key get val --namespace-id some-namespace-id --text`
);
expect(std.out).toMatchInlineSnapshot(`
"Writing the value \\"value\\" to key \\"val\\" on namespace some-namespace-id.
Expand All @@ -291,7 +289,7 @@ describe("wrangler", () => {
`);

await runWrangler(
`kv key get val --namespace-id some-namespace-id --local --text --persist-to ./persistdir`
`kv key get val --namespace-id some-namespace-id --text --persist-to ./persistdir`
);
expect(std.out).toMatchInlineSnapshot(`
"Writing the value \\"value\\" to key \\"val\\" on namespace some-namespace-id.
Expand Down
Loading

0 comments on commit 4d92e0b

Please sign in to comment.