Skip to content

Commit

Permalink
Update create KV namespace message and test (#5934)
Browse files Browse the repository at this point in the history
* Update create KV namespace message and test

* Fix failing tests in `./tools` (#5935)

Co-authored-by: Carmen Popoviciu <cpopoviciu@cloudflare.com>

* Update create KV namespace message and test

* Run prettify

* Run prettify again after update

* Update kv tests to match new message

* Fix create KV namespace output

* Update snapshot for KV tests

---------

Co-authored-by: Carmen Popoviciu <carmen.popoviciu@gmail.com>
Co-authored-by: Carmen Popoviciu <cpopoviciu@cloudflare.com>
  • Loading branch information
3 people authored Jun 5, 2024
1 parent b7b1d65 commit bac79fb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 26 deletions.
5 changes: 5 additions & 0 deletions .changeset/green-turtles-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

fix: Update create KV namespace binding details message for easier implementation
48 changes: 28 additions & 20 deletions packages/wrangler/src/__tests__/kv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,34 +118,40 @@ describe("wrangler", () => {
mockCreateRequest("worker-UnitTestNamespace");
await runWrangler("kv:namespace create UnitTestNamespace");
expect(std.out).toMatchInlineSnapshot(`
"🌀 Creating namespace with title \\"worker-UnitTestNamespace\\"
✨ Success!
Add the following to your configuration file in your kv_namespaces array:
{ binding = \\"UnitTestNamespace\\", id = \\"some-namespace-id\\" }"
`);
"🌀 Creating namespace with title \\"worker-UnitTestNamespace\\"
✨ Success!
Add the following to your configuration file in your kv_namespaces array:
[[kv_namespaces]]
binding = \\"UnitTestNamespace\\"
id = \\"some-namespace-id\\""
`);
});

it("should create a preview namespace if configured to do so", async () => {
mockCreateRequest("worker-UnitTestNamespace_preview");
await runWrangler("kv:namespace create UnitTestNamespace --preview");
expect(std.out).toMatchInlineSnapshot(`
"🌀 Creating namespace with title \\"worker-UnitTestNamespace_preview\\"
✨ Success!
Add the following to your configuration file in your kv_namespaces array:
{ binding = \\"UnitTestNamespace\\", preview_id = \\"some-namespace-id\\" }"
`);
"🌀 Creating namespace with title \\"worker-UnitTestNamespace_preview\\"
✨ Success!
Add the following to your configuration file in your kv_namespaces array:
[[kv_namespaces]]
binding = \\"UnitTestNamespace\\"
preview_id = \\"some-namespace-id\\""
`);
});

it("should create a namespace using configured worker name", async () => {
writeFileSync("./wrangler.toml", 'name = "other-worker"', "utf-8");
mockCreateRequest("other-worker-UnitTestNamespace");
await runWrangler("kv:namespace create UnitTestNamespace");
expect(std.out).toMatchInlineSnapshot(`
"🌀 Creating namespace with title \\"other-worker-UnitTestNamespace\\"
✨ Success!
Add the following to your configuration file in your kv_namespaces array:
{ binding = \\"UnitTestNamespace\\", id = \\"some-namespace-id\\" }"
`);
"🌀 Creating namespace with title \\"other-worker-UnitTestNamespace\\"
✨ Success!
Add the following to your configuration file in your kv_namespaces array:
[[kv_namespaces]]
binding = \\"UnitTestNamespace\\"
id = \\"some-namespace-id\\""
`);
});

it("should create a namespace in an environment if configured to do so", async () => {
Expand All @@ -154,11 +160,13 @@ describe("wrangler", () => {
"kv:namespace create UnitTestNamespace --env customEnv"
);
expect(std.out).toMatchInlineSnapshot(`
"🌀 Creating namespace with title \\"worker-customEnv-UnitTestNamespace\\"
✨ Success!
Add the following to your configuration file in your kv_namespaces array under [env.customEnv]:
{ binding = \\"UnitTestNamespace\\", id = \\"some-namespace-id\\" }"
`);
"🌀 Creating namespace with title \\"worker-customEnv-UnitTestNamespace\\"
✨ Success!
Add the following to your configuration file in your kv_namespaces array under [env.customEnv]:
[[kv_namespaces]]
binding = \\"UnitTestNamespace\\"
id = \\"some-namespace-id\\""
`);
});
});

Expand Down
9 changes: 3 additions & 6 deletions packages/wrangler/src/kv/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,9 @@ export function kvNamespace(kvYargs: CommonYargsArgv) {
logger.log(
`Add the following to your configuration file in your kv_namespaces array${envString}:`
);
logger.log(
`{ binding = "${getValidBindingName(
args.namespace,
"KV"
)}", ${previewString}id = "${namespaceId}" }`
);
logger.log(`[[kv_namespaces]]`);
logger.log(`binding = "${getValidBindingName(args.namespace, "KV")}"`);
logger.log(`${previewString}id = "${namespaceId}"`);

// TODO: automatically write this block to the wrangler.toml config file??
}
Expand Down

0 comments on commit bac79fb

Please sign in to comment.