wrangler 0.0.13 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/wrangler.js +2 -2
- package/package.json +20 -11
- package/pages/functions/buildWorker.ts +1 -1
- package/pages/functions/filepath-routing.test.ts +112 -28
- package/pages/functions/filepath-routing.ts +44 -51
- package/pages/functions/routes.ts +11 -18
- package/pages/functions/template-worker.ts +3 -9
- package/src/__tests__/dev.test.tsx +42 -5
- package/src/__tests__/guess-worker-format.test.ts +66 -0
- package/src/__tests__/{clipboardy-mock.js → helpers/clipboardy-mock.js} +0 -0
- package/src/__tests__/helpers/cmd-shim.d.ts +11 -0
- package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
- package/src/__tests__/helpers/mock-account-id.ts +30 -0
- package/src/__tests__/helpers/mock-bin.ts +36 -0
- package/src/__tests__/{mock-cfetch.ts → helpers/mock-cfetch.ts} +43 -9
- package/src/__tests__/helpers/mock-console.ts +62 -0
- package/src/__tests__/{mock-dialogs.ts → helpers/mock-dialogs.ts} +1 -1
- package/src/__tests__/helpers/mock-kv.ts +40 -0
- package/src/__tests__/helpers/mock-user.ts +27 -0
- package/src/__tests__/helpers/mock-web-socket.ts +37 -0
- package/src/__tests__/{run-in-tmp.ts → helpers/run-in-tmp.ts} +1 -1
- package/src/__tests__/helpers/run-wrangler.ts +16 -0
- package/src/__tests__/helpers/write-wrangler-toml.ts +20 -0
- package/src/__tests__/index.test.ts +418 -71
- package/src/__tests__/jest.setup.ts +30 -2
- package/src/__tests__/kv.test.ts +147 -252
- package/src/__tests__/logout.test.ts +50 -0
- package/src/__tests__/package-manager.test.ts +206 -0
- package/src/__tests__/publish.test.ts +1136 -291
- package/src/__tests__/r2.test.ts +206 -0
- package/src/__tests__/secret.test.ts +210 -0
- package/src/__tests__/sentry.test.ts +146 -0
- package/src/__tests__/tail.test.ts +246 -0
- package/src/__tests__/whoami.test.tsx +6 -47
- package/src/api/form_data.ts +75 -25
- package/src/api/preview.ts +2 -2
- package/src/api/worker.ts +34 -15
- package/src/bundle.ts +127 -0
- package/src/cfetch/index.ts +7 -15
- package/src/cfetch/internal.ts +41 -6
- package/src/cli.ts +10 -0
- package/src/config.ts +125 -95
- package/src/dev.tsx +300 -193
- package/src/dialogs.tsx +2 -2
- package/src/guess-worker-format.ts +68 -0
- package/src/index.tsx +578 -192
- package/src/inspect.ts +29 -10
- package/src/kv.tsx +23 -17
- package/src/module-collection.ts +32 -12
- package/src/open-in-browser.ts +13 -0
- package/src/package-manager.ts +120 -0
- package/src/pages.tsx +28 -23
- package/src/paths.ts +26 -0
- package/src/proxy.ts +88 -14
- package/src/publish.ts +260 -297
- package/src/r2.ts +50 -0
- package/src/reporting.ts +115 -0
- package/src/sites.tsx +28 -27
- package/src/tail.tsx +178 -9
- package/src/user.tsx +58 -44
- package/templates/new-worker.js +15 -0
- package/templates/new-worker.ts +15 -0
- package/{static-asset-facade.js → templates/static-asset-facade.js} +0 -0
- package/wrangler-dist/cli.js +124315 -104677
- package/wrangler-dist/cli.js.map +3 -3
- package/src/__tests__/mock-console.ts +0 -34
- package/src/__tests__/run-wrangler.ts +0 -8
package/src/__tests__/kv.test.ts
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import { writeFileSync } from "fs";
|
|
2
|
-
import
|
|
1
|
+
import { writeFileSync } from "node:fs";
|
|
2
|
+
import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
|
|
3
3
|
import {
|
|
4
4
|
setMockResponse,
|
|
5
|
-
setMockRawResponse,
|
|
6
5
|
unsetAllMocks,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
6
|
+
unsetMockFetchKVGetValues,
|
|
7
|
+
setMockFetchKVGetValue,
|
|
8
|
+
} from "./helpers/mock-cfetch";
|
|
9
|
+
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
10
|
+
import { mockKeyListRequest } from "./helpers/mock-kv";
|
|
11
|
+
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
12
|
+
import { runWrangler } from "./helpers/run-wrangler";
|
|
13
|
+
import type { KVNamespaceInfo, NamespaceKeyInfo } from "../kv";
|
|
12
14
|
|
|
13
15
|
describe("wrangler", () => {
|
|
16
|
+
mockAccountId();
|
|
17
|
+
mockApiToken();
|
|
14
18
|
runInTempDir();
|
|
15
19
|
const std = mockConsoleMethods();
|
|
16
20
|
|
|
@@ -34,12 +38,11 @@ describe("wrangler", () => {
|
|
|
34
38
|
}
|
|
35
39
|
|
|
36
40
|
it("should error if no namespace is given", async () => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
41
|
+
await expect(
|
|
42
|
+
runWrangler("kv:namespace create")
|
|
43
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
44
|
+
`"Not enough non-option arguments: got 0, need at least 1"`
|
|
45
|
+
);
|
|
43
46
|
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
44
47
|
expect(std.err).toMatchInlineSnapshot(`
|
|
45
48
|
"wrangler kv:namespace create <namespace>
|
|
@@ -61,18 +64,14 @@ describe("wrangler", () => {
|
|
|
61
64
|
|
|
62
65
|
Not enough non-option arguments: got 0, need at least 1"
|
|
63
66
|
`);
|
|
64
|
-
expect(error).toMatchInlineSnapshot(
|
|
65
|
-
`[Error: Not enough non-option arguments: got 0, need at least 1]`
|
|
66
|
-
);
|
|
67
67
|
});
|
|
68
68
|
|
|
69
69
|
it("should error if the namespace to create contains spaces", async () => {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
70
|
+
await expect(
|
|
71
|
+
runWrangler("kv:namespace create abc def ghi")
|
|
72
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
73
|
+
`"Unexpected additional positional arguments \\"def ghi\\"."`
|
|
74
|
+
);
|
|
76
75
|
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
77
76
|
expect(std.err).toMatchInlineSnapshot(`
|
|
78
77
|
"wrangler kv:namespace create <namespace>
|
|
@@ -94,18 +93,14 @@ describe("wrangler", () => {
|
|
|
94
93
|
|
|
95
94
|
Unexpected additional positional arguments \\"def ghi\\"."
|
|
96
95
|
`);
|
|
97
|
-
expect(error).toMatchInlineSnapshot(
|
|
98
|
-
`[Error: Unexpected additional positional arguments "def ghi".]`
|
|
99
|
-
);
|
|
100
96
|
});
|
|
101
97
|
|
|
102
98
|
it("should error if the namespace to create is not valid", async () => {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
99
|
+
await expect(
|
|
100
|
+
runWrangler("kv:namespace create abc-def")
|
|
101
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
102
|
+
`"The namespace binding name \\"abc-def\\" is invalid. It can only have alphanumeric and _ characters, and cannot begin with a number."`
|
|
103
|
+
);
|
|
109
104
|
|
|
110
105
|
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
111
106
|
expect(std.err).toMatchInlineSnapshot(`
|
|
@@ -128,9 +123,6 @@ describe("wrangler", () => {
|
|
|
128
123
|
|
|
129
124
|
The namespace binding name \\"abc-def\\" is invalid. It can only have alphanumeric and _ characters, and cannot begin with a number."
|
|
130
125
|
`);
|
|
131
|
-
expect(error).toMatchInlineSnapshot(
|
|
132
|
-
`[Error: The namespace binding name "abc-def" is invalid. It can only have alphanumeric and _ characters, and cannot begin with a number.]`
|
|
133
|
-
);
|
|
134
126
|
});
|
|
135
127
|
|
|
136
128
|
it("should create a namespace", async () => {
|
|
@@ -273,16 +265,11 @@ describe("wrangler", () => {
|
|
|
273
265
|
|
|
274
266
|
it("should error if a given binding name is not in the configured kv namespaces", async () => {
|
|
275
267
|
writeWranglerConfig();
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
}
|
|
282
|
-
expect(error).toMatchInlineSnapshot(`
|
|
283
|
-
[Error: Not able to delete namespace.
|
|
284
|
-
A namespace with binding name "otherBinding" was not found in the configured "kv_namespaces".]
|
|
285
|
-
`);
|
|
268
|
+
await expect(runWrangler("kv:namespace delete --binding otherBinding"))
|
|
269
|
+
.rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
270
|
+
"Not able to delete namespace.
|
|
271
|
+
A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."
|
|
272
|
+
`);
|
|
286
273
|
expect(std.err).toMatchInlineSnapshot(`
|
|
287
274
|
"wrangler kv:namespace delete
|
|
288
275
|
|
|
@@ -422,21 +409,14 @@ describe("wrangler", () => {
|
|
|
422
409
|
10,
|
|
423
410
|
20
|
|
424
411
|
);
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
"kv:key put my-key my-value --namespace-id some-namespace-id --expiration 10 --ttl 20"
|
|
429
|
-
);
|
|
430
|
-
} catch (e) {
|
|
431
|
-
error = e;
|
|
432
|
-
}
|
|
433
|
-
|
|
412
|
+
await runWrangler(
|
|
413
|
+
"kv:key put my-key my-value --namespace-id some-namespace-id --expiration 10 --ttl 20"
|
|
414
|
+
);
|
|
434
415
|
expect(requests.count).toEqual(1);
|
|
435
416
|
expect(std.out).toMatchInlineSnapshot(
|
|
436
417
|
`"writing the value \\"my-value\\" to key \\"my-key\\" on namespace some-namespace-id"`
|
|
437
418
|
);
|
|
438
419
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
439
|
-
expect(error).toMatchInlineSnapshot(`undefined`);
|
|
440
420
|
});
|
|
441
421
|
|
|
442
422
|
it("should put a key to the specified environment in a given namespace", async () => {
|
|
@@ -474,12 +454,11 @@ describe("wrangler", () => {
|
|
|
474
454
|
});
|
|
475
455
|
|
|
476
456
|
it("should error if no key is provided", async () => {
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
}
|
|
457
|
+
await expect(
|
|
458
|
+
runWrangler("kv:key put")
|
|
459
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
460
|
+
`"Not enough non-option arguments: got 0, need at least 1"`
|
|
461
|
+
);
|
|
483
462
|
|
|
484
463
|
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
485
464
|
expect(std.err).toMatchInlineSnapshot(`
|
|
@@ -508,18 +487,14 @@ describe("wrangler", () => {
|
|
|
508
487
|
|
|
509
488
|
Not enough non-option arguments: got 0, need at least 1"
|
|
510
489
|
`);
|
|
511
|
-
expect(error).toMatchInlineSnapshot(
|
|
512
|
-
`[Error: Not enough non-option arguments: got 0, need at least 1]`
|
|
513
|
-
);
|
|
514
490
|
});
|
|
515
491
|
|
|
516
492
|
it("should error if no binding nor namespace is provided", async () => {
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
}
|
|
493
|
+
await expect(
|
|
494
|
+
runWrangler("kv:key put foo bar")
|
|
495
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
496
|
+
`"Exactly one of the arguments binding and namespace-id is required"`
|
|
497
|
+
);
|
|
523
498
|
|
|
524
499
|
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
525
500
|
expect(std.err).toMatchInlineSnapshot(`
|
|
@@ -548,18 +523,14 @@ describe("wrangler", () => {
|
|
|
548
523
|
|
|
549
524
|
Exactly one of the arguments binding and namespace-id is required"
|
|
550
525
|
`);
|
|
551
|
-
expect(error).toMatchInlineSnapshot(
|
|
552
|
-
`[Error: Exactly one of the arguments binding and namespace-id is required]`
|
|
553
|
-
);
|
|
554
526
|
});
|
|
555
527
|
|
|
556
528
|
it("should error if both binding and namespace is provided", async () => {
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
}
|
|
529
|
+
await expect(
|
|
530
|
+
runWrangler("kv:key put foo bar --binding x --namespace-id y")
|
|
531
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
532
|
+
`"Arguments binding and namespace-id are mutually exclusive"`
|
|
533
|
+
);
|
|
563
534
|
|
|
564
535
|
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
565
536
|
expect(std.err).toMatchInlineSnapshot(`
|
|
@@ -588,18 +559,14 @@ describe("wrangler", () => {
|
|
|
588
559
|
|
|
589
560
|
Arguments binding and namespace-id are mutually exclusive"
|
|
590
561
|
`);
|
|
591
|
-
expect(error).toMatchInlineSnapshot(
|
|
592
|
-
`[Error: Arguments binding and namespace-id are mutually exclusive]`
|
|
593
|
-
);
|
|
594
562
|
});
|
|
595
563
|
|
|
596
564
|
it("should error if no value nor path is provided", async () => {
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
}
|
|
565
|
+
await expect(
|
|
566
|
+
runWrangler("kv:key put key --namespace-id 12345")
|
|
567
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
568
|
+
`"Exactly one of the arguments value and path is required"`
|
|
569
|
+
);
|
|
603
570
|
|
|
604
571
|
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
605
572
|
expect(std.err).toMatchInlineSnapshot(`
|
|
@@ -628,20 +595,14 @@ describe("wrangler", () => {
|
|
|
628
595
|
|
|
629
596
|
Exactly one of the arguments value and path is required"
|
|
630
597
|
`);
|
|
631
|
-
expect(error).toMatchInlineSnapshot(
|
|
632
|
-
`[Error: Exactly one of the arguments value and path is required]`
|
|
633
|
-
);
|
|
634
598
|
});
|
|
635
599
|
|
|
636
600
|
it("should error if both value and path is provided", async () => {
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
} catch (e) {
|
|
643
|
-
error = e;
|
|
644
|
-
}
|
|
601
|
+
await expect(
|
|
602
|
+
runWrangler("kv:key put key value --path xyz --namespace-id 12345")
|
|
603
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
604
|
+
`"Arguments value and path are mutually exclusive"`
|
|
605
|
+
);
|
|
645
606
|
|
|
646
607
|
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
647
608
|
expect(std.err).toMatchInlineSnapshot(`
|
|
@@ -670,19 +631,15 @@ describe("wrangler", () => {
|
|
|
670
631
|
|
|
671
632
|
Arguments value and path are mutually exclusive"
|
|
672
633
|
`);
|
|
673
|
-
expect(error).toMatchInlineSnapshot(
|
|
674
|
-
`[Error: Arguments value and path are mutually exclusive]`
|
|
675
|
-
);
|
|
676
634
|
});
|
|
677
635
|
|
|
678
636
|
it("should error if a given binding name is not in the configured kv namespaces", async () => {
|
|
679
637
|
writeWranglerConfig();
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
}
|
|
638
|
+
await expect(
|
|
639
|
+
runWrangler("kv:key put key value --binding otherBinding")
|
|
640
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
641
|
+
`"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."`
|
|
642
|
+
);
|
|
686
643
|
|
|
687
644
|
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
688
645
|
expect(std.err).toMatchInlineSnapshot(`
|
|
@@ -691,9 +648,6 @@ describe("wrangler", () => {
|
|
|
691
648
|
[32m%s[0m
|
|
692
649
|
If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
693
650
|
`);
|
|
694
|
-
expect(error).toMatchInlineSnapshot(
|
|
695
|
-
`[Error: A namespace with binding name "otherBinding" was not found in the configured "kv_namespaces".]`
|
|
696
|
-
);
|
|
697
651
|
});
|
|
698
652
|
|
|
699
653
|
it("should error if a given binding has both preview and non-preview and --preview is not specified", async () => {
|
|
@@ -703,12 +657,11 @@ describe("wrangler", () => {
|
|
|
703
657
|
"my-key",
|
|
704
658
|
"my-value"
|
|
705
659
|
);
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
}
|
|
660
|
+
await expect(
|
|
661
|
+
runWrangler("kv:key put my-key my-value --binding someBinding")
|
|
662
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
663
|
+
`"someBinding has both a namespace ID and a preview ID. Specify \\"--preview\\" or \\"--preview false\\" to avoid writing data to the wrong namespace."`
|
|
664
|
+
);
|
|
712
665
|
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
713
666
|
expect(std.err).toMatchInlineSnapshot(`
|
|
714
667
|
"someBinding has both a namespace ID and a preview ID. Specify \\"--preview\\" or \\"--preview false\\" to avoid writing data to the wrong namespace.
|
|
@@ -716,9 +669,6 @@ describe("wrangler", () => {
|
|
|
716
669
|
[32m%s[0m
|
|
717
670
|
If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
718
671
|
`);
|
|
719
|
-
expect(error).toMatchInlineSnapshot(
|
|
720
|
-
`[Error: someBinding has both a namespace ID and a preview ID. Specify "--preview" or "--preview false" to avoid writing data to the wrong namespace.]`
|
|
721
|
-
);
|
|
722
672
|
expect(requests.count).toEqual(0);
|
|
723
673
|
});
|
|
724
674
|
});
|
|
@@ -863,32 +813,46 @@ describe("wrangler", () => {
|
|
|
863
813
|
`);
|
|
864
814
|
});
|
|
865
815
|
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
"
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
816
|
+
// We'll run the next test with variations on the cursor
|
|
817
|
+
// that's returned on cloudflare's API after all results
|
|
818
|
+
// have been drained.
|
|
819
|
+
for (const blankCursorValue of [undefined, null, ""] as [
|
|
820
|
+
undefined,
|
|
821
|
+
null,
|
|
822
|
+
""
|
|
823
|
+
]) {
|
|
824
|
+
describe(`cursor - ${blankCursorValue}`, () => {
|
|
825
|
+
it("should make multiple requests for paginated results", async () => {
|
|
826
|
+
// Create a lot of mock keys, so that the fetch requests will be paginated
|
|
827
|
+
const keys: string[] = [];
|
|
828
|
+
for (let i = 0; i < 550; i++) {
|
|
829
|
+
keys.push("key-" + i);
|
|
830
|
+
}
|
|
831
|
+
// Ask for the keys in pages of size 100.
|
|
832
|
+
const requests = mockKeyListRequest(
|
|
833
|
+
"some-namespace-id",
|
|
834
|
+
keys,
|
|
835
|
+
100,
|
|
836
|
+
blankCursorValue
|
|
837
|
+
);
|
|
838
|
+
await runWrangler(
|
|
839
|
+
"kv:key list --namespace-id some-namespace-id --limit 100"
|
|
840
|
+
);
|
|
841
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
842
|
+
expect(
|
|
843
|
+
JSON.parse(std.out).map((k: NamespaceKeyInfo) => k.name)
|
|
844
|
+
).toEqual(keys);
|
|
845
|
+
expect(requests.count).toEqual(6);
|
|
846
|
+
});
|
|
847
|
+
});
|
|
848
|
+
}
|
|
881
849
|
|
|
882
850
|
it("should error if a given binding name is not in the configured kv namespaces", async () => {
|
|
883
851
|
writeWranglerConfig();
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
error = e;
|
|
889
|
-
}
|
|
890
|
-
expect(error).toMatchInlineSnapshot(
|
|
891
|
-
`[Error: A namespace with binding name "otherBinding" was not found in the configured "kv_namespaces".]`
|
|
852
|
+
await expect(
|
|
853
|
+
runWrangler("kv:key list --binding otherBinding")
|
|
854
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
855
|
+
`"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."`
|
|
892
856
|
);
|
|
893
857
|
expect(std.err).toMatchInlineSnapshot(`
|
|
894
858
|
"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
|
|
@@ -901,27 +865,13 @@ describe("wrangler", () => {
|
|
|
901
865
|
});
|
|
902
866
|
|
|
903
867
|
describe("get", () => {
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
expectedValue: string
|
|
908
|
-
) {
|
|
909
|
-
const requests = { count: 0 };
|
|
910
|
-
setMockRawResponse(
|
|
911
|
-
"/accounts/:accountId/storage/kv/namespaces/:namespaceId/values/:key",
|
|
912
|
-
([_url, accountId, namespaceId, key]) => {
|
|
913
|
-
requests.count++;
|
|
914
|
-
expect(accountId).toEqual("some-account-id");
|
|
915
|
-
expect(namespaceId).toEqual(expectedNamespaceId);
|
|
916
|
-
expect(key).toEqual(expectedKey);
|
|
917
|
-
return expectedValue;
|
|
918
|
-
}
|
|
919
|
-
);
|
|
920
|
-
return requests;
|
|
921
|
-
}
|
|
868
|
+
afterEach(() => {
|
|
869
|
+
unsetMockFetchKVGetValues();
|
|
870
|
+
});
|
|
922
871
|
|
|
923
872
|
it("should get a key in a given namespace specified by namespace-id", async () => {
|
|
924
|
-
|
|
873
|
+
setMockFetchKVGetValue(
|
|
874
|
+
"some-account-id",
|
|
925
875
|
"some-namespace-id",
|
|
926
876
|
"my-key",
|
|
927
877
|
"my-value"
|
|
@@ -929,23 +879,27 @@ describe("wrangler", () => {
|
|
|
929
879
|
await runWrangler("kv:key get my-key --namespace-id some-namespace-id");
|
|
930
880
|
expect(std.out).toMatchInlineSnapshot(`"my-value"`);
|
|
931
881
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
932
|
-
expect(requests.count).toEqual(1);
|
|
933
882
|
});
|
|
934
883
|
|
|
935
884
|
it("should get a key in a given namespace specified by binding", async () => {
|
|
936
885
|
writeWranglerConfig();
|
|
937
|
-
|
|
886
|
+
setMockFetchKVGetValue(
|
|
887
|
+
"some-account-id",
|
|
888
|
+
"bound-id",
|
|
889
|
+
"my-key",
|
|
890
|
+
"my-value"
|
|
891
|
+
);
|
|
938
892
|
await runWrangler(
|
|
939
893
|
"kv:key get my-key --binding someBinding --preview false"
|
|
940
894
|
);
|
|
941
895
|
expect(std.out).toMatchInlineSnapshot(`"my-value"`);
|
|
942
896
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
943
|
-
expect(requests.count).toEqual(1);
|
|
944
897
|
});
|
|
945
898
|
|
|
946
899
|
it("should get a key in a given preview namespace specified by binding", async () => {
|
|
947
900
|
writeWranglerConfig();
|
|
948
|
-
|
|
901
|
+
setMockFetchKVGetValue(
|
|
902
|
+
"some-account-id",
|
|
949
903
|
"preview-bound-id",
|
|
950
904
|
"my-key",
|
|
951
905
|
"my-value"
|
|
@@ -953,12 +907,12 @@ describe("wrangler", () => {
|
|
|
953
907
|
await runWrangler("kv:key get my-key --binding someBinding --preview");
|
|
954
908
|
expect(std.out).toMatchInlineSnapshot(`"my-value"`);
|
|
955
909
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
956
|
-
expect(requests.count).toEqual(1);
|
|
957
910
|
});
|
|
958
911
|
|
|
959
912
|
it("should get a key for the specified environment in a given namespace", async () => {
|
|
960
913
|
writeWranglerConfig();
|
|
961
|
-
|
|
914
|
+
setMockFetchKVGetValue(
|
|
915
|
+
"some-account-id",
|
|
962
916
|
"env-bound-id",
|
|
963
917
|
"my-key",
|
|
964
918
|
"my-value"
|
|
@@ -968,16 +922,14 @@ describe("wrangler", () => {
|
|
|
968
922
|
);
|
|
969
923
|
expect(std.out).toMatchInlineSnapshot(`"my-value"`);
|
|
970
924
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
971
|
-
expect(requests.count).toEqual(1);
|
|
972
925
|
});
|
|
973
926
|
|
|
974
927
|
it("should error if no key is provided", async () => {
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
}
|
|
928
|
+
await expect(
|
|
929
|
+
runWrangler("kv:key get")
|
|
930
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
931
|
+
`"Not enough non-option arguments: got 0, need at least 1"`
|
|
932
|
+
);
|
|
981
933
|
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
982
934
|
expect(std.err).toMatchInlineSnapshot(`
|
|
983
935
|
"wrangler kv:key get <key>
|
|
@@ -1001,18 +953,14 @@ describe("wrangler", () => {
|
|
|
1001
953
|
|
|
1002
954
|
Not enough non-option arguments: got 0, need at least 1"
|
|
1003
955
|
`);
|
|
1004
|
-
expect(error).toMatchInlineSnapshot(
|
|
1005
|
-
`[Error: Not enough non-option arguments: got 0, need at least 1]`
|
|
1006
|
-
);
|
|
1007
956
|
});
|
|
1008
957
|
|
|
1009
958
|
it("should error if no binding nor namespace is provided", async () => {
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
}
|
|
959
|
+
await expect(
|
|
960
|
+
runWrangler("kv:key get foo")
|
|
961
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
962
|
+
`"Exactly one of the arguments binding and namespace-id is required"`
|
|
963
|
+
);
|
|
1016
964
|
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
1017
965
|
expect(std.err).toMatchInlineSnapshot(`
|
|
1018
966
|
"wrangler kv:key get <key>
|
|
@@ -1036,18 +984,14 @@ describe("wrangler", () => {
|
|
|
1036
984
|
|
|
1037
985
|
Exactly one of the arguments binding and namespace-id is required"
|
|
1038
986
|
`);
|
|
1039
|
-
expect(error).toMatchInlineSnapshot(
|
|
1040
|
-
`[Error: Exactly one of the arguments binding and namespace-id is required]`
|
|
1041
|
-
);
|
|
1042
987
|
});
|
|
1043
988
|
|
|
1044
989
|
it("should error if both binding and namespace is provided", async () => {
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
}
|
|
990
|
+
await expect(
|
|
991
|
+
runWrangler("kv:key get foo --binding x --namespace-id y")
|
|
992
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
993
|
+
`"Arguments binding and namespace-id are mutually exclusive"`
|
|
994
|
+
);
|
|
1051
995
|
|
|
1052
996
|
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
1053
997
|
expect(std.err).toMatchInlineSnapshot(`
|
|
@@ -1072,19 +1016,15 @@ describe("wrangler", () => {
|
|
|
1072
1016
|
|
|
1073
1017
|
Arguments binding and namespace-id are mutually exclusive"
|
|
1074
1018
|
`);
|
|
1075
|
-
expect(error).toMatchInlineSnapshot(
|
|
1076
|
-
`[Error: Arguments binding and namespace-id are mutually exclusive]`
|
|
1077
|
-
);
|
|
1078
1019
|
});
|
|
1079
1020
|
|
|
1080
1021
|
it("should error if a given binding name is not in the configured kv namespaces", async () => {
|
|
1081
1022
|
writeWranglerConfig();
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
}
|
|
1023
|
+
await expect(
|
|
1024
|
+
runWrangler("kv:key get key --binding otherBinding")
|
|
1025
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
1026
|
+
`"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."`
|
|
1027
|
+
);
|
|
1088
1028
|
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
1089
1029
|
expect(std.err).toMatchInlineSnapshot(`
|
|
1090
1030
|
"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
|
|
@@ -1092,9 +1032,6 @@ describe("wrangler", () => {
|
|
|
1092
1032
|
[32m%s[0m
|
|
1093
1033
|
If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
1094
1034
|
`);
|
|
1095
|
-
expect(error).toMatchInlineSnapshot(
|
|
1096
|
-
`[Error: A namespace with binding name "otherBinding" was not found in the configured "kv_namespaces".]`
|
|
1097
|
-
);
|
|
1098
1035
|
});
|
|
1099
1036
|
});
|
|
1100
1037
|
|
|
@@ -1146,12 +1083,11 @@ describe("wrangler", () => {
|
|
|
1146
1083
|
|
|
1147
1084
|
it("should error if a given binding name is not in the configured kv namespaces", async () => {
|
|
1148
1085
|
writeWranglerConfig();
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
}
|
|
1086
|
+
await expect(
|
|
1087
|
+
runWrangler(`kv:key delete --binding otherBinding someKey`)
|
|
1088
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
1089
|
+
`"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."`
|
|
1090
|
+
);
|
|
1155
1091
|
|
|
1156
1092
|
expect(std.err).toMatchInlineSnapshot(`
|
|
1157
1093
|
"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
|
|
@@ -1159,9 +1095,6 @@ describe("wrangler", () => {
|
|
|
1159
1095
|
[32m%s[0m
|
|
1160
1096
|
If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
1161
1097
|
`);
|
|
1162
|
-
expect(error).toMatchInlineSnapshot(
|
|
1163
|
-
`[Error: A namespace with binding name "otherBinding" was not found in the configured "kv_namespaces".]`
|
|
1164
|
-
);
|
|
1165
1098
|
});
|
|
1166
1099
|
|
|
1167
1100
|
it("should delete a key in a namespace specified by binding name in a given environment", async () => {
|
|
@@ -1206,41 +1139,3 @@ function writeWranglerConfig() {
|
|
|
1206
1139
|
"utf-8"
|
|
1207
1140
|
);
|
|
1208
1141
|
}
|
|
1209
|
-
|
|
1210
|
-
export function mockKeyListRequest(
|
|
1211
|
-
expectedNamespaceId: string,
|
|
1212
|
-
expectedKeys: string[],
|
|
1213
|
-
keysPerRequest = 1000
|
|
1214
|
-
) {
|
|
1215
|
-
const requests = { count: 0 };
|
|
1216
|
-
// See https://api.cloudflare.com/#workers-kv-namespace-list-a-namespace-s-keys
|
|
1217
|
-
const expectedKeyObjects = expectedKeys.map((name) => ({
|
|
1218
|
-
name,
|
|
1219
|
-
expiration: 123456789,
|
|
1220
|
-
metadata: {},
|
|
1221
|
-
}));
|
|
1222
|
-
setMockRawResponse(
|
|
1223
|
-
"/accounts/:accountId/storage/kv/namespaces/:namespaceId/keys",
|
|
1224
|
-
"GET",
|
|
1225
|
-
([_url, accountId, namespaceId], _init, query) => {
|
|
1226
|
-
requests.count++;
|
|
1227
|
-
expect(accountId).toEqual("some-account-id");
|
|
1228
|
-
expect(namespaceId).toEqual(expectedNamespaceId);
|
|
1229
|
-
if (expectedKeyObjects.length <= keysPerRequest) {
|
|
1230
|
-
return createFetchResult(expectedKeyObjects);
|
|
1231
|
-
} else {
|
|
1232
|
-
const start = parseInt(query.get("cursor") ?? "0") || 0;
|
|
1233
|
-
const end = start + keysPerRequest;
|
|
1234
|
-
const cursor = end < expectedKeyObjects.length ? end : undefined;
|
|
1235
|
-
return createFetchResult(
|
|
1236
|
-
expectedKeyObjects.slice(start, end),
|
|
1237
|
-
true,
|
|
1238
|
-
[],
|
|
1239
|
-
[],
|
|
1240
|
-
{ cursor }
|
|
1241
|
-
);
|
|
1242
|
-
}
|
|
1243
|
-
}
|
|
1244
|
-
);
|
|
1245
|
-
return requests;
|
|
1246
|
-
}
|