|
| 1 | +import { strict as assert } from "node:assert"; |
| 2 | +import XDELEX, { XDELEX_REPLY_CODES, XDelexPolicy } from "./XDELEX"; |
| 3 | +import { parseArgs } from "./generic-transformers"; |
| 4 | +import testUtils, { GLOBAL } from "../test-utils"; |
| 5 | + |
| 6 | +describe("XDELEX", () => { |
| 7 | + describe("transformArguments", () => { |
| 8 | + it("string - without policy", () => { |
| 9 | + assert.deepEqual(parseArgs(XDELEX, "key", "0-0"), [ |
| 10 | + "XDELEX", |
| 11 | + "key", |
| 12 | + "IDS", |
| 13 | + "1", |
| 14 | + "0-0", |
| 15 | + ]); |
| 16 | + }); |
| 17 | + |
| 18 | + it("string - with policy", () => { |
| 19 | + assert.deepEqual(parseArgs(XDELEX, "key", "0-0", XDelexPolicy.KEEPREF), [ |
| 20 | + "XDELEX", |
| 21 | + "key", |
| 22 | + "KEEPREF", |
| 23 | + "IDS", |
| 24 | + "1", |
| 25 | + "0-0", |
| 26 | + ]); |
| 27 | + }); |
| 28 | + |
| 29 | + it("array - without policy", () => { |
| 30 | + assert.deepEqual(parseArgs(XDELEX, "key", ["0-0", "1-0"]), [ |
| 31 | + "XDELEX", |
| 32 | + "key", |
| 33 | + "IDS", |
| 34 | + "2", |
| 35 | + "0-0", |
| 36 | + "1-0", |
| 37 | + ]); |
| 38 | + }); |
| 39 | + |
| 40 | + it("array - with policy", () => { |
| 41 | + assert.deepEqual( |
| 42 | + parseArgs(XDELEX, "key", ["0-0", "1-0"], XDelexPolicy.DELREF), |
| 43 | + ["XDELEX", "key", "DELREF", "IDS", "2", "0-0", "1-0"] |
| 44 | + ); |
| 45 | + }); |
| 46 | + }); |
| 47 | + |
| 48 | + testUtils.testAll( |
| 49 | + `XDELEX non-existing key - without policy`, |
| 50 | + async (client) => { |
| 51 | + const reply = await client.xDelex("{tag}stream-key", "0-0"); |
| 52 | + assert.deepEqual(reply, [XDELEX_REPLY_CODES.NOT_FOUND]); |
| 53 | + }, |
| 54 | + { |
| 55 | + client: { ...GLOBAL.SERVERS.OPEN, minimumDockerVersion: [8, 2] }, |
| 56 | + cluster: { ...GLOBAL.CLUSTERS.OPEN, minimumDockerVersion: [8, 2] }, |
| 57 | + } |
| 58 | + ); |
| 59 | + |
| 60 | + testUtils.testAll( |
| 61 | + `XDELEX existing key - without policy`, |
| 62 | + async (client) => { |
| 63 | + const streamKey = "{tag}stream-key"; |
| 64 | + const messageId = await client.xAdd(streamKey, "*", { |
| 65 | + field: "value", |
| 66 | + }); |
| 67 | + |
| 68 | + const reply = await client.xDelex( |
| 69 | + streamKey, |
| 70 | + messageId, |
| 71 | + XDelexPolicy.KEEPREF |
| 72 | + ); |
| 73 | + assert.deepEqual(reply, [XDELEX_REPLY_CODES.DELETED]); |
| 74 | + }, |
| 75 | + { |
| 76 | + client: { ...GLOBAL.SERVERS.OPEN, minimumDockerVersion: [8, 2] }, |
| 77 | + cluster: { ...GLOBAL.CLUSTERS.OPEN, minimumDockerVersion: [8, 2] }, |
| 78 | + } |
| 79 | + ); |
| 80 | + |
| 81 | + testUtils.testAll( |
| 82 | + `XDELEX existing key - with policy`, |
| 83 | + async (client) => { |
| 84 | + const streamKey = "{tag}stream-key"; |
| 85 | + const messageId = await client.xAdd(streamKey, "*", { |
| 86 | + field: "value", |
| 87 | + }); |
| 88 | + |
| 89 | + const reply = await client.xDelex( |
| 90 | + streamKey, |
| 91 | + messageId, |
| 92 | + XDelexPolicy.DELREF |
| 93 | + ); |
| 94 | + assert.deepEqual(reply, [XDELEX_REPLY_CODES.DELETED]); |
| 95 | + }, |
| 96 | + { |
| 97 | + client: { ...GLOBAL.SERVERS.OPEN, minimumDockerVersion: [8, 2] }, |
| 98 | + cluster: { ...GLOBAL.CLUSTERS.OPEN, minimumDockerVersion: [8, 2] }, |
| 99 | + } |
| 100 | + ); |
| 101 | + |
| 102 | + testUtils.testAll( |
| 103 | + `XDELEX acknowledge policy - with consumer group`, |
| 104 | + async (client) => { |
| 105 | + const streamKey = "{tag}stream-key"; |
| 106 | + |
| 107 | + // Add a message to the stream |
| 108 | + const messageId = await client.xAdd(streamKey, "*", { |
| 109 | + field: "value", |
| 110 | + }); |
| 111 | + |
| 112 | + // Create consumer group |
| 113 | + await client.xGroupCreate(streamKey, "testgroup", "0"); |
| 114 | + |
| 115 | + const reply = await client.xDelex( |
| 116 | + streamKey, |
| 117 | + messageId, |
| 118 | + XDelexPolicy.ACKED |
| 119 | + ); |
| 120 | + assert.deepEqual(reply, [XDELEX_REPLY_CODES.DANGLING_REFS]); |
| 121 | + }, |
| 122 | + { |
| 123 | + client: { ...GLOBAL.SERVERS.OPEN, minimumDockerVersion: [8, 2] }, |
| 124 | + cluster: { ...GLOBAL.CLUSTERS.OPEN, minimumDockerVersion: [8, 2] }, |
| 125 | + } |
| 126 | + ); |
| 127 | + |
| 128 | + testUtils.testAll( |
| 129 | + `XDELEX multiple keys`, |
| 130 | + async (client) => { |
| 131 | + const streamKey = "{tag}stream-key"; |
| 132 | + const messageIds = await Promise.all([ |
| 133 | + client.xAdd(streamKey, "*", { |
| 134 | + field: "value1", |
| 135 | + }), |
| 136 | + client.xAdd(streamKey, "*", { |
| 137 | + field: "value2", |
| 138 | + }), |
| 139 | + ]); |
| 140 | + |
| 141 | + const reply = await client.xDelex( |
| 142 | + streamKey, |
| 143 | + [...messageIds, "0-0"], |
| 144 | + XDelexPolicy.DELREF |
| 145 | + ); |
| 146 | + assert.deepEqual(reply, [ |
| 147 | + XDELEX_REPLY_CODES.DELETED, |
| 148 | + XDELEX_REPLY_CODES.DELETED, |
| 149 | + XDELEX_REPLY_CODES.NOT_FOUND, |
| 150 | + ]); |
| 151 | + }, |
| 152 | + { |
| 153 | + client: { ...GLOBAL.SERVERS.OPEN, minimumDockerVersion: [8, 2] }, |
| 154 | + cluster: { ...GLOBAL.CLUSTERS.OPEN, minimumDockerVersion: [8, 2] }, |
| 155 | + } |
| 156 | + ); |
| 157 | +}); |
0 commit comments