wrangler 0.0.0-e978986 → 0.0.0-e9e9872
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/README.md +7 -1
- package/bin/wrangler.js +114 -57
- package/kv-asset-handler.js +1 -0
- package/miniflare-dist/index.mjs +10 -2
- package/package.json +159 -152
- package/src/__tests__/config-cache-without-cache-dir.test.ts +38 -0
- package/src/__tests__/config-cache.test.ts +30 -24
- package/src/__tests__/configuration.test.ts +3935 -3363
- package/src/__tests__/dev.test.tsx +1128 -949
- package/src/__tests__/guess-worker-format.test.ts +68 -68
- package/src/__tests__/helpers/cmd-shim.d.ts +6 -6
- package/src/__tests__/helpers/mock-account-id.ts +24 -24
- package/src/__tests__/helpers/mock-bin.ts +20 -20
- package/src/__tests__/helpers/mock-cfetch.ts +92 -92
- package/src/__tests__/helpers/mock-console.ts +49 -39
- package/src/__tests__/helpers/mock-dialogs.ts +94 -71
- package/src/__tests__/helpers/mock-http-server.ts +30 -30
- package/src/__tests__/helpers/mock-istty.ts +65 -18
- package/src/__tests__/helpers/mock-kv.ts +26 -26
- package/src/__tests__/helpers/mock-oauth-flow.ts +223 -228
- package/src/__tests__/helpers/mock-process.ts +39 -0
- package/src/__tests__/helpers/mock-stdin.ts +82 -77
- package/src/__tests__/helpers/mock-web-socket.ts +21 -21
- package/src/__tests__/helpers/run-in-tmp.ts +27 -28
- package/src/__tests__/helpers/run-wrangler.ts +8 -8
- package/src/__tests__/helpers/write-worker-source.ts +16 -16
- package/src/__tests__/helpers/write-wrangler-toml.ts +9 -9
- package/src/__tests__/https-options.test.ts +142 -109
- package/src/__tests__/index.test.ts +239 -233
- package/src/__tests__/init.test.ts +1605 -1180
- package/src/__tests__/jest.setup.ts +76 -33
- package/src/__tests__/kv.test.ts +1160 -991
- package/src/__tests__/logger.test.ts +100 -74
- package/src/__tests__/package-manager.test.ts +303 -303
- package/src/__tests__/pages.test.ts +1160 -563
- package/src/__tests__/parse.test.ts +252 -252
- package/src/__tests__/publish.test.ts +6426 -5299
- package/src/__tests__/pubsub.test.ts +367 -0
- package/src/__tests__/r2.test.ts +133 -133
- package/src/__tests__/route.test.ts +18 -18
- package/src/__tests__/secret.test.ts +470 -459
- package/src/__tests__/tail.test.ts +538 -530
- package/src/__tests__/user.test.ts +124 -112
- package/src/__tests__/whoami.test.tsx +208 -83
- package/src/__tests__/worker-namespace.test.ts +327 -0
- package/src/abort.d.ts +1 -1
- package/src/api/dev.ts +52 -0
- package/src/api/index.ts +1 -0
- package/src/bundle-reporter.tsx +29 -0
- package/src/bundle.ts +158 -146
- package/src/cfetch/index.ts +80 -80
- package/src/cfetch/internal.ts +92 -88
- package/src/cli.ts +21 -7
- package/src/config/config.ts +204 -195
- package/src/config/diagnostics.ts +61 -61
- package/src/config/environment.ts +390 -357
- package/src/config/index.ts +206 -193
- package/src/config/validation-helpers.ts +366 -357
- package/src/config/validation.ts +1573 -1367
- package/src/config-cache.ts +79 -41
- package/src/create-worker-preview.ts +206 -136
- package/src/create-worker-upload-form.ts +247 -238
- package/src/dev/dev-vars.ts +13 -13
- package/src/dev/dev.tsx +334 -336
- package/src/dev/local.tsx +310 -274
- package/src/dev/remote.tsx +366 -211
- package/src/dev/use-esbuild.ts +126 -94
- package/src/dev.tsx +538 -0
- package/src/dialogs.tsx +97 -97
- package/src/durable.ts +87 -87
- package/src/entry.ts +234 -228
- package/src/environment-variables.ts +23 -23
- package/src/errors.ts +6 -6
- package/src/faye-websocket.d.ts +6 -0
- package/src/generate.ts +33 -0
- package/src/git-client.ts +42 -0
- package/src/global-wrangler-config-path.ts +26 -0
- package/src/https-options.ts +84 -80
- package/src/index.tsx +1800 -2752
- package/src/init.ts +549 -0
- package/src/inspect.ts +593 -593
- package/src/intl-polyfill.d.ts +123 -123
- package/src/is-interactive.ts +12 -0
- package/src/kv.ts +299 -277
- package/src/logger.ts +46 -39
- package/src/miniflare-cli/enum-keys.ts +8 -8
- package/src/miniflare-cli/index.ts +43 -31
- package/src/miniflare-cli/request-context.ts +18 -18
- package/src/module-collection.ts +212 -212
- package/src/open-in-browser.ts +4 -6
- package/src/package-manager.ts +173 -128
- package/src/pages/build.tsx +202 -0
- package/src/pages/constants.ts +7 -0
- package/src/pages/deployments.tsx +101 -0
- package/src/pages/dev.tsx +964 -0
- package/src/pages/functions/buildPlugin.ts +105 -0
- package/src/pages/functions/buildWorker.ts +151 -0
- package/{pages → src/pages}/functions/filepath-routing.test.ts +113 -113
- package/src/pages/functions/filepath-routing.ts +189 -0
- package/src/pages/functions/identifiers.ts +78 -0
- package/src/pages/functions/routes.ts +151 -0
- package/src/pages/index.tsx +84 -0
- package/src/pages/projects.tsx +157 -0
- package/src/pages/publish.tsx +335 -0
- package/src/pages/types.ts +40 -0
- package/src/pages/upload.tsx +396 -0
- package/src/pages/utils.ts +12 -0
- package/src/parse.ts +209 -125
- package/src/paths.ts +6 -6
- package/src/preview.ts +31 -0
- package/src/proxy.ts +400 -389
- package/src/publish.ts +702 -505
- package/src/pubsub/index.ts +286 -0
- package/src/pubsub/pubsub-commands.tsx +577 -0
- package/src/r2.ts +19 -19
- package/src/selfsigned.d.ts +23 -23
- package/src/sites.tsx +278 -201
- package/src/tail/filters.ts +108 -108
- package/src/tail/index.ts +217 -217
- package/src/tail/printing.ts +45 -45
- package/src/update-check.ts +11 -11
- package/src/user/choose-account.tsx +60 -0
- package/src/user/env-vars.ts +46 -0
- package/src/user/generate-auth-url.ts +33 -0
- package/src/user/generate-random-state.ts +16 -0
- package/src/user/index.ts +3 -0
- package/src/user/user.tsx +1170 -0
- package/src/whoami.tsx +61 -41
- package/src/worker-namespace.ts +190 -0
- package/src/worker.ts +110 -99
- package/src/zones.ts +76 -0
- package/templates/checked-fetch.js +17 -0
- package/templates/new-worker-scheduled.js +4 -4
- package/templates/new-worker-scheduled.ts +16 -16
- package/templates/new-worker.js +3 -3
- package/templates/new-worker.ts +15 -15
- package/templates/no-op-worker.js +10 -0
- package/templates/pages-template-plugin.ts +155 -0
- package/templates/pages-template-worker.ts +161 -0
- package/templates/static-asset-facade.js +38 -36
- package/templates/tsconfig.json +95 -95
- package/wrangler-dist/cli.d.ts +298 -0
- package/wrangler-dist/cli.js +33496 -31370
- package/pages/functions/buildPlugin.ts +0 -105
- package/pages/functions/buildWorker.ts +0 -151
- package/pages/functions/filepath-routing.ts +0 -189
- package/pages/functions/identifiers.ts +0 -78
- package/pages/functions/routes.ts +0 -156
- package/pages/functions/template-plugin.ts +0 -147
- package/pages/functions/template-worker.ts +0 -143
- package/src/__tests__/helpers/faye-websocket.d.ts +0 -6
- package/src/pages.tsx +0 -2027
- package/src/user.tsx +0 -1203
- package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
- package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
- package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
- package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
- package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
- package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
- package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
- package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
- package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
- package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
- package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
- package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
- package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
- package/vendor/wrangler-mime/CHANGELOG.md +0 -289
- package/vendor/wrangler-mime/LICENSE +0 -21
- package/vendor/wrangler-mime/Mime.js +0 -97
- package/vendor/wrangler-mime/README.md +0 -187
- package/vendor/wrangler-mime/cli.js +0 -46
- package/vendor/wrangler-mime/index.js +0 -4
- package/vendor/wrangler-mime/lite.js +0 -4
- package/vendor/wrangler-mime/package.json +0 -52
- package/vendor/wrangler-mime/types/other.js +0 -1
- package/vendor/wrangler-mime/types/standard.js +0 -1
package/src/__tests__/kv.test.ts
CHANGED
|
@@ -1,52 +1,56 @@
|
|
|
1
1
|
import { writeFileSync } from "node:fs";
|
|
2
|
-
import { Headers } from "undici";
|
|
2
|
+
import { FormData, Headers } from "undici";
|
|
3
3
|
import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
setMockResponse,
|
|
6
|
+
unsetAllMocks,
|
|
7
|
+
unsetMockFetchKVGetValues,
|
|
8
|
+
setMockFetchKVGetValue,
|
|
9
9
|
} from "./helpers/mock-cfetch";
|
|
10
10
|
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
11
11
|
import { clearConfirmMocks, mockConfirm } from "./helpers/mock-dialogs";
|
|
12
|
+
import { useMockIsTTY } from "./helpers/mock-istty";
|
|
12
13
|
import { mockKeyListRequest } from "./helpers/mock-kv";
|
|
14
|
+
import { mockGetMemberships } from "./helpers/mock-oauth-flow";
|
|
15
|
+
import { mockProcess } from "./helpers/mock-process";
|
|
13
16
|
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
14
17
|
import { runWrangler } from "./helpers/run-wrangler";
|
|
15
18
|
import type { KeyValue, KVNamespaceInfo, NamespaceKeyInfo } from "../kv";
|
|
16
19
|
|
|
17
20
|
describe("wrangler", () => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
21
|
+
mockAccountId();
|
|
22
|
+
mockApiToken();
|
|
23
|
+
runInTempDir();
|
|
24
|
+
const std = mockConsoleMethods();
|
|
25
|
+
const proc = mockProcess();
|
|
26
|
+
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
unsetAllMocks();
|
|
29
|
+
clearConfirmMocks();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe("kv:namespace", () => {
|
|
33
|
+
describe("create", () => {
|
|
34
|
+
function mockCreateRequest(expectedTitle: string) {
|
|
35
|
+
setMockResponse(
|
|
36
|
+
"/accounts/:accountId/storage/kv/namespaces",
|
|
37
|
+
"POST",
|
|
38
|
+
([_url, accountId], { body }) => {
|
|
39
|
+
expect(accountId).toEqual("some-account-id");
|
|
40
|
+
const title = JSON.parse(body as string).title;
|
|
41
|
+
expect(title).toEqual(expectedTitle);
|
|
42
|
+
return { id: "some-namespace-id" };
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
it("should error if no namespace is given", async () => {
|
|
48
|
+
await expect(
|
|
49
|
+
runWrangler("kv:namespace create")
|
|
50
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
51
|
+
`"Not enough non-option arguments: got 0, need at least 1"`
|
|
52
|
+
);
|
|
53
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
50
54
|
"
|
|
51
55
|
wrangler kv:namespace create <namespace>
|
|
52
56
|
|
|
@@ -64,20 +68,20 @@ describe("wrangler", () => {
|
|
|
64
68
|
-e, --env Perform on a specific environment [string]
|
|
65
69
|
--preview Interact with a preview namespace [boolean]"
|
|
66
70
|
`);
|
|
67
|
-
|
|
71
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
68
72
|
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mNot enough non-option arguments: got 0, need at least 1[0m
|
|
69
73
|
|
|
70
74
|
"
|
|
71
75
|
`);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("should error if the namespace to create contains spaces", async () => {
|
|
79
|
+
await expect(
|
|
80
|
+
runWrangler("kv:namespace create abc def ghi")
|
|
81
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
82
|
+
`"Unknown arguments: def, ghi"`
|
|
83
|
+
);
|
|
84
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
81
85
|
"
|
|
82
86
|
wrangler kv:namespace create <namespace>
|
|
83
87
|
|
|
@@ -95,21 +99,21 @@ describe("wrangler", () => {
|
|
|
95
99
|
-e, --env Perform on a specific environment [string]
|
|
96
100
|
--preview Interact with a preview namespace [boolean]"
|
|
97
101
|
`);
|
|
98
|
-
|
|
102
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
99
103
|
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mUnknown arguments: def, ghi[0m
|
|
100
104
|
|
|
101
105
|
"
|
|
102
106
|
`);
|
|
103
|
-
|
|
107
|
+
});
|
|
104
108
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
109
|
+
it("should error if the namespace to create is not valid", async () => {
|
|
110
|
+
await expect(
|
|
111
|
+
runWrangler("kv:namespace create abc-def")
|
|
112
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
113
|
+
`"The namespace binding name \\"abc-def\\" is invalid. It can only have alphanumeric and _ characters, and cannot begin with a number."`
|
|
114
|
+
);
|
|
111
115
|
|
|
112
|
-
|
|
116
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
113
117
|
"
|
|
114
118
|
wrangler kv:namespace create <namespace>
|
|
115
119
|
|
|
@@ -127,350 +131,397 @@ describe("wrangler", () => {
|
|
|
127
131
|
-e, --env Perform on a specific environment [string]
|
|
128
132
|
--preview Interact with a preview namespace [boolean]"
|
|
129
133
|
`);
|
|
130
|
-
|
|
134
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
131
135
|
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mThe namespace binding name \\"abc-def\\" is invalid. It can only have alphanumeric and _ characters, and cannot begin with a number.[0m
|
|
132
136
|
|
|
133
137
|
"
|
|
134
138
|
`);
|
|
135
|
-
|
|
139
|
+
});
|
|
136
140
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
+
it("should create a namespace", async () => {
|
|
142
|
+
mockCreateRequest("worker-UnitTestNamespace");
|
|
143
|
+
await runWrangler("kv:namespace create UnitTestNamespace");
|
|
144
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
141
145
|
"🌀 Creating namespace with title \\"worker-UnitTestNamespace\\"
|
|
142
146
|
✨ Success!
|
|
143
147
|
Add the following to your configuration file in your kv_namespaces array:
|
|
144
148
|
{ binding = \\"UnitTestNamespace\\", id = \\"some-namespace-id\\" }"
|
|
145
149
|
`);
|
|
146
|
-
|
|
150
|
+
});
|
|
147
151
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
+
it("should create a preview namespace if configured to do so", async () => {
|
|
153
|
+
mockCreateRequest("worker-UnitTestNamespace_preview");
|
|
154
|
+
await runWrangler("kv:namespace create UnitTestNamespace --preview");
|
|
155
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
152
156
|
"🌀 Creating namespace with title \\"worker-UnitTestNamespace_preview\\"
|
|
153
157
|
✨ Success!
|
|
154
158
|
Add the following to your configuration file in your kv_namespaces array:
|
|
155
159
|
{ binding = \\"UnitTestNamespace\\", preview_id = \\"some-namespace-id\\" }"
|
|
156
160
|
`);
|
|
157
|
-
|
|
161
|
+
});
|
|
158
162
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
163
|
+
it("should create a namespace using configured worker name", async () => {
|
|
164
|
+
writeFileSync("./wrangler.toml", 'name = "other-worker"', "utf-8");
|
|
165
|
+
mockCreateRequest("other-worker-UnitTestNamespace");
|
|
166
|
+
await runWrangler("kv:namespace create UnitTestNamespace");
|
|
167
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
164
168
|
"🌀 Creating namespace with title \\"other-worker-UnitTestNamespace\\"
|
|
165
169
|
✨ Success!
|
|
166
170
|
Add the following to your configuration file in your kv_namespaces array:
|
|
167
171
|
{ binding = \\"UnitTestNamespace\\", id = \\"some-namespace-id\\" }"
|
|
168
172
|
`);
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it("should create a namespace in an environment if configured to do so", async () => {
|
|
176
|
+
mockCreateRequest("worker-customEnv-UnitTestNamespace");
|
|
177
|
+
await runWrangler(
|
|
178
|
+
"kv:namespace create UnitTestNamespace --env customEnv"
|
|
179
|
+
);
|
|
180
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
177
181
|
"🌀 Creating namespace with title \\"worker-customEnv-UnitTestNamespace\\"
|
|
178
182
|
✨ Success!
|
|
179
183
|
Add the following to your configuration file in your kv_namespaces array under [env.customEnv]:
|
|
180
184
|
{ binding = \\"UnitTestNamespace\\", id = \\"some-namespace-id\\" }"
|
|
181
185
|
`);
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
describe("list", () => {
|
|
190
|
+
function mockListRequest(namespaces: unknown[]) {
|
|
191
|
+
const requests = { count: 0 };
|
|
192
|
+
setMockResponse(
|
|
193
|
+
"/accounts/:accountId/storage/kv/namespaces",
|
|
194
|
+
([_url, accountId], init, query) => {
|
|
195
|
+
requests.count++;
|
|
196
|
+
expect(accountId).toEqual("some-account-id");
|
|
197
|
+
expect(query.get("per_page")).toEqual("100");
|
|
198
|
+
expect(query.get("order")).toEqual("title");
|
|
199
|
+
expect(query.get("direction")).toEqual("asc");
|
|
200
|
+
expect(query.get("page")).toEqual(`${requests.count}`);
|
|
201
|
+
expect(init).toEqual({});
|
|
202
|
+
const pageSize = Number(query.get("per_page"));
|
|
203
|
+
const page = Number(query.get("page"));
|
|
204
|
+
return namespaces.slice((page - 1) * pageSize, page * pageSize);
|
|
205
|
+
}
|
|
206
|
+
);
|
|
207
|
+
return requests;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
it("should list namespaces", async () => {
|
|
211
|
+
const kvNamespaces: KVNamespaceInfo[] = [
|
|
212
|
+
{ title: "title-1", id: "id-1" },
|
|
213
|
+
{ title: "title-2", id: "id-2" },
|
|
214
|
+
];
|
|
215
|
+
mockListRequest(kvNamespaces);
|
|
216
|
+
await runWrangler("kv:namespace list");
|
|
217
|
+
|
|
218
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
219
|
+
const namespaces = JSON.parse(std.out);
|
|
220
|
+
expect(namespaces).toEqual(kvNamespaces);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it("should make multiple requests for paginated results", async () => {
|
|
224
|
+
// Create a lot of mock namespaces, so that the fetch requests will be paginated
|
|
225
|
+
const kvNamespaces: KVNamespaceInfo[] = [];
|
|
226
|
+
for (let i = 0; i < 550; i++) {
|
|
227
|
+
kvNamespaces.push({ title: "title-" + i, id: "id-" + i });
|
|
228
|
+
}
|
|
229
|
+
const requests = mockListRequest(kvNamespaces);
|
|
230
|
+
await runWrangler("kv:namespace list");
|
|
231
|
+
const namespaces = JSON.parse(std.out);
|
|
232
|
+
expect(namespaces).toEqual(kvNamespaces);
|
|
233
|
+
expect(requests.count).toEqual(6);
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
describe("delete", () => {
|
|
238
|
+
function mockDeleteRequest(expectedNamespaceId: string) {
|
|
239
|
+
const requests = { count: 0 };
|
|
240
|
+
setMockResponse(
|
|
241
|
+
"/accounts/:accountId/storage/kv/namespaces/:namespaceId",
|
|
242
|
+
"DELETE",
|
|
243
|
+
([_url, accountId, namespaceId]) => {
|
|
244
|
+
requests.count++;
|
|
245
|
+
expect(accountId).toEqual("some-account-id");
|
|
246
|
+
expect(namespaceId).toEqual(expectedNamespaceId);
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
);
|
|
250
|
+
return requests;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
it("should delete a namespace specified by id", async () => {
|
|
254
|
+
const requests = mockDeleteRequest("some-namespace-id");
|
|
255
|
+
await runWrangler(
|
|
256
|
+
`kv:namespace delete --namespace-id some-namespace-id`
|
|
257
|
+
);
|
|
258
|
+
expect(requests.count).toEqual(1);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it("should delete a namespace specified by binding name", async () => {
|
|
262
|
+
writeWranglerConfig();
|
|
263
|
+
const requests = mockDeleteRequest("bound-id");
|
|
264
|
+
await runWrangler(
|
|
265
|
+
`kv:namespace delete --binding someBinding --preview false`
|
|
266
|
+
);
|
|
267
|
+
expect(requests.count).toEqual(1);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it("should delete a preview namespace specified by binding name", async () => {
|
|
271
|
+
writeWranglerConfig();
|
|
272
|
+
const requests = mockDeleteRequest("preview-bound-id");
|
|
273
|
+
await runWrangler(
|
|
274
|
+
`kv:namespace delete --binding someBinding --preview`
|
|
275
|
+
);
|
|
276
|
+
expect(requests.count).toEqual(1);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it("should error if a given binding name is not in the configured kv namespaces", async () => {
|
|
280
|
+
writeWranglerConfig();
|
|
281
|
+
await expect(runWrangler("kv:namespace delete --binding otherBinding"))
|
|
282
|
+
.rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
279
283
|
"Not able to delete namespace.
|
|
280
284
|
A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."
|
|
281
285
|
`);
|
|
282
|
-
|
|
286
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
283
287
|
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mNot able to delete namespace.[0m
|
|
284
288
|
|
|
285
289
|
A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
|
|
286
290
|
|
|
287
291
|
"
|
|
288
292
|
`);
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
it("should delete a namespace specified by binding name in a given environment", async () => {
|
|
296
|
+
writeWranglerConfig();
|
|
297
|
+
const requests = mockDeleteRequest("env-bound-id");
|
|
298
|
+
await runWrangler(
|
|
299
|
+
"kv:namespace delete --binding someBinding --env some-environment --preview false"
|
|
300
|
+
);
|
|
301
|
+
|
|
302
|
+
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
303
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
304
|
+
expect(requests.count).toEqual(1);
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it("should delete a preview namespace specified by binding name in a given environment", async () => {
|
|
308
|
+
writeWranglerConfig();
|
|
309
|
+
const requests = mockDeleteRequest("preview-env-bound-id");
|
|
310
|
+
await runWrangler(
|
|
311
|
+
`kv:namespace delete --binding someBinding --env some-environment --preview`
|
|
312
|
+
);
|
|
313
|
+
expect(requests.count).toEqual(1);
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
describe("kv:key", () => {
|
|
319
|
+
describe("put", () => {
|
|
320
|
+
function mockKeyPutRequest(
|
|
321
|
+
expectedNamespaceId: string,
|
|
322
|
+
expectedKV: KeyValue
|
|
323
|
+
) {
|
|
324
|
+
const requests = { count: 0 };
|
|
325
|
+
setMockResponse(
|
|
326
|
+
"/accounts/:accountId/storage/kv/namespaces/:namespaceId/values/:key",
|
|
327
|
+
"PUT",
|
|
328
|
+
([_url, accountId, namespaceId, key], { body }, query) => {
|
|
329
|
+
requests.count++;
|
|
330
|
+
expect(accountId).toEqual("some-account-id");
|
|
331
|
+
expect(namespaceId).toEqual(expectedNamespaceId);
|
|
332
|
+
expect(key).toEqual(expectedKV.key);
|
|
333
|
+
if (expectedKV.metadata) {
|
|
334
|
+
expect(body).toBeInstanceOf(FormData);
|
|
335
|
+
expect((body as FormData).get("value")).toEqual(expectedKV.value);
|
|
336
|
+
expect((body as FormData).get("metadata")).toEqual(
|
|
337
|
+
JSON.stringify(expectedKV.metadata)
|
|
338
|
+
);
|
|
339
|
+
} else {
|
|
340
|
+
expect(body).toEqual(expectedKV.value);
|
|
341
|
+
}
|
|
342
|
+
if (expectedKV.expiration !== undefined) {
|
|
343
|
+
expect(query.get("expiration")).toEqual(
|
|
344
|
+
`${expectedKV.expiration}`
|
|
345
|
+
);
|
|
346
|
+
} else {
|
|
347
|
+
expect(query.has("expiration")).toBe(false);
|
|
348
|
+
}
|
|
349
|
+
if (expectedKV.expiration_ttl) {
|
|
350
|
+
expect(query.get("expiration_ttl")).toEqual(
|
|
351
|
+
`${expectedKV.expiration_ttl}`
|
|
352
|
+
);
|
|
353
|
+
} else {
|
|
354
|
+
expect(query.has("expiration_ttl")).toBe(false);
|
|
355
|
+
}
|
|
356
|
+
return null;
|
|
357
|
+
}
|
|
358
|
+
);
|
|
359
|
+
return requests;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
it("should put a key in a given namespace specified by namespace-id", async () => {
|
|
363
|
+
const requests = mockKeyPutRequest("some-namespace-id", {
|
|
364
|
+
key: "my-key",
|
|
365
|
+
value: "my-value",
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
await runWrangler(
|
|
369
|
+
"kv:key put my-key my-value --namespace-id some-namespace-id"
|
|
370
|
+
);
|
|
371
|
+
|
|
372
|
+
expect(requests.count).toEqual(1);
|
|
373
|
+
expect(std.out).toMatchInlineSnapshot(
|
|
374
|
+
`"Writing the value \\"my-value\\" to key \\"my-key\\" on namespace some-namespace-id."`
|
|
375
|
+
);
|
|
376
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
it("should encode the key in the api request to put a value", async () => {
|
|
380
|
+
const requests = mockKeyPutRequest("DS9", {
|
|
381
|
+
key: "%2Fmy-key",
|
|
382
|
+
value: "my-value",
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
await runWrangler("kv:key put /my-key my-value --namespace-id DS9");
|
|
386
|
+
|
|
387
|
+
expect(requests.count).toEqual(1);
|
|
388
|
+
expect(std.out).toMatchInlineSnapshot(
|
|
389
|
+
`"Writing the value \\"my-value\\" to key \\"/my-key\\" on namespace DS9."`
|
|
390
|
+
);
|
|
391
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
it("should put a key in a given namespace specified by binding", async () => {
|
|
395
|
+
writeWranglerConfig();
|
|
396
|
+
const requests = mockKeyPutRequest("bound-id", {
|
|
397
|
+
key: "my-key",
|
|
398
|
+
value: "my-value",
|
|
399
|
+
});
|
|
400
|
+
await runWrangler(
|
|
401
|
+
"kv:key put my-key my-value --binding someBinding --preview false"
|
|
402
|
+
);
|
|
403
|
+
|
|
404
|
+
expect(std.out).toMatchInlineSnapshot(
|
|
405
|
+
`"Writing the value \\"my-value\\" to key \\"my-key\\" on namespace bound-id."`
|
|
406
|
+
);
|
|
407
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
408
|
+
expect(requests.count).toEqual(1);
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
it("should put a key in a given preview namespace specified by binding", async () => {
|
|
412
|
+
writeWranglerConfig();
|
|
413
|
+
const requests = mockKeyPutRequest("preview-bound-id", {
|
|
414
|
+
key: "my-key",
|
|
415
|
+
value: "my-value",
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
await runWrangler(
|
|
419
|
+
"kv:key put my-key my-value --binding someBinding --preview"
|
|
420
|
+
);
|
|
421
|
+
|
|
422
|
+
expect(std.out).toMatchInlineSnapshot(
|
|
423
|
+
`"Writing the value \\"my-value\\" to key \\"my-key\\" on namespace preview-bound-id."`
|
|
424
|
+
);
|
|
425
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
426
|
+
expect(requests.count).toEqual(1);
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
it("should add expiration and ttl properties when putting a key", async () => {
|
|
430
|
+
const requests = mockKeyPutRequest("some-namespace-id", {
|
|
431
|
+
key: "my-key",
|
|
432
|
+
value: "my-value",
|
|
433
|
+
expiration: 10,
|
|
434
|
+
expiration_ttl: 20,
|
|
435
|
+
});
|
|
436
|
+
await runWrangler(
|
|
437
|
+
"kv:key put my-key my-value --namespace-id some-namespace-id --expiration 10 --ttl 20"
|
|
438
|
+
);
|
|
439
|
+
expect(requests.count).toEqual(1);
|
|
440
|
+
expect(std.out).toMatchInlineSnapshot(
|
|
441
|
+
`"Writing the value \\"my-value\\" to key \\"my-key\\" on namespace some-namespace-id."`
|
|
442
|
+
);
|
|
443
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
it("should put a key to the specified environment in a given namespace", async () => {
|
|
447
|
+
writeWranglerConfig();
|
|
448
|
+
const requests = mockKeyPutRequest("env-bound-id", {
|
|
449
|
+
key: "my-key",
|
|
450
|
+
value: "my-value",
|
|
451
|
+
});
|
|
452
|
+
await runWrangler(
|
|
453
|
+
"kv:key put my-key my-value --binding someBinding --env some-environment --preview false"
|
|
454
|
+
);
|
|
455
|
+
expect(std.out).toMatchInlineSnapshot(
|
|
456
|
+
`"Writing the value \\"my-value\\" to key \\"my-key\\" on namespace env-bound-id."`
|
|
457
|
+
);
|
|
458
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
459
|
+
expect(requests.count).toEqual(1);
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
it("should put a key with a value loaded from a given path", async () => {
|
|
463
|
+
const buf = Buffer.from("file-contents", "utf-8");
|
|
464
|
+
writeFileSync("foo.txt", buf);
|
|
465
|
+
const requests = mockKeyPutRequest("some-namespace-id", {
|
|
466
|
+
key: "my-key",
|
|
467
|
+
value: buf,
|
|
468
|
+
});
|
|
469
|
+
await runWrangler(
|
|
470
|
+
"kv:key put my-key --namespace-id some-namespace-id --path foo.txt"
|
|
471
|
+
);
|
|
472
|
+
expect(std.out).toMatchInlineSnapshot(
|
|
473
|
+
`"Writing the contents of foo.txt to the key \\"my-key\\" on namespace some-namespace-id."`
|
|
474
|
+
);
|
|
475
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
476
|
+
expect(requests.count).toEqual(1);
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
it("should put a key with a binary value loaded from a given path", async () => {
|
|
480
|
+
const buf = Buffer.from(
|
|
481
|
+
"iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAiSURBVHgB7coxEQAACMPAgH/PgAM6dGwu49fA/deIBXrgAj2cAhIFT4QxAAAAAElFTkSuQmCC",
|
|
482
|
+
"base64"
|
|
483
|
+
);
|
|
484
|
+
writeFileSync("test.png", buf);
|
|
485
|
+
const requests = mockKeyPutRequest("another-namespace-id", {
|
|
486
|
+
key: "my-key",
|
|
487
|
+
value: buf,
|
|
488
|
+
});
|
|
489
|
+
await runWrangler(
|
|
490
|
+
"kv:key put my-key --namespace-id another-namespace-id --path test.png"
|
|
491
|
+
);
|
|
492
|
+
expect(std.out).toMatchInlineSnapshot(
|
|
493
|
+
`"Writing the contents of test.png to the key \\"my-key\\" on namespace another-namespace-id."`
|
|
494
|
+
);
|
|
495
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
496
|
+
expect(requests.count).toEqual(1);
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
it("should put a key with metadata", async () => {
|
|
500
|
+
const requests = mockKeyPutRequest("some-namespace-id", {
|
|
501
|
+
key: "dKey",
|
|
502
|
+
value: "dVal",
|
|
503
|
+
metadata: {
|
|
504
|
+
mKey: "mValue",
|
|
505
|
+
},
|
|
506
|
+
});
|
|
507
|
+
await runWrangler(
|
|
508
|
+
`kv:key put dKey dVal --namespace-id some-namespace-id --metadata {"mKey":"mValue"}`
|
|
509
|
+
);
|
|
510
|
+
expect(requests.count).toEqual(1);
|
|
511
|
+
expect(std.out).toMatchInlineSnapshot(
|
|
512
|
+
`"Writing the value \\"dVal\\" to key \\"dKey\\" on namespace some-namespace-id with metadata \\"{\\"mKey\\":\\"mValue\\"}\\"."`
|
|
513
|
+
);
|
|
514
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
it("should error if no key is provided", async () => {
|
|
518
|
+
await expect(
|
|
519
|
+
runWrangler("kv:key put")
|
|
520
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
521
|
+
`"Not enough non-option arguments: got 0, need at least 1"`
|
|
522
|
+
);
|
|
523
|
+
|
|
524
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
474
525
|
"
|
|
475
526
|
wrangler kv:key put <key> [value]
|
|
476
527
|
|
|
@@ -492,23 +543,24 @@ describe("wrangler", () => {
|
|
|
492
543
|
--preview Interact with a preview namespace [boolean]
|
|
493
544
|
--ttl Time for which the entries should be visible [number]
|
|
494
545
|
--expiration Time since the UNIX epoch after which the entry expires [number]
|
|
546
|
+
--metadata Arbitrary JSON that is associated with a key [string]
|
|
495
547
|
--path Read value from the file at a given path [string]"
|
|
496
548
|
`);
|
|
497
|
-
|
|
549
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
498
550
|
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mNot enough non-option arguments: got 0, need at least 1[0m
|
|
499
551
|
|
|
500
552
|
"
|
|
501
553
|
`);
|
|
502
|
-
|
|
554
|
+
});
|
|
503
555
|
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
556
|
+
it("should error if no binding nor namespace is provided", async () => {
|
|
557
|
+
await expect(
|
|
558
|
+
runWrangler("kv:key put foo bar")
|
|
559
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
560
|
+
`"Exactly one of the arguments binding and namespace-id is required"`
|
|
561
|
+
);
|
|
510
562
|
|
|
511
|
-
|
|
563
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
512
564
|
"
|
|
513
565
|
wrangler kv:key put <key> [value]
|
|
514
566
|
|
|
@@ -530,23 +582,24 @@ describe("wrangler", () => {
|
|
|
530
582
|
--preview Interact with a preview namespace [boolean]
|
|
531
583
|
--ttl Time for which the entries should be visible [number]
|
|
532
584
|
--expiration Time since the UNIX epoch after which the entry expires [number]
|
|
585
|
+
--metadata Arbitrary JSON that is associated with a key [string]
|
|
533
586
|
--path Read value from the file at a given path [string]"
|
|
534
587
|
`);
|
|
535
|
-
|
|
588
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
536
589
|
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mExactly one of the arguments binding and namespace-id is required[0m
|
|
537
590
|
|
|
538
591
|
"
|
|
539
592
|
`);
|
|
540
|
-
|
|
593
|
+
});
|
|
541
594
|
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
595
|
+
it("should error if both binding and namespace is provided", async () => {
|
|
596
|
+
await expect(
|
|
597
|
+
runWrangler("kv:key put foo bar --binding x --namespace-id y")
|
|
598
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
599
|
+
`"Arguments binding and namespace-id are mutually exclusive"`
|
|
600
|
+
);
|
|
548
601
|
|
|
549
|
-
|
|
602
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
550
603
|
"
|
|
551
604
|
wrangler kv:key put <key> [value]
|
|
552
605
|
|
|
@@ -568,23 +621,24 @@ describe("wrangler", () => {
|
|
|
568
621
|
--preview Interact with a preview namespace [boolean]
|
|
569
622
|
--ttl Time for which the entries should be visible [number]
|
|
570
623
|
--expiration Time since the UNIX epoch after which the entry expires [number]
|
|
624
|
+
--metadata Arbitrary JSON that is associated with a key [string]
|
|
571
625
|
--path Read value from the file at a given path [string]"
|
|
572
626
|
`);
|
|
573
|
-
|
|
627
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
574
628
|
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mArguments binding and namespace-id are mutually exclusive[0m
|
|
575
629
|
|
|
576
630
|
"
|
|
577
631
|
`);
|
|
578
|
-
|
|
632
|
+
});
|
|
579
633
|
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
634
|
+
it("should error if no value nor path is provided", async () => {
|
|
635
|
+
await expect(
|
|
636
|
+
runWrangler("kv:key put key --namespace-id 12345")
|
|
637
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
638
|
+
`"Exactly one of the arguments value and path is required"`
|
|
639
|
+
);
|
|
586
640
|
|
|
587
|
-
|
|
641
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
588
642
|
"
|
|
589
643
|
wrangler kv:key put <key> [value]
|
|
590
644
|
|
|
@@ -606,23 +660,24 @@ describe("wrangler", () => {
|
|
|
606
660
|
--preview Interact with a preview namespace [boolean]
|
|
607
661
|
--ttl Time for which the entries should be visible [number]
|
|
608
662
|
--expiration Time since the UNIX epoch after which the entry expires [number]
|
|
663
|
+
--metadata Arbitrary JSON that is associated with a key [string]
|
|
609
664
|
--path Read value from the file at a given path [string]"
|
|
610
665
|
`);
|
|
611
|
-
|
|
666
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
612
667
|
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mExactly one of the arguments value and path is required[0m
|
|
613
668
|
|
|
614
669
|
"
|
|
615
670
|
`);
|
|
616
|
-
|
|
671
|
+
});
|
|
617
672
|
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
673
|
+
it("should error if both value and path is provided", async () => {
|
|
674
|
+
await expect(
|
|
675
|
+
runWrangler("kv:key put key value --path xyz --namespace-id 12345")
|
|
676
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
677
|
+
`"Arguments value and path are mutually exclusive"`
|
|
678
|
+
);
|
|
624
679
|
|
|
625
|
-
|
|
680
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
626
681
|
"
|
|
627
682
|
wrangler kv:key put <key> [value]
|
|
628
683
|
|
|
@@ -644,69 +699,70 @@ describe("wrangler", () => {
|
|
|
644
699
|
--preview Interact with a preview namespace [boolean]
|
|
645
700
|
--ttl Time for which the entries should be visible [number]
|
|
646
701
|
--expiration Time since the UNIX epoch after which the entry expires [number]
|
|
702
|
+
--metadata Arbitrary JSON that is associated with a key [string]
|
|
647
703
|
--path Read value from the file at a given path [string]"
|
|
648
704
|
`);
|
|
649
|
-
|
|
705
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
650
706
|
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mArguments value and path are mutually exclusive[0m
|
|
651
707
|
|
|
652
708
|
"
|
|
653
709
|
`);
|
|
654
|
-
|
|
710
|
+
});
|
|
655
711
|
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
712
|
+
it("should error if a given binding name is not in the configured kv namespaces", async () => {
|
|
713
|
+
writeWranglerConfig();
|
|
714
|
+
await expect(
|
|
715
|
+
runWrangler("kv:key put key value --binding otherBinding")
|
|
716
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
717
|
+
`"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."`
|
|
718
|
+
);
|
|
663
719
|
|
|
664
|
-
|
|
720
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
665
721
|
"
|
|
666
722
|
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
667
723
|
`);
|
|
668
|
-
|
|
724
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
669
725
|
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mA namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".[0m
|
|
670
726
|
|
|
671
727
|
"
|
|
672
728
|
`);
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
729
|
+
});
|
|
730
|
+
|
|
731
|
+
it("should error if a given binding has both preview and non-preview and --preview is not specified", async () => {
|
|
732
|
+
writeWranglerConfig();
|
|
733
|
+
const requests = mockKeyPutRequest("preview-bound-id", {
|
|
734
|
+
key: "my-key",
|
|
735
|
+
value: "my-value",
|
|
736
|
+
});
|
|
737
|
+
await expect(
|
|
738
|
+
runWrangler("kv:key put my-key my-value --binding someBinding")
|
|
739
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
740
|
+
`"someBinding has both a namespace ID and a preview ID. Specify \\"--preview\\" or \\"--preview false\\" to avoid writing data to the wrong namespace."`
|
|
741
|
+
);
|
|
742
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
687
743
|
"
|
|
688
744
|
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
689
745
|
`);
|
|
690
|
-
|
|
746
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
691
747
|
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1msomeBinding has both a namespace ID and a preview ID. Specify \\"--preview\\" or \\"--preview false\\" to avoid writing data to the wrong namespace.[0m
|
|
692
748
|
|
|
693
749
|
"
|
|
694
750
|
`);
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
751
|
+
expect(requests.count).toEqual(0);
|
|
752
|
+
});
|
|
753
|
+
});
|
|
754
|
+
|
|
755
|
+
describe("list", () => {
|
|
756
|
+
it("should list the keys of a namespace specified by namespace-id", async () => {
|
|
757
|
+
const keys = [
|
|
758
|
+
{ name: "key-1" },
|
|
759
|
+
{ name: "key-2", expiration: 123456789 },
|
|
760
|
+
{ name: "key-3", expiration_ttl: 666 },
|
|
761
|
+
];
|
|
762
|
+
mockKeyListRequest("some-namespace-id", keys);
|
|
763
|
+
await runWrangler("kv:key list --namespace-id some-namespace-id");
|
|
764
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
765
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
710
766
|
"[
|
|
711
767
|
{
|
|
712
768
|
\\"name\\": \\"key-1\\"
|
|
@@ -721,16 +777,16 @@ describe("wrangler", () => {
|
|
|
721
777
|
}
|
|
722
778
|
]"
|
|
723
779
|
`);
|
|
724
|
-
|
|
780
|
+
});
|
|
725
781
|
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
782
|
+
it("should list the keys of a namespace specified by binding", async () => {
|
|
783
|
+
writeWranglerConfig();
|
|
784
|
+
const keys = [{ name: "key-1" }, { name: "key-2" }, { name: "key-3" }];
|
|
785
|
+
mockKeyListRequest("bound-id", keys);
|
|
730
786
|
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
787
|
+
await runWrangler("kv:key list --binding someBinding");
|
|
788
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
789
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
734
790
|
"[
|
|
735
791
|
{
|
|
736
792
|
\\"name\\": \\"key-1\\"
|
|
@@ -743,15 +799,15 @@ describe("wrangler", () => {
|
|
|
743
799
|
}
|
|
744
800
|
]"
|
|
745
801
|
`);
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
802
|
+
});
|
|
803
|
+
|
|
804
|
+
it("should list the keys of a preview namespace specified by binding", async () => {
|
|
805
|
+
writeWranglerConfig();
|
|
806
|
+
const keys = [{ name: "key-1" }, { name: "key-2" }, { name: "key-3" }];
|
|
807
|
+
mockKeyListRequest("preview-bound-id", keys);
|
|
808
|
+
await runWrangler("kv:key list --binding someBinding --preview");
|
|
809
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
810
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
755
811
|
"[
|
|
756
812
|
{
|
|
757
813
|
\\"name\\": \\"key-1\\"
|
|
@@ -764,17 +820,17 @@ describe("wrangler", () => {
|
|
|
764
820
|
}
|
|
765
821
|
]"
|
|
766
822
|
`);
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
823
|
+
});
|
|
824
|
+
|
|
825
|
+
it("should list the keys of a namespace specified by binding, in a given environment", async () => {
|
|
826
|
+
writeWranglerConfig();
|
|
827
|
+
const keys = [{ name: "key-1" }, { name: "key-2" }, { name: "key-3" }];
|
|
828
|
+
mockKeyListRequest("env-bound-id", keys);
|
|
829
|
+
await runWrangler(
|
|
830
|
+
"kv:key list --binding someBinding --env some-environment"
|
|
831
|
+
);
|
|
832
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
833
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
778
834
|
"[
|
|
779
835
|
{
|
|
780
836
|
\\"name\\": \\"key-1\\"
|
|
@@ -787,17 +843,17 @@ describe("wrangler", () => {
|
|
|
787
843
|
}
|
|
788
844
|
]"
|
|
789
845
|
`);
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
846
|
+
});
|
|
847
|
+
|
|
848
|
+
it("should list the keys of a preview namespace specified by binding, in a given environment", async () => {
|
|
849
|
+
writeWranglerConfig();
|
|
850
|
+
const keys = [{ name: "key-1" }, { name: "key-2" }, { name: "key-3" }];
|
|
851
|
+
mockKeyListRequest("preview-env-bound-id", keys);
|
|
852
|
+
await runWrangler(
|
|
853
|
+
"kv:key list --binding someBinding --preview --env some-environment"
|
|
854
|
+
);
|
|
855
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
856
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
801
857
|
"[
|
|
802
858
|
{
|
|
803
859
|
\\"name\\": \\"key-1\\"
|
|
@@ -810,138 +866,195 @@ describe("wrangler", () => {
|
|
|
810
866
|
}
|
|
811
867
|
]"
|
|
812
868
|
`);
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
869
|
+
});
|
|
870
|
+
|
|
871
|
+
// We'll run the next test with variations on the cursor
|
|
872
|
+
// that's returned on cloudflare's API after all results
|
|
873
|
+
// have been drained.
|
|
874
|
+
for (const blankCursorValue of [undefined, null, ""] as [
|
|
875
|
+
undefined,
|
|
876
|
+
null,
|
|
877
|
+
""
|
|
878
|
+
]) {
|
|
879
|
+
describe(`cursor - ${blankCursorValue}`, () => {
|
|
880
|
+
it("should make multiple requests for paginated results", async () => {
|
|
881
|
+
// Create a lot of mock keys, so that the fetch requests will be paginated
|
|
882
|
+
const keys: NamespaceKeyInfo[] = [];
|
|
883
|
+
for (let i = 0; i < 550; i++) {
|
|
884
|
+
keys.push({ name: "key-" + i });
|
|
885
|
+
}
|
|
886
|
+
// Ask for the keys in pages of size 100.
|
|
887
|
+
const requests = mockKeyListRequest(
|
|
888
|
+
"some-namespace-id",
|
|
889
|
+
keys,
|
|
890
|
+
100,
|
|
891
|
+
blankCursorValue
|
|
892
|
+
);
|
|
893
|
+
await runWrangler("kv:key list --namespace-id some-namespace-id");
|
|
894
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
895
|
+
expect(JSON.parse(std.out)).toEqual(keys);
|
|
896
|
+
expect(requests.count).toEqual(6);
|
|
897
|
+
});
|
|
898
|
+
});
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
it("should error if a given binding name is not in the configured kv namespaces", async () => {
|
|
902
|
+
writeWranglerConfig();
|
|
903
|
+
await expect(
|
|
904
|
+
runWrangler("kv:key list --binding otherBinding")
|
|
905
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
906
|
+
`"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."`
|
|
907
|
+
);
|
|
908
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
853
909
|
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mA namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".[0m
|
|
854
910
|
|
|
855
911
|
"
|
|
856
912
|
`);
|
|
857
|
-
|
|
913
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
858
914
|
"
|
|
859
915
|
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
860
916
|
`);
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
917
|
+
});
|
|
918
|
+
});
|
|
919
|
+
|
|
920
|
+
describe("get", () => {
|
|
921
|
+
afterEach(() => {
|
|
922
|
+
unsetMockFetchKVGetValues();
|
|
923
|
+
});
|
|
924
|
+
|
|
925
|
+
it("should get a key in a given namespace specified by namespace-id", async () => {
|
|
926
|
+
setMockFetchKVGetValue(
|
|
927
|
+
"some-account-id",
|
|
928
|
+
"some-namespace-id",
|
|
929
|
+
"my-key",
|
|
930
|
+
"my-value"
|
|
931
|
+
);
|
|
932
|
+
await runWrangler("kv:key get my-key --namespace-id some-namespace-id");
|
|
933
|
+
expect(proc.write).toEqual(Buffer.from("my-value"));
|
|
934
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
935
|
+
});
|
|
936
|
+
|
|
937
|
+
it("should get a key and decode the value from the response as a utf8 string if the `--text` flag is passed", async () => {
|
|
938
|
+
setMockFetchKVGetValue(
|
|
939
|
+
"some-account-id",
|
|
940
|
+
"some-namespace-id",
|
|
941
|
+
"my-key",
|
|
942
|
+
"my-value"
|
|
943
|
+
);
|
|
944
|
+
await runWrangler(
|
|
945
|
+
"kv:key get my-key --text --namespace-id some-namespace-id"
|
|
946
|
+
);
|
|
947
|
+
expect(proc.write).not.toEqual(Buffer.from("my-value"));
|
|
948
|
+
expect(std).toMatchInlineSnapshot(`
|
|
949
|
+
Object {
|
|
950
|
+
"debug": "",
|
|
951
|
+
"err": "",
|
|
952
|
+
"out": "my-value",
|
|
953
|
+
"warn": "",
|
|
954
|
+
}
|
|
955
|
+
`);
|
|
956
|
+
});
|
|
957
|
+
|
|
958
|
+
it("should get a binary and decode as utf8 text, resulting in improper decoding", async () => {
|
|
959
|
+
const buf = Buffer.from(
|
|
960
|
+
"iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAiSURBVHgB7coxEQAACMPAgH/PgAM6dGwu49fA/deIBXrgAj2cAhIFT4QxAAAAAElFTkSuQmCC",
|
|
961
|
+
"base64"
|
|
962
|
+
);
|
|
963
|
+
setMockFetchKVGetValue(
|
|
964
|
+
"some-account-id",
|
|
965
|
+
"some-namespace-id",
|
|
966
|
+
"my-key",
|
|
967
|
+
buf
|
|
968
|
+
);
|
|
969
|
+
await runWrangler(
|
|
970
|
+
"kv:key get my-key --text --namespace-id some-namespace-id"
|
|
971
|
+
);
|
|
972
|
+
expect(proc.write).not.toEqual(buf);
|
|
973
|
+
expect(JSON.stringify(std)).toMatchInlineSnapshot(
|
|
974
|
+
`"{\\"debug\\":\\"\\",\\"out\\":\\"�PNG\\\\n\\\\u001a\\\\n\\\\u0000\\\\u0000\\\\u0000\\\\rIHDR\\\\u0000\\\\u0000\\\\u0000\\\\n\\\\u0000\\\\u0000\\\\u0000\\\\n\\\\b\\\\u0006\\\\u0000\\\\u0000\\\\u0000�2Ͻ\\\\u0000\\\\u0000\\\\u0000\\\\tpHYs\\\\u0000\\\\u0000\\\\u000b\\\\u0013\\\\u0000\\\\u0000\\\\u000b\\\\u0013\\\\u0001\\\\u0000��\\\\u0018\\\\u0000\\\\u0000\\\\u0000\\\\u0001sRGB\\\\u0000��\\\\u001c�\\\\u0000\\\\u0000\\\\u0000\\\\u0004gAMA\\\\u0000\\\\u0000��\\\\u000b�a\\\\u0005\\\\u0000\\\\u0000\\\\u0000\\\\\\"IDATx\\\\u0001��1\\\\u0011\\\\u0000\\\\u0000\\\\b���π\\\\u0003:tl.����\\\\u0005z�\\\\u0002=�\\\\u0002\\\\u0012\\\\u0005O�1\\\\u0000\\\\u0000\\\\u0000\\\\u0000IEND�B\`�\\",\\"err\\":\\"\\",\\"warn\\":\\"\\"}"`
|
|
975
|
+
);
|
|
976
|
+
});
|
|
977
|
+
|
|
978
|
+
it("should get a binary file by key in a given namespace specified by namespace-id", async () => {
|
|
979
|
+
const buf = Buffer.from(
|
|
980
|
+
"iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAiSURBVHgB7coxEQAACMPAgH/PgAM6dGwu49fA/deIBXrgAj2cAhIFT4QxAAAAAElFTkSuQmCC",
|
|
981
|
+
"base64"
|
|
982
|
+
);
|
|
983
|
+
setMockFetchKVGetValue(
|
|
984
|
+
"some-account-id",
|
|
985
|
+
"some-namespace-id",
|
|
986
|
+
"my-key",
|
|
987
|
+
buf
|
|
988
|
+
);
|
|
989
|
+
await runWrangler("kv:key get my-key --namespace-id some-namespace-id");
|
|
990
|
+
expect(proc.write).toEqual(buf);
|
|
991
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
992
|
+
});
|
|
993
|
+
|
|
994
|
+
it("should get a key in a given namespace specified by binding", async () => {
|
|
995
|
+
writeWranglerConfig();
|
|
996
|
+
setMockFetchKVGetValue(
|
|
997
|
+
"some-account-id",
|
|
998
|
+
"bound-id",
|
|
999
|
+
"my-key",
|
|
1000
|
+
"my-value"
|
|
1001
|
+
);
|
|
1002
|
+
await runWrangler(
|
|
1003
|
+
"kv:key get my-key --binding someBinding --preview false"
|
|
1004
|
+
);
|
|
1005
|
+
expect(proc.write).toEqual(Buffer.from("my-value"));
|
|
1006
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1007
|
+
});
|
|
1008
|
+
|
|
1009
|
+
it("should get a key in a given preview namespace specified by binding", async () => {
|
|
1010
|
+
writeWranglerConfig();
|
|
1011
|
+
setMockFetchKVGetValue(
|
|
1012
|
+
"some-account-id",
|
|
1013
|
+
"preview-bound-id",
|
|
1014
|
+
"my-key",
|
|
1015
|
+
"my-value"
|
|
1016
|
+
);
|
|
1017
|
+
await runWrangler("kv:key get my-key --binding someBinding --preview");
|
|
1018
|
+
expect(proc.write).toEqual(Buffer.from("my-value"));
|
|
1019
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1020
|
+
});
|
|
1021
|
+
|
|
1022
|
+
it("should get a key for the specified environment in a given namespace", async () => {
|
|
1023
|
+
writeWranglerConfig();
|
|
1024
|
+
setMockFetchKVGetValue(
|
|
1025
|
+
"some-account-id",
|
|
1026
|
+
"env-bound-id",
|
|
1027
|
+
"my-key",
|
|
1028
|
+
"my-value"
|
|
1029
|
+
);
|
|
1030
|
+
await runWrangler(
|
|
1031
|
+
"kv:key get my-key --binding someBinding --env some-environment --preview false"
|
|
1032
|
+
);
|
|
1033
|
+
expect(proc.write).toEqual(Buffer.from("my-value"));
|
|
1034
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1035
|
+
});
|
|
1036
|
+
|
|
1037
|
+
it("should encode the key in the api request to get a value", async () => {
|
|
1038
|
+
setMockFetchKVGetValue(
|
|
1039
|
+
"some-account-id",
|
|
1040
|
+
"some-namespace-id",
|
|
1041
|
+
"%2Fmy%2Ckey",
|
|
1042
|
+
"my-value"
|
|
1043
|
+
);
|
|
1044
|
+
await runWrangler(
|
|
1045
|
+
"kv:key get /my,key --namespace-id some-namespace-id"
|
|
1046
|
+
);
|
|
1047
|
+
expect(proc.write).toEqual(Buffer.from("my-value"));
|
|
1048
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1049
|
+
});
|
|
1050
|
+
|
|
1051
|
+
it("should error if no key is provided", async () => {
|
|
1052
|
+
await expect(
|
|
1053
|
+
runWrangler("kv:key get")
|
|
1054
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
1055
|
+
`"Not enough non-option arguments: got 0, need at least 1"`
|
|
1056
|
+
);
|
|
1057
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
945
1058
|
"
|
|
946
1059
|
wrangler kv:key get <key>
|
|
947
1060
|
|
|
@@ -959,22 +1072,23 @@ describe("wrangler", () => {
|
|
|
959
1072
|
--binding The name of the namespace to get from [string]
|
|
960
1073
|
--namespace-id The id of the namespace to get from [string]
|
|
961
1074
|
-e, --env Perform on a specific environment [string]
|
|
962
|
-
--preview Interact with a preview namespace [boolean] [default: false]
|
|
1075
|
+
--preview Interact with a preview namespace [boolean] [default: false]
|
|
1076
|
+
--text Decode the returned value as a utf8 string [boolean] [default: false]"
|
|
963
1077
|
`);
|
|
964
|
-
|
|
1078
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
965
1079
|
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mNot enough non-option arguments: got 0, need at least 1[0m
|
|
966
1080
|
|
|
967
1081
|
"
|
|
968
1082
|
`);
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
1083
|
+
});
|
|
1084
|
+
|
|
1085
|
+
it("should error if no binding nor namespace is provided", async () => {
|
|
1086
|
+
await expect(
|
|
1087
|
+
runWrangler("kv:key get foo")
|
|
1088
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
1089
|
+
`"Exactly one of the arguments binding and namespace-id is required"`
|
|
1090
|
+
);
|
|
1091
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
978
1092
|
"
|
|
979
1093
|
wrangler kv:key get <key>
|
|
980
1094
|
|
|
@@ -992,23 +1106,24 @@ describe("wrangler", () => {
|
|
|
992
1106
|
--binding The name of the namespace to get from [string]
|
|
993
1107
|
--namespace-id The id of the namespace to get from [string]
|
|
994
1108
|
-e, --env Perform on a specific environment [string]
|
|
995
|
-
--preview Interact with a preview namespace [boolean] [default: false]
|
|
1109
|
+
--preview Interact with a preview namespace [boolean] [default: false]
|
|
1110
|
+
--text Decode the returned value as a utf8 string [boolean] [default: false]"
|
|
996
1111
|
`);
|
|
997
|
-
|
|
1112
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
998
1113
|
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mExactly one of the arguments binding and namespace-id is required[0m
|
|
999
1114
|
|
|
1000
1115
|
"
|
|
1001
1116
|
`);
|
|
1002
|
-
|
|
1117
|
+
});
|
|
1003
1118
|
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1119
|
+
it("should error if both binding and namespace is provided", async () => {
|
|
1120
|
+
await expect(
|
|
1121
|
+
runWrangler("kv:key get foo --binding x --namespace-id y")
|
|
1122
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
1123
|
+
`"Arguments binding and namespace-id are mutually exclusive"`
|
|
1124
|
+
);
|
|
1010
1125
|
|
|
1011
|
-
|
|
1126
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
1012
1127
|
"
|
|
1013
1128
|
wrangler kv:key get <key>
|
|
1014
1129
|
|
|
@@ -1026,241 +1141,295 @@ describe("wrangler", () => {
|
|
|
1026
1141
|
--binding The name of the namespace to get from [string]
|
|
1027
1142
|
--namespace-id The id of the namespace to get from [string]
|
|
1028
1143
|
-e, --env Perform on a specific environment [string]
|
|
1029
|
-
--preview Interact with a preview namespace [boolean] [default: false]
|
|
1144
|
+
--preview Interact with a preview namespace [boolean] [default: false]
|
|
1145
|
+
--text Decode the returned value as a utf8 string [boolean] [default: false]"
|
|
1030
1146
|
`);
|
|
1031
|
-
|
|
1147
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
1032
1148
|
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mArguments binding and namespace-id are mutually exclusive[0m
|
|
1033
1149
|
|
|
1034
1150
|
"
|
|
1035
1151
|
`);
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1152
|
+
});
|
|
1153
|
+
|
|
1154
|
+
it("should error if a given binding name is not in the configured kv namespaces", async () => {
|
|
1155
|
+
writeWranglerConfig();
|
|
1156
|
+
await expect(
|
|
1157
|
+
runWrangler("kv:key get key --binding otherBinding")
|
|
1158
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
1159
|
+
`"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."`
|
|
1160
|
+
);
|
|
1161
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
1046
1162
|
"
|
|
1047
1163
|
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
1048
1164
|
`);
|
|
1049
|
-
|
|
1165
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
1050
1166
|
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mA namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".[0m
|
|
1051
1167
|
|
|
1052
1168
|
"
|
|
1053
1169
|
`);
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1170
|
+
});
|
|
1171
|
+
|
|
1172
|
+
describe("non-interactive", () => {
|
|
1173
|
+
const { setIsTTY } = useMockIsTTY();
|
|
1174
|
+
mockAccountId({ accountId: null });
|
|
1175
|
+
|
|
1176
|
+
it("should error if there are multiple accounts available but not interactive on stdin", async () => {
|
|
1177
|
+
mockGetMemberships([
|
|
1178
|
+
{ id: "xxx", account: { id: "1", name: "one" } },
|
|
1179
|
+
{ id: "yyy", account: { id: "2", name: "two" } },
|
|
1180
|
+
]);
|
|
1181
|
+
setIsTTY({ stdin: false, stdout: true });
|
|
1182
|
+
await expect(runWrangler("kv:key get key --namespace-id=xxxx"))
|
|
1183
|
+
.rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
1184
|
+
"More than one account available but unable to select one in non-interactive mode.
|
|
1185
|
+
Please set the appropriate \`account_id\` in your \`wrangler.toml\` file.
|
|
1186
|
+
Available accounts are (\\"<name>\\" - \\"<id>\\"):
|
|
1187
|
+
\\"one\\" - \\"1\\")
|
|
1188
|
+
\\"two\\" - \\"2\\")"
|
|
1189
|
+
`);
|
|
1190
|
+
});
|
|
1191
|
+
|
|
1192
|
+
it("should error if there are multiple accounts available but not interactive on stdout", async () => {
|
|
1193
|
+
mockGetMemberships([
|
|
1194
|
+
{ id: "xxx", account: { id: "1", name: "one" } },
|
|
1195
|
+
{ id: "yyy", account: { id: "2", name: "two" } },
|
|
1196
|
+
]);
|
|
1197
|
+
setIsTTY({ stdin: true, stdout: false });
|
|
1198
|
+
await expect(runWrangler("kv:key get key --namespace-id=xxxx"))
|
|
1199
|
+
.rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
1200
|
+
"More than one account available but unable to select one in non-interactive mode.
|
|
1201
|
+
Please set the appropriate \`account_id\` in your \`wrangler.toml\` file.
|
|
1202
|
+
Available accounts are (\\"<name>\\" - \\"<id>\\"):
|
|
1203
|
+
\\"one\\" - \\"1\\")
|
|
1204
|
+
\\"two\\" - \\"2\\")"
|
|
1205
|
+
`);
|
|
1206
|
+
});
|
|
1207
|
+
|
|
1208
|
+
it("should error if there are multiple accounts available but not interactive at all", async () => {
|
|
1209
|
+
mockGetMemberships([
|
|
1210
|
+
{ id: "xxx", account: { id: "1", name: "one" } },
|
|
1211
|
+
{ id: "yyy", account: { id: "2", name: "two" } },
|
|
1212
|
+
]);
|
|
1213
|
+
setIsTTY(false);
|
|
1214
|
+
await expect(runWrangler("kv:key get key --namespace-id=xxxx"))
|
|
1215
|
+
.rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
1216
|
+
"More than one account available but unable to select one in non-interactive mode.
|
|
1217
|
+
Please set the appropriate \`account_id\` in your \`wrangler.toml\` file.
|
|
1218
|
+
Available accounts are (\\"<name>\\" - \\"<id>\\"):
|
|
1219
|
+
\\"one\\" - \\"1\\")
|
|
1220
|
+
\\"two\\" - \\"2\\")"
|
|
1221
|
+
`);
|
|
1222
|
+
});
|
|
1223
|
+
});
|
|
1224
|
+
});
|
|
1225
|
+
|
|
1226
|
+
describe("delete", () => {
|
|
1227
|
+
function mockDeleteRequest(
|
|
1228
|
+
expectedNamespaceId: string,
|
|
1229
|
+
expectedKey: string
|
|
1230
|
+
) {
|
|
1231
|
+
const requests = { count: 0 };
|
|
1232
|
+
setMockResponse(
|
|
1233
|
+
"/accounts/:accountId/storage/kv/namespaces/:namespaceId/values/:key",
|
|
1234
|
+
"DELETE",
|
|
1235
|
+
([_url, accountId, namespaceId, key]) => {
|
|
1236
|
+
requests.count++;
|
|
1237
|
+
expect(accountId).toEqual("some-account-id");
|
|
1238
|
+
expect(namespaceId).toEqual(expectedNamespaceId);
|
|
1239
|
+
expect(key).toEqual(expectedKey);
|
|
1240
|
+
return null;
|
|
1241
|
+
}
|
|
1242
|
+
);
|
|
1243
|
+
return requests;
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
it("should delete a key in a namespace specified by id", async () => {
|
|
1247
|
+
const requests = mockDeleteRequest("some-namespace-id", "someKey");
|
|
1248
|
+
await runWrangler(
|
|
1249
|
+
`kv:key delete --namespace-id some-namespace-id someKey`
|
|
1250
|
+
);
|
|
1251
|
+
expect(requests.count).toEqual(1);
|
|
1252
|
+
});
|
|
1253
|
+
|
|
1254
|
+
it("should encode the key in the api request to delete a value", async () => {
|
|
1255
|
+
const requests = mockDeleteRequest("voyager", "%2FNCC-74656");
|
|
1256
|
+
await runWrangler(`kv:key delete --namespace-id voyager /NCC-74656`);
|
|
1257
|
+
expect(requests.count).toEqual(1);
|
|
1258
|
+
expect(std.out).toMatchInlineSnapshot(
|
|
1259
|
+
`"Deleting the key \\"/NCC-74656\\" on namespace voyager."`
|
|
1260
|
+
);
|
|
1261
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1262
|
+
});
|
|
1263
|
+
|
|
1264
|
+
it("should delete a key in a namespace specified by binding name", async () => {
|
|
1265
|
+
writeWranglerConfig();
|
|
1266
|
+
const requests = mockDeleteRequest("bound-id", "someKey");
|
|
1267
|
+
await runWrangler(
|
|
1268
|
+
`kv:key delete --binding someBinding --preview false someKey`
|
|
1269
|
+
);
|
|
1270
|
+
expect(requests.count).toEqual(1);
|
|
1271
|
+
});
|
|
1272
|
+
|
|
1273
|
+
it("should delete a key in a preview namespace specified by binding name", async () => {
|
|
1274
|
+
writeWranglerConfig();
|
|
1275
|
+
const requests = mockDeleteRequest("preview-bound-id", "someKey");
|
|
1276
|
+
await runWrangler(
|
|
1277
|
+
`kv:key delete --binding someBinding --preview someKey`
|
|
1278
|
+
);
|
|
1279
|
+
expect(requests.count).toEqual(1);
|
|
1280
|
+
});
|
|
1281
|
+
|
|
1282
|
+
it("should error if a given binding name is not in the configured kv namespaces", async () => {
|
|
1283
|
+
writeWranglerConfig();
|
|
1284
|
+
await expect(
|
|
1285
|
+
runWrangler(`kv:key delete --binding otherBinding someKey`)
|
|
1286
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
1287
|
+
`"A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."`
|
|
1288
|
+
);
|
|
1289
|
+
|
|
1290
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
1122
1291
|
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mA namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".[0m
|
|
1123
1292
|
|
|
1124
1293
|
"
|
|
1125
1294
|
`);
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1295
|
+
});
|
|
1296
|
+
|
|
1297
|
+
it("should delete a key in a namespace specified by binding name in a given environment", async () => {
|
|
1298
|
+
writeWranglerConfig();
|
|
1299
|
+
const requests = mockDeleteRequest("env-bound-id", "someKey");
|
|
1300
|
+
await runWrangler(
|
|
1301
|
+
`kv:key delete --binding someBinding --env some-environment --preview false someKey`
|
|
1302
|
+
);
|
|
1303
|
+
expect(std.out).toMatchInlineSnapshot(
|
|
1304
|
+
`"Deleting the key \\"someKey\\" on namespace env-bound-id."`
|
|
1305
|
+
);
|
|
1306
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1307
|
+
expect(requests.count).toEqual(1);
|
|
1308
|
+
});
|
|
1309
|
+
|
|
1310
|
+
it("should delete a key in a preview namespace specified by binding name in a given environment", async () => {
|
|
1311
|
+
writeWranglerConfig();
|
|
1312
|
+
const requests = mockDeleteRequest("preview-env-bound-id", "someKey");
|
|
1313
|
+
await runWrangler(
|
|
1314
|
+
`kv:key delete --binding someBinding --env some-environment --preview someKey`
|
|
1315
|
+
);
|
|
1316
|
+
expect(requests.count).toEqual(1);
|
|
1317
|
+
});
|
|
1318
|
+
});
|
|
1319
|
+
});
|
|
1320
|
+
|
|
1321
|
+
describe("kv:bulk", () => {
|
|
1322
|
+
describe("put", () => {
|
|
1323
|
+
function mockPutRequest(
|
|
1324
|
+
expectedNamespaceId: string,
|
|
1325
|
+
expectedKeyValues: KeyValue[]
|
|
1326
|
+
) {
|
|
1327
|
+
const requests = { count: 0 };
|
|
1328
|
+
setMockResponse(
|
|
1329
|
+
"/accounts/:accountId/storage/kv/namespaces/:namespaceId/bulk",
|
|
1330
|
+
"PUT",
|
|
1331
|
+
([_url, accountId, namespaceId], { body }) => {
|
|
1332
|
+
requests.count++;
|
|
1333
|
+
expect(accountId).toEqual("some-account-id");
|
|
1334
|
+
expect(namespaceId).toEqual(expectedNamespaceId);
|
|
1335
|
+
expect(JSON.parse(body as string)).toEqual(
|
|
1336
|
+
expectedKeyValues.slice(
|
|
1337
|
+
(requests.count - 1) * 5000,
|
|
1338
|
+
requests.count * 5000
|
|
1339
|
+
)
|
|
1340
|
+
);
|
|
1341
|
+
return null;
|
|
1342
|
+
}
|
|
1343
|
+
);
|
|
1344
|
+
return requests;
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
it("should put the key-values parsed from a file", async () => {
|
|
1348
|
+
const keyValues: KeyValue[] = [
|
|
1349
|
+
{ key: "someKey1", value: "someValue1" },
|
|
1350
|
+
{ key: "ns:someKey2", value: "123", base64: true },
|
|
1351
|
+
{ key: "someKey3", value: "someValue3", expiration: 100 },
|
|
1352
|
+
{ key: "someKey4", value: "someValue4", expiration_ttl: 500 },
|
|
1353
|
+
];
|
|
1354
|
+
writeFileSync("./keys.json", JSON.stringify(keyValues));
|
|
1355
|
+
const requests = mockPutRequest("some-namespace-id", keyValues);
|
|
1356
|
+
await runWrangler(
|
|
1357
|
+
`kv:bulk put --namespace-id some-namespace-id keys.json`
|
|
1358
|
+
);
|
|
1359
|
+
expect(requests.count).toEqual(1);
|
|
1360
|
+
expect(std.out).toMatchInlineSnapshot(`"Success!"`);
|
|
1361
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1362
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1363
|
+
});
|
|
1364
|
+
|
|
1365
|
+
it("should put the key-values in batches of 5000 parsed from a file", async () => {
|
|
1366
|
+
const keyValues: KeyValue[] = new Array(12000).fill({
|
|
1367
|
+
key: "someKey1",
|
|
1368
|
+
value: "someValue1",
|
|
1369
|
+
});
|
|
1370
|
+
writeFileSync("./keys.json", JSON.stringify(keyValues));
|
|
1371
|
+
const requests = mockPutRequest("some-namespace-id", keyValues);
|
|
1372
|
+
await runWrangler(
|
|
1373
|
+
`kv:bulk put --namespace-id some-namespace-id keys.json`
|
|
1374
|
+
);
|
|
1375
|
+
expect(requests.count).toEqual(3);
|
|
1376
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
1208
1377
|
"Uploaded 0% (0 out of 12,000)
|
|
1209
1378
|
Uploaded 41% (5,000 out of 12,000)
|
|
1210
1379
|
Uploaded 83% (10,000 out of 12,000)
|
|
1211
1380
|
Uploaded 100% (12,000 out of 12,000)
|
|
1212
1381
|
Success!"
|
|
1213
1382
|
`);
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1383
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1384
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1385
|
+
});
|
|
1386
|
+
|
|
1387
|
+
it("should error if the file is not a JSON array", async () => {
|
|
1388
|
+
const keyValues = { key: "someKey1", value: "someValue1" };
|
|
1389
|
+
writeFileSync("./keys.json", JSON.stringify(keyValues));
|
|
1390
|
+
await expect(
|
|
1391
|
+
runWrangler(`kv:bulk put --namespace-id some-namespace-id keys.json`)
|
|
1392
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
1224
1393
|
"Unexpected JSON input from \\"keys.json\\".
|
|
1225
1394
|
Expected an array of key-value objects but got type \\"object\\"."
|
|
1226
1395
|
`);
|
|
1227
|
-
|
|
1396
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
1228
1397
|
"
|
|
1229
1398
|
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
1230
1399
|
`);
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1400
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1401
|
+
});
|
|
1402
|
+
|
|
1403
|
+
it("should error if the array contains items that are not key-value objects", async () => {
|
|
1404
|
+
const keyValues = [
|
|
1405
|
+
123,
|
|
1406
|
+
"a string",
|
|
1407
|
+
{ key: "someKey" },
|
|
1408
|
+
{ value: "someValue" },
|
|
1409
|
+
// add a valid object here to make sure it's not included
|
|
1410
|
+
{ key: "someKey1", value: "someValue1" },
|
|
1411
|
+
// this one will only add a warning
|
|
1412
|
+
{ key: "someKey1", value: "someValue1", invalid: true },
|
|
1413
|
+
// back to the invalid ones
|
|
1414
|
+
{ key: 123, value: "somevalue" },
|
|
1415
|
+
{ key: "somekey", value: 123 },
|
|
1416
|
+
{ key: "someKey1", value: "someValue1", expiration: "string" },
|
|
1417
|
+
{ key: "someKey1", value: "someValue1", expiration_ttl: "string" },
|
|
1418
|
+
{
|
|
1419
|
+
key: 123,
|
|
1420
|
+
value: {
|
|
1421
|
+
a: {
|
|
1422
|
+
nested: "object",
|
|
1423
|
+
},
|
|
1424
|
+
},
|
|
1425
|
+
},
|
|
1426
|
+
{ key: "someKey1", value: "someValue1", metadata: 123 },
|
|
1427
|
+
{ key: "someKey1", value: "someValue1", base64: "string" },
|
|
1428
|
+
];
|
|
1429
|
+
writeFileSync("./keys.json", JSON.stringify(keyValues));
|
|
1430
|
+
await expect(
|
|
1431
|
+
runWrangler(`kv:bulk put --namespace-id some-namespace-id keys.json`)
|
|
1432
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
1264
1433
|
"Unexpected JSON input from \\"keys.json\\".
|
|
1265
1434
|
Each item in the array should be an object that matches:
|
|
1266
1435
|
|
|
@@ -1286,196 +1455,196 @@ describe("wrangler", () => {
|
|
|
1286
1455
|
The item at index 12 is {\\"key\\":\\"someKey1\\",\\"value\\":\\"someValue1\\",\\"base64\\":\\"string\\"}"
|
|
1287
1456
|
`);
|
|
1288
1457
|
|
|
1289
|
-
|
|
1458
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
1290
1459
|
"
|
|
1291
1460
|
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
1292
1461
|
`);
|
|
1293
|
-
|
|
1462
|
+
expect(std.warn).toMatchInlineSnapshot(`
|
|
1294
1463
|
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mUnexpected key-value properties in \\"keys.json\\".[0m
|
|
1295
1464
|
|
|
1296
1465
|
The item at index 5 contains unexpected properties: [\\"invalid\\"].
|
|
1297
1466
|
|
|
1298
1467
|
"
|
|
1299
1468
|
`);
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1469
|
+
});
|
|
1470
|
+
});
|
|
1471
|
+
|
|
1472
|
+
describe("delete", () => {
|
|
1473
|
+
function mockDeleteRequest(
|
|
1474
|
+
expectedNamespaceId: string,
|
|
1475
|
+
expectedKeys: string[]
|
|
1476
|
+
) {
|
|
1477
|
+
const requests = { count: 0 };
|
|
1478
|
+
setMockResponse(
|
|
1479
|
+
"/accounts/:accountId/storage/kv/namespaces/:namespaceId/bulk",
|
|
1480
|
+
"DELETE",
|
|
1481
|
+
([_url, accountId, namespaceId], { headers, body }) => {
|
|
1482
|
+
requests.count++;
|
|
1483
|
+
expect(accountId).toEqual("some-account-id");
|
|
1484
|
+
expect(namespaceId).toEqual(expectedNamespaceId);
|
|
1485
|
+
expect(new Headers(headers ?? []).get("Content-Type")).toEqual(
|
|
1486
|
+
"application/json"
|
|
1487
|
+
);
|
|
1488
|
+
expect(JSON.parse(body as string)).toEqual(
|
|
1489
|
+
expectedKeys.slice(
|
|
1490
|
+
(requests.count - 1) * 5000,
|
|
1491
|
+
requests.count * 5000
|
|
1492
|
+
)
|
|
1493
|
+
);
|
|
1494
|
+
return null;
|
|
1495
|
+
}
|
|
1496
|
+
);
|
|
1497
|
+
return requests;
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
it("should delete the keys parsed from a file", async () => {
|
|
1501
|
+
const keys = ["someKey1", "ns:someKey2"];
|
|
1502
|
+
writeFileSync("./keys.json", JSON.stringify(keys));
|
|
1503
|
+
mockConfirm({
|
|
1504
|
+
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace with id "some-namespace-id"?`,
|
|
1505
|
+
result: true,
|
|
1506
|
+
});
|
|
1507
|
+
const requests = mockDeleteRequest("some-namespace-id", keys);
|
|
1508
|
+
await runWrangler(
|
|
1509
|
+
`kv:bulk delete --namespace-id some-namespace-id keys.json`
|
|
1510
|
+
);
|
|
1511
|
+
expect(requests.count).toEqual(1);
|
|
1512
|
+
expect(std.out).toMatchInlineSnapshot(`"Success!"`);
|
|
1513
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1514
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1515
|
+
});
|
|
1516
|
+
|
|
1517
|
+
it("should delete the keys in batches of 5000 parsed from a file", async () => {
|
|
1518
|
+
const keys = new Array(12000).fill("some-key");
|
|
1519
|
+
writeFileSync("./keys.json", JSON.stringify(keys));
|
|
1520
|
+
mockConfirm({
|
|
1521
|
+
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace with id "some-namespace-id"?`,
|
|
1522
|
+
result: true,
|
|
1523
|
+
});
|
|
1524
|
+
const requests = mockDeleteRequest("some-namespace-id", keys);
|
|
1525
|
+
await runWrangler(
|
|
1526
|
+
`kv:bulk delete --namespace-id some-namespace-id keys.json`
|
|
1527
|
+
);
|
|
1528
|
+
expect(requests.count).toEqual(3);
|
|
1529
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
1361
1530
|
"Deleted 0% (0 out of 12,000)
|
|
1362
1531
|
Deleted 41% (5,000 out of 12,000)
|
|
1363
1532
|
Deleted 83% (10,000 out of 12,000)
|
|
1364
1533
|
Deleted 100% (12,000 out of 12,000)
|
|
1365
1534
|
Success!"
|
|
1366
1535
|
`);
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1536
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1537
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1538
|
+
});
|
|
1539
|
+
|
|
1540
|
+
it("should not delete the keys if the user confirms no", async () => {
|
|
1541
|
+
const keys = ["someKey1", "ns:someKey2"];
|
|
1542
|
+
writeFileSync("./keys.json", JSON.stringify(keys));
|
|
1543
|
+
mockConfirm({
|
|
1544
|
+
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace with id "some-namespace-id"?`,
|
|
1545
|
+
result: false,
|
|
1546
|
+
});
|
|
1547
|
+
await runWrangler(
|
|
1548
|
+
`kv:bulk delete --namespace-id some-namespace-id keys.json`
|
|
1549
|
+
);
|
|
1550
|
+
expect(std.out).toMatchInlineSnapshot(
|
|
1551
|
+
`"Not deleting keys read from \\"keys.json\\"."`
|
|
1552
|
+
);
|
|
1553
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1554
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1555
|
+
});
|
|
1556
|
+
|
|
1557
|
+
it("should delete the keys without asking if --force is provided", async () => {
|
|
1558
|
+
const keys = ["someKey1", "ns:someKey2"];
|
|
1559
|
+
writeFileSync("./keys.json", JSON.stringify(keys));
|
|
1560
|
+
const requests = mockDeleteRequest("some-namespace-id", keys);
|
|
1561
|
+
await runWrangler(
|
|
1562
|
+
`kv:bulk delete --namespace-id some-namespace-id keys.json --force`
|
|
1563
|
+
);
|
|
1564
|
+
expect(requests.count).toEqual(1);
|
|
1565
|
+
expect(std.out).toMatchInlineSnapshot(`"Success!"`);
|
|
1566
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1567
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1568
|
+
});
|
|
1569
|
+
|
|
1570
|
+
it("should delete the keys without asking if -f is provided", async () => {
|
|
1571
|
+
const keys = ["someKey1", "ns:someKey2"];
|
|
1572
|
+
writeFileSync("./keys.json", JSON.stringify(keys));
|
|
1573
|
+
const requests = mockDeleteRequest("some-namespace-id", keys);
|
|
1574
|
+
await runWrangler(
|
|
1575
|
+
`kv:bulk delete --namespace-id some-namespace-id keys.json -f`
|
|
1576
|
+
);
|
|
1577
|
+
expect(requests.count).toEqual(1);
|
|
1578
|
+
expect(std.out).toMatchInlineSnapshot(`"Success!"`);
|
|
1579
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1580
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
1581
|
+
});
|
|
1582
|
+
|
|
1583
|
+
it("should error if the file is not a JSON array", async () => {
|
|
1584
|
+
const keys = 12354;
|
|
1585
|
+
writeFileSync("./keys.json", JSON.stringify(keys));
|
|
1586
|
+
mockConfirm({
|
|
1587
|
+
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace with id "some-namespace-id"?`,
|
|
1588
|
+
result: true,
|
|
1589
|
+
});
|
|
1590
|
+
await expect(
|
|
1591
|
+
runWrangler(
|
|
1592
|
+
`kv:bulk delete --namespace-id some-namespace-id keys.json`
|
|
1593
|
+
)
|
|
1594
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
1426
1595
|
"Unexpected JSON input from \\"keys.json\\".
|
|
1427
1596
|
Expected an array of strings but got:
|
|
1428
1597
|
12354"
|
|
1429
1598
|
`);
|
|
1430
|
-
|
|
1599
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
1431
1600
|
"
|
|
1432
1601
|
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
1433
1602
|
`);
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1603
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1604
|
+
});
|
|
1605
|
+
|
|
1606
|
+
it("should error if the file contains non-string items", async () => {
|
|
1607
|
+
const keys = ["good", 12354, { key: "someKey" }, null];
|
|
1608
|
+
writeFileSync("./keys.json", JSON.stringify(keys));
|
|
1609
|
+
mockConfirm({
|
|
1610
|
+
text: `Are you sure you want to delete all the keys read from "keys.json" from kv-namespace with id "some-namespace-id"?`,
|
|
1611
|
+
result: true,
|
|
1612
|
+
});
|
|
1613
|
+
await expect(
|
|
1614
|
+
runWrangler(
|
|
1615
|
+
`kv:bulk delete --namespace-id some-namespace-id keys.json`
|
|
1616
|
+
)
|
|
1617
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
1449
1618
|
"Unexpected JSON input from \\"keys.json\\".
|
|
1450
1619
|
Expected an array of strings.
|
|
1451
1620
|
The item at index 1 is type: \\"number\\" - 12354
|
|
1452
1621
|
The item at index 2 is type: \\"object\\" - {\\"key\\":\\"someKey\\"}
|
|
1453
1622
|
The item at index 3 is type: \\"object\\" - null"
|
|
1454
1623
|
`);
|
|
1455
|
-
|
|
1624
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
1456
1625
|
"
|
|
1457
1626
|
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose[0m"
|
|
1458
1627
|
`);
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1628
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
1629
|
+
});
|
|
1630
|
+
});
|
|
1631
|
+
});
|
|
1463
1632
|
});
|
|
1464
1633
|
|
|
1465
1634
|
function writeWranglerConfig() {
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1635
|
+
writeFileSync(
|
|
1636
|
+
"./wrangler.toml",
|
|
1637
|
+
[
|
|
1638
|
+
'name = "other-worker"',
|
|
1639
|
+
"kv_namespaces = [",
|
|
1640
|
+
' { binding = "someBinding", id = "bound-id", preview_id = "preview-bound-id" }',
|
|
1641
|
+
"]",
|
|
1642
|
+
"",
|
|
1643
|
+
"[env.some-environment]",
|
|
1644
|
+
"kv_namespaces = [",
|
|
1645
|
+
' { binding = "someBinding", id = "env-bound-id", preview_id = "preview-env-bound-id" }',
|
|
1646
|
+
"]",
|
|
1647
|
+
].join("\n"),
|
|
1648
|
+
"utf-8"
|
|
1649
|
+
);
|
|
1481
1650
|
}
|