|
1 | 1 | import { writeFileSync } from "node:fs";
|
2 | 2 | import { http, HttpResponse } from "msw";
|
| 3 | +import { BATCH_MAX_ERRORS_WARNINGS } from "../kv/helpers"; |
3 | 4 | import { endEventLoop } from "./helpers/end-event-loop";
|
4 | 5 | import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
|
5 | 6 | import { mockConsoleMethods } from "./helpers/mock-console";
|
@@ -1609,6 +1610,79 @@ describe("wrangler", () => {
|
1609 | 1610 | "
|
1610 | 1611 | `);
|
1611 | 1612 | });
|
| 1613 | + |
| 1614 | + it("should cap the number of errors", async () => { |
| 1615 | + const keyValues = [...Array(BATCH_MAX_ERRORS_WARNINGS + 5).keys()]; |
| 1616 | + |
| 1617 | + writeFileSync("./keys.json", JSON.stringify(keyValues)); |
| 1618 | + await expect( |
| 1619 | + runWrangler(`kv bulk put --namespace-id some-namespace-id keys.json`) |
| 1620 | + ).rejects.toThrowErrorMatchingInlineSnapshot(` |
| 1621 | + [Error: Unexpected JSON input from "keys.json". |
| 1622 | + Each item in the array should be an object that matches: |
| 1623 | +
|
| 1624 | + interface KeyValue { |
| 1625 | + key: string; |
| 1626 | + value: string; |
| 1627 | + expiration?: number; |
| 1628 | + expiration_ttl?: number; |
| 1629 | + metadata?: object; |
| 1630 | + base64?: boolean; |
| 1631 | + } |
| 1632 | +
|
| 1633 | + The item at index 0 is 0 |
| 1634 | + The item at index 1 is 1 |
| 1635 | + The item at index 2 is 2 |
| 1636 | + The item at index 3 is 3 |
| 1637 | + The item at index 4 is 4 |
| 1638 | + The item at index 5 is 5 |
| 1639 | + The item at index 6 is 6 |
| 1640 | + The item at index 7 is 7 |
| 1641 | + The item at index 8 is 8 |
| 1642 | + The item at index 9 is 9 |
| 1643 | + The item at index 10 is 10 |
| 1644 | + The item at index 11 is 11 |
| 1645 | + ...] |
| 1646 | + `); |
| 1647 | + |
| 1648 | + expect(std.warn).toMatchInlineSnapshot(`""`); |
| 1649 | + }); |
| 1650 | + |
| 1651 | + it("should cap the number of warnings", async () => { |
| 1652 | + const keyValues: KeyValue[] = new Array( |
| 1653 | + BATCH_MAX_ERRORS_WARNINGS + 5 |
| 1654 | + ).fill({ |
| 1655 | + key: "k", |
| 1656 | + value: "v", |
| 1657 | + invalid: true, |
| 1658 | + }); |
| 1659 | + writeFileSync("./keys.json", JSON.stringify(keyValues)); |
| 1660 | + const requests = mockPutRequest("some-namespace-id", keyValues); |
| 1661 | + await runWrangler( |
| 1662 | + `kv bulk put --namespace-id some-namespace-id keys.json` |
| 1663 | + ); |
| 1664 | + expect(requests.count).toEqual(1); |
| 1665 | + |
| 1666 | + expect(std.warn).toMatchInlineSnapshot(` |
| 1667 | + "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mUnexpected key-value properties in \\"keys.json\\".[0m |
| 1668 | +
|
| 1669 | + The item at index 0 contains unexpected properties: [\\"invalid\\"]. |
| 1670 | + The item at index 1 contains unexpected properties: [\\"invalid\\"]. |
| 1671 | + The item at index 2 contains unexpected properties: [\\"invalid\\"]. |
| 1672 | + The item at index 3 contains unexpected properties: [\\"invalid\\"]. |
| 1673 | + The item at index 4 contains unexpected properties: [\\"invalid\\"]. |
| 1674 | + The item at index 5 contains unexpected properties: [\\"invalid\\"]. |
| 1675 | + The item at index 6 contains unexpected properties: [\\"invalid\\"]. |
| 1676 | + The item at index 7 contains unexpected properties: [\\"invalid\\"]. |
| 1677 | + The item at index 8 contains unexpected properties: [\\"invalid\\"]. |
| 1678 | + The item at index 9 contains unexpected properties: [\\"invalid\\"]. |
| 1679 | + The item at index 10 contains unexpected properties: [\\"invalid\\"]. |
| 1680 | + The item at index 11 contains unexpected properties: [\\"invalid\\"]. |
| 1681 | + ... |
| 1682 | +
|
| 1683 | + " |
| 1684 | + `); |
| 1685 | + }); |
1612 | 1686 | });
|
1613 | 1687 |
|
1614 | 1688 | describe("delete", () => {
|
|
0 commit comments