|
| 1 | +import { strict as assert } from "node:assert"; |
| 2 | +import DELEX, { DelexCondition } from "./DELEX"; |
| 3 | +import { parseArgs } from "./generic-transformers"; |
| 4 | +import testUtils, { GLOBAL } from "../test-utils"; |
| 5 | + |
| 6 | +describe("DELEX", () => { |
| 7 | + describe("transformArguments", () => { |
| 8 | + it("no condition", () => { |
| 9 | + assert.deepEqual(parseArgs(DELEX, "key"), ["DELEX", "key"]); |
| 10 | + }); |
| 11 | + |
| 12 | + it("with condition", () => { |
| 13 | + assert.deepEqual( |
| 14 | + parseArgs(DELEX, "key", { |
| 15 | + condition: DelexCondition.IFEQ, |
| 16 | + matchValue: "some-value", |
| 17 | + }), |
| 18 | + ["DELEX", "key", "IFEQ", "some-value"] |
| 19 | + ); |
| 20 | + }); |
| 21 | + }); |
| 22 | + |
| 23 | + testUtils.testAll( |
| 24 | + "non-existing key", |
| 25 | + async (client) => { |
| 26 | + assert.equal(await client.delEx("key{tag}"), 0); |
| 27 | + }, |
| 28 | + { |
| 29 | + client: { ...GLOBAL.SERVERS.OPEN, minimumDockerVersion: [8, 4] }, |
| 30 | + cluster: { ...GLOBAL.CLUSTERS.OPEN, minimumDockerVersion: [8, 4] }, |
| 31 | + } |
| 32 | + ); |
| 33 | + |
| 34 | + testUtils.testAll( |
| 35 | + "non-existing key with condition", |
| 36 | + async (client) => { |
| 37 | + assert.equal( |
| 38 | + await client.delEx("key{tag}", { |
| 39 | + condition: DelexCondition.IFDEQ, |
| 40 | + matchValue: "digest", |
| 41 | + }), |
| 42 | + 0 |
| 43 | + ); |
| 44 | + }, |
| 45 | + { |
| 46 | + client: { ...GLOBAL.SERVERS.OPEN, minimumDockerVersion: [8, 4] }, |
| 47 | + cluster: { ...GLOBAL.CLUSTERS.OPEN, minimumDockerVersion: [8, 4] }, |
| 48 | + } |
| 49 | + ); |
| 50 | + |
| 51 | + testUtils.testAll( |
| 52 | + "existing key no condition", |
| 53 | + async (client) => { |
| 54 | + await client.set("key{tag}", "value"); |
| 55 | + assert.equal(await client.delEx("key{tag}"), 1); |
| 56 | + }, |
| 57 | + { |
| 58 | + client: { ...GLOBAL.SERVERS.OPEN, minimumDockerVersion: [8, 4] }, |
| 59 | + cluster: { ...GLOBAL.CLUSTERS.OPEN, minimumDockerVersion: [8, 4] }, |
| 60 | + } |
| 61 | + ); |
| 62 | + |
| 63 | + testUtils.testAll( |
| 64 | + "existing key and condition", |
| 65 | + async (client) => { |
| 66 | + await client.set("key{tag}", "some-value"); |
| 67 | + |
| 68 | + assert.equal( |
| 69 | + await client.delEx("key{tag}", { |
| 70 | + condition: DelexCondition.IFEQ, |
| 71 | + matchValue: "some-value", |
| 72 | + }), |
| 73 | + 1 |
| 74 | + ); |
| 75 | + }, |
| 76 | + { |
| 77 | + client: { ...GLOBAL.SERVERS.OPEN, minimumDockerVersion: [8, 4] }, |
| 78 | + cluster: { ...GLOBAL.CLUSTERS.OPEN, minimumDockerVersion: [8, 4] }, |
| 79 | + } |
| 80 | + ); |
| 81 | +}); |
0 commit comments