From 61b6135e6a2d01f7f8f403ae03e17ce5fa7dfea4 Mon Sep 17 00:00:00 2001 From: Sam Mayer Date: Fri, 8 Nov 2024 13:06:46 -0600 Subject: [PATCH] Break up large test file --- src/lib/filter/adjudicators.test.ts | 743 +++--------------- .../adjudicators/bindingAdjudicators.test.ts | 682 ++++++++++++++++ 2 files changed, 813 insertions(+), 612 deletions(-) create mode 100644 src/lib/filter/adjudicators/bindingAdjudicators.test.ts diff --git a/src/lib/filter/adjudicators.test.ts b/src/lib/filter/adjudicators.test.ts index 2550f279d..4b2ae42db 100644 --- a/src/lib/filter/adjudicators.test.ts +++ b/src/lib/filter/adjudicators.test.ts @@ -7,40 +7,6 @@ import { GroupVersionKind, KubernetesObject } from "kubernetes-fluent-client"; import { AdmissionRequest, Binding, DeepPartial } from "../types"; import { Event, Operation } from "../enums"; -describe("definesDeletionTimestamp", () => { - //[ Binding, result ] - it.each([ - [{}, false], - [{ filters: {} }, false], - [{ filters: { deletionTimestamp: null } }, false], - [{ filters: { deletionTimestamp: false } }, false], - [{ filters: { deletionTimestamp: true } }, true], - ])("given %j, returns %s", (given, expected) => { - const binding = given as DeepPartial; - - const result = sut.definesDeletionTimestamp(binding); - - expect(result).toBe(expected); - }); -}); - -describe("ignoresDeletionTimestamp", () => { - //[ Binding, result ] - it.each([ - [{}, true], - [{ filters: {} }, true], - [{ filters: { deletionTimestamp: null } }, true], - [{ filters: { deletionTimestamp: false } }, true], - [{ filters: { deletionTimestamp: true } }, false], - ])("given %j, returns %s", (given, expected) => { - const binding = given as DeepPartial; - - const result = sut.ignoresDeletionTimestamp(binding); - - expect(result).toBe(expected); - }); -}); - describe("carriesDeletionTimestamp", () => { //[ KubernetesObject, result ] it.each([ @@ -73,129 +39,57 @@ describe("missingDeletionTimestamp", () => { }); }); -describe("definedName", () => { - //[ Binding, result ] - it.each([ - [{}, ""], - [{ filters: {} }, ""], - [{ filters: { name: null } }, ""], - [{ filters: { name: "name" } }, "name"], - ])("given %j, returns '%s'", (given, expected) => { - const binding = given as DeepPartial; - - const result = sut.definedName(binding); - - expect(result).toBe(expected); - }); -}); - -describe("definesName", () => { - //[ Binding, result ] - it.each([ - [{}, false], - [{ filters: {} }, false], - [{ filters: { name: null } }, false], - [{ filters: { name: "name" } }, true], - ])("given %j, returns %s", (given, expected) => { - const binding = given as DeepPartial; - - const result = sut.definesName(binding); - - expect(result).toBe(expected); - }); -}); - -describe("ignoresName", () => { - //[ Binding, result ] - it.each([ - [{}, true], - [{ filters: {} }, true], - [{ filters: { name: null } }, true], - [{ filters: { name: "name" } }, false], - ])("given %j, returns %s", (given, expected) => { - const binding = given as DeepPartial; - - const result = sut.ignoresName(binding); - - expect(result).toBe(expected); - }); -}); - -describe("definedNameRegex", () => { - //[ Binding, result ] - it.each([ - [{}, ""], - [{ filters: {} }, ""], - [{ filters: { regexName: null } }, ""], - [{ filters: { regexName: "n.me" } }, "n.me"], - ])("given %j, returns '%s'", (given, expected) => { - const binding = given as DeepPartial; - - const result = sut.definedNameRegex(binding); - - expect(result).toBe(expected); - }); -}); - -describe("definesNameRegex", () => { - //[ Binding, result ] +describe("mismatchedDeletionTimestamp", () => { + //[ Binding, KubernetesObject, result ] it.each([ - [{}, false], - [{ filters: {} }, false], - [{ filters: { regexName: null } }, false], - [{ filters: { regexName: "n.me" } }, true], - ])("given %j, returns %s", (given, expected) => { - const binding = given as DeepPartial; - - const result = sut.definesNameRegex(binding); - - expect(result).toBe(expected); - }); -}); - -describe("carriedName", () => { - //[ KubernetesObject, result ] - it.each([ - [{}, ""], - [{ metadata: {} }, ""], - [{ metadata: { name: null } }, ""], - [{ metadata: { name: "name" } }, "name"], - ])("given %j, returns '%s'", (given, expected) => { - const binding = given as DeepPartial; + [{}, {}, false], + [{}, { metadata: { deletionTimestamp: new Date() } }, false], + [{ filters: { deletionTimestamp: true } }, {}, true], + [{ filters: { deletionTimestamp: true } }, { metadata: { deletionTimestamp: new Date() } }, false], + ])("given binding %j and object %j, returns %s", (bnd, obj, expected) => { + const binding = bnd as DeepPartial; + const object = obj as DeepPartial; - const result = sut.carriedName(binding); + const result = sut.mismatchedDeletionTimestamp(binding, object); expect(result).toBe(expected); }); }); -describe("carriesName", () => { - //[ KubernetesObject, result ] +describe("mismatchedName", () => { + //[ Binding, KubernetesObject, result ] it.each([ - [{}, false], - [{ metadata: {} }, false], - [{ metadata: { name: null } }, false], - [{ metadata: { name: "name" } }, true], - ])("given %j, returns %s", (given, expected) => { - const binding = given as DeepPartial; + [{}, {}, false], + [{}, { metadata: { name: "name" } }, false], + [{ filters: { name: "name" } }, {}, true], + [{ filters: { name: "name" } }, { metadata: { name: "name" } }, false], + ])("given binding %j and object %j, returns %s", (bnd, obj, expected) => { + const binding = bnd as DeepPartial; + const object = obj as DeepPartial; - const result = sut.carriesName(binding); + const result = sut.mismatchedName(binding, object); expect(result).toBe(expected); }); }); -describe("missingName", () => { - //[ Binding, result ] +describe("mismatchedNameRegex", () => { + //[ Binding, KubernetesObject, result ] it.each([ - [{}, true], - [{ metadata: {} }, true], - [{ metadata: { name: null } }, true], - [{ metadata: { name: "name" } }, false], - ])("given %j, returns %s", (given, expected) => { - const binding = given as DeepPartial; + [{}, {}, false], + [{}, { metadata: { name: "name" } }, false], + [{ filters: { regexName: "^n[aeiou]me$" } }, {}, true], + [{ filters: { regexName: "^n[aeiou]me$" } }, { metadata: { name: "name" } }, false], + [{ filters: { regexName: "^n[aeiou]me$" } }, { metadata: { name: "neme" } }, false], + [{ filters: { regexName: "^n[aeiou]me$" } }, { metadata: { name: "nime" } }, false], + [{ filters: { regexName: "^n[aeiou]me$" } }, { metadata: { name: "nome" } }, false], + [{ filters: { regexName: "^n[aeiou]me$" } }, { metadata: { name: "nume" } }, false], + [{ filters: { regexName: "^n[aeiou]me$" } }, { metadata: { name: "n3me" } }, true], + ])("given binding %j and object %j, returns %s", (bnd, obj, expected) => { + const binding = bnd as DeepPartial; + const object = obj as DeepPartial; - const result = sut.missingName(binding); + const result = sut.mismatchedNameRegex(binding, object); expect(result).toBe(expected); }); @@ -223,284 +117,138 @@ describe("bindsToKind", () => { }); }); -describe("bindsToNamespace", () => { - //[ Binding, result ] +describe("mismatchedNamespace", () => { + //[ Binding, KubernetesObject, result ] it.each([ - [{}, false], - [{ kind: {} }, false], - [{ kind: { kind: null } }, false], - [{ kind: { kind: "" } }, false], - [{ kind: { kind: "Namespace" } }, true], - ])("given binding %j returns %s", (bnd, expected) => { + [{}, {}, false], + [{}, { metadata: { namespace: "namespace" } }, false], + [{ filters: { namespaces: ["namespace"] } }, {}, true], + [{ filters: { namespaces: ["namespace"] } }, { metadata: { namespace: "nopesause" } }, true], + [{ filters: { namespaces: ["namespace"] } }, { metadata: { namespace: "namespace" } }, false], + ])("given binding %j and object %j, returns %s", (bnd, obj, expected) => { const binding = bnd as DeepPartial; + const object = obj as DeepPartial; - const result = sut.bindsToNamespace(binding); - - expect(result).toBe(expected); - }); -}); - -describe("definedNamespaces", () => { - //[ Binding, result ] - it.each([ - [{}, []], - [{ filters: {} }, []], - [{ filters: { namespaces: null } }, []], - [{ filters: { namespaces: [] } }, []], - [{ filters: { namespaces: ["namespace"] } }, ["namespace"]], - [{ filters: { namespaces: ["name", "space"] } }, ["name", "space"]], - ])("given %j, returns %j", (given, expected) => { - const binding = given as DeepPartial; - - const result = sut.definedNamespaces(binding); - - expect(result).toEqual(expected); - }); -}); - -describe("definesNamespaces", () => { - //[ Binding, result ] - it.each([ - [{}, false], - [{ filters: {} }, false], - [{ filters: { namespaces: null } }, false], - [{ filters: { namespaces: [] } }, false], - [{ filters: { namespaces: ["namespace"] } }, true], - [{ filters: { namespaces: ["name", "space"] } }, true], - ])("given %j, returns %s", (given, expected) => { - const binding = given as DeepPartial; - - const result = sut.definesNamespaces(binding); - - expect(result).toBe(expected); - }); -}); - -describe("definedNamespaceRegexes", () => { - //[ Binding, result ] - it.each([ - [{}, []], - [{ filters: {} }, []], - [{ filters: { regexNamespaces: null } }, []], - [{ filters: { regexNamespaces: [] } }, []], - [{ filters: { regexNamespaces: ["n.mesp.ce"] } }, ["n.mesp.ce"]], - [{ filters: { regexNamespaces: ["n.me", "sp.ce"] } }, ["n.me", "sp.ce"]], - ])("given %j, returns %j", (given, expected) => { - const binding = given as DeepPartial; - - const result = sut.definedNamespaceRegexes(binding); - - expect(result).toEqual(expected); - }); -}); - -describe("definesNamespaceRegexes", () => { - //[ Binding, result ] - it.each([ - [{}, false], - [{ filters: {} }, false], - [{ filters: { regexNamespaces: null } }, false], - [{ filters: { regexNamespaces: [] } }, false], - [{ filters: { regexNamespaces: ["n.mesp.ce"] } }, true], - [{ filters: { regexNamespaces: ["n.me", "sp.ce"] } }, true], - ])("given %j, returns %s", (given, expected) => { - const binding = given as DeepPartial; - - const result = sut.definesNamespaceRegexes(binding); - - expect(result).toBe(expected); - }); -}); - -describe("carriedNamespace", () => { - //[ KubernetesObject, result ] - it.each([ - [{}, ""], - [{ metadata: {} }, ""], - [{ metadata: { namespace: null } }, ""], - [{ metadata: { namespace: "" } }, ""], - [{ metadata: { namespace: "namespace" } }, "namespace"], - ])("given %j, returns %j", (given, expected) => { - const binding = given as DeepPartial; - - const result = sut.carriedNamespace(binding); - - expect(result).toEqual(expected); - }); -}); - -describe("carriesNamespace", () => { - //[ KubernetesObject, result ] - it.each([ - [{}, false], - [{ metadata: {} }, false], - [{ metadata: { namespace: null } }, false], - [{ metadata: { namespace: "" } }, false], - [{ metadata: { namespace: "namespace" } }, true], - ])("given %j, returns %s", (given, expected) => { - const binding = given as DeepPartial; - - const result = sut.carriesNamespace(binding); - - expect(result).toBe(expected); - }); -}); - -describe("misboundNamespace", () => { - //[ Binding, result ] - it.each([ - [{ kind: { kind: "Kind" }, filters: { namespaces: [] } }, false], - [{ kind: { kind: "Kind" }, filters: { namespaces: ["namespace"] } }, false], - [{ kind: { kind: "Namespace" }, filters: { namespaces: [] } }, false], - [{ kind: { kind: "Namespace" }, filters: { namespaces: ["namespace"] } }, true], - ])("given %j, returns %s", (given, expected) => { - const binding = given as DeepPartial; - - const result = sut.misboundNamespace(binding); + const result = sut.mismatchedNamespace(binding, object); expect(result).toBe(expected); }); }); -describe("definedAnnotations", () => { - //[ Binding, result ] +describe("mismatchedNamespaceRegex", () => { + //[ Binding, KubernetesObject, result ] it.each([ - [{}, {}], - [{ filters: {} }, {}], - [{ filters: { annotations: null } }, {}], - [{ filters: { annotations: {} } }, {}], - [{ filters: { annotations: { annotation: "" } } }, { annotation: "" }], - [{ filters: { annotations: { anno: "tation" } } }, { anno: "tation" }], - ])("given %j, returns %j", (given, expected) => { - const binding = given as DeepPartial; - - const result = sut.definedAnnotations(binding); - - expect(result).toEqual(expected); - }); -}); - -describe("definesAnnotations", () => { - //[ Binding, result ] - it.each([ - [{}, false], - [{ filters: {} }, false], - [{ filters: { annotations: null } }, false], - [{ filters: { annotations: {} } }, false], - [{ filters: { annotations: { annotation: "" } } }, true], - [{ filters: { annotations: { anno: "tation" } } }, true], - ])("given %j, returns %s", (given, expected) => { - const binding = given as DeepPartial; + [{}, {}, false], + [{}, { metadata: { namespace: "namespace" } }, false], + [{ filters: { regexNamespaces: ["^n.mespace$"] } }, {}, true], + + [{ filters: { regexNamespaces: ["^n[aeiou]mespace$"] } }, { metadata: { namespace: "namespace" } }, false], + [{ filters: { regexNamespaces: ["^n[aeiou]mespace$"] } }, { metadata: { namespace: "nemespace" } }, false], + [{ filters: { regexNamespaces: ["^n[aeiou]mespace$"] } }, { metadata: { namespace: "nimespace" } }, false], + [{ filters: { regexNamespaces: ["^n[aeiou]mespace$"] } }, { metadata: { namespace: "nomespace" } }, false], + [{ filters: { regexNamespaces: ["^n[aeiou]mespace$"] } }, { metadata: { namespace: "numespace" } }, false], + [{ filters: { regexNamespaces: ["^n[aeiou]mespace$"] } }, { metadata: { namespace: "n3mespace" } }, true], + + [{ filters: { regexNamespaces: ["^n[aeiou]me$", "^sp[aeiou]ce$"] } }, { metadata: { namespace: "name" } }, false], + [{ filters: { regexNamespaces: ["^n[aeiou]me$", "^sp[aeiou]ce$"] } }, { metadata: { namespace: "space" } }, false], + [ + { filters: { regexNamespaces: ["^n[aeiou]me$", "^sp[aeiou]ce$"] } }, + { metadata: { namespace: "namespace" } }, + true, + ], + ])("given binding %j and object %j, returns %s", (bnd, obj, expected) => { + const binding = bnd as DeepPartial; + const object = obj as DeepPartial; - const result = sut.definesAnnotations(binding); + const result = sut.mismatchedNamespaceRegex(binding, object); expect(result).toBe(expected); }); }); -describe("carriedAnnotations", () => { - //[ KuberneteObject, result ] +describe("metasMismatch", () => { it.each([ - [{}, {}], - [{ metadata: {} }, {}], - [{ metadata: { annotations: null } }, {}], - [{ metadata: { annotations: {} } }, {}], - [{ metadata: { annotations: { annotation: "" } } }, { annotation: "" }], - [{ metadata: { annotations: { anno: "tation" } } }, { anno: "tation" }], - ])("given %j, returns %j", (given, expected) => { - const binding = given as DeepPartial; - - const result = sut.carriedAnnotations(binding); + [{}, {}, false], + [{}, { anno: "tate" }, false], - expect(result).toEqual(expected); - }); -}); + [{ anno: "" }, {}, true], + [{ anno: "" }, { anno: "" }, false], + [{ anno: "" }, { anno: "tate" }, false], -describe("carriesAnnotations", () => { - //[ KubernetesObject, result ] - it.each([ - [{}, false], - [{ metadata: {} }, false], - [{ metadata: { annotations: null } }, false], - [{ metadata: { annotations: {} } }, false], - [{ metadata: { annotations: { annotation: "" } } }, true], - [{ metadata: { annotations: { anno: "tation" } } }, true], - ])("given %j, returns %s", (given, expected) => { - const binding = given as DeepPartial; + [{ anno: "tate" }, {}, true], + [{ anno: "tate" }, { anno: "" }, true], + [{ anno: "tate" }, { anno: "tate" }, false], + [{ anno: "tate" }, { anno: "tato" }, true], - const result = sut.carriesAnnotations(binding); + [{ an: "no", ta: "te" }, { an: "" }, true], + [{ an: "no", ta: "te" }, { an: "no" }, true], + [{ an: "no", ta: "te" }, { an: "no", ta: "" }, true], + [{ an: "no", ta: "te" }, { an: "no", ta: "te" }, false], + [{ an: "no", ta: "te" }, { an: "no", ta: "to" }, true], + ])("given left %j and right %j, returns %s", (bnd, obj, expected) => { + const result = sut.metasMismatch(bnd, obj); expect(result).toBe(expected); }); }); -describe("definedLabels", () => { - //[ Binding, result ] - it.each([ - [{}, {}], - [{ filters: {} }, {}], - [{ filters: { labels: null } }, {}], - [{ filters: { labels: {} } }, {}], - [{ filters: { labels: { label: "" } } }, { label: "" }], - [{ filters: { labels: { lab: "el" } } }, { lab: "el" }], - ])("given %j, returns %j", (given, expected) => { - const binding = given as DeepPartial; - - const result = sut.definedLabels(binding); - - expect(result).toEqual(expected); - }); -}); - -describe("definesLabels", () => { - //[ Binding, result ] +describe("mismatchedAnnotations", () => { + //[ Binding, KubernetesObject, result ] it.each([ - [{}, false], - [{ filters: {} }, false], - [{ filters: { labels: null } }, false], - [{ filters: { labels: {} } }, false], - [{ filters: { labels: { label: "" } } }, true], - [{ filters: { labels: { lab: "el" } } }, true], - ])("given %j, returns %s", (given, expected) => { - const binding = given as DeepPartial; + [{}, {}, false], + [{}, { metadata: { annotations: { anno: "tate" } } }, false], + + [{ filters: { annotations: { anno: "" } } }, {}, true], + [{ filters: { annotations: { anno: "" } } }, { metadata: { annotations: { anno: "" } } }, false], + [{ filters: { annotations: { anno: "" } } }, { metadata: { annotations: { anno: "tate" } } }, false], + + [{ filters: { annotations: { anno: "tate" } } }, {}, true], + [{ filters: { annotations: { anno: "tate" } } }, { metadata: { annotations: { anno: "" } } }, true], + [{ filters: { annotations: { anno: "tate" } } }, { metadata: { annotations: { anno: "tate" } } }, false], + [{ filters: { annotations: { anno: "tate" } } }, { metadata: { annotations: { anno: "tato" } } }, true], + + [{ filters: { annotations: { an: "no", ta: "te" } } }, { metadata: { annotations: { an: "" } } }, true], + [{ filters: { annotations: { an: "no", ta: "te" } } }, { metadata: { annotations: { an: "no" } } }, true], + [{ filters: { annotations: { an: "no", ta: "te" } } }, { metadata: { annotations: { an: "no", ta: "" } } }, true], + [{ filters: { annotations: { an: "no", ta: "te" } } }, { metadata: { annotations: { an: "no", ta: "to" } } }, true], + [ + { filters: { annotations: { an: "no", ta: "te" } } }, + { metadata: { annotations: { an: "no", ta: "te" } } }, + false, + ], + ])("given binding %j and object %j, returns %s", (bnd, obj, expected) => { + const binding = bnd as DeepPartial; + const object = obj as DeepPartial; - const result = sut.definesLabels(binding); + const result = sut.mismatchedAnnotations(binding, object); expect(result).toBe(expected); }); }); -describe("carriedLabels", () => { - //[ KubernetesObject, result ] +describe("mismatchedLabels", () => { + //[ Binding, KubernetesObject, result ] it.each([ - [{}, {}], - [{ metadata: {} }, {}], - [{ metadata: { labels: null } }, {}], - [{ metadata: { labels: {} } }, {}], - [{ metadata: { labels: { label: "" } } }, { label: "" }], - [{ metadata: { labels: { lab: "el" } } }, { lab: "el" }], - ])("given %j, returns %j", (given, expected) => { - const binding = given as DeepPartial; + [{}, {}, false], + [{}, { metadata: { labels: { la: "ble" } } }, false], - const result = sut.carriedLabels(binding); + [{ filters: { labels: { la: "" } } }, {}, true], + [{ filters: { labels: { la: "" } } }, { metadata: { labels: { la: "" } } }, false], + [{ filters: { labels: { la: "" } } }, { metadata: { labels: { la: "ble" } } }, false], - expect(result).toEqual(expected); - }); -}); + [{ filters: { labels: { la: "ble" } } }, {}, true], + [{ filters: { labels: { la: "ble" } } }, { metadata: { labels: { la: "" } } }, true], + [{ filters: { labels: { la: "ble" } } }, { metadata: { labels: { la: "ble" } } }, false], -describe("carriesLabels", () => { - //[ KubernetesObject, result ] - it.each([ - [{}, false], - [{ metadata: {} }, false], - [{ metadata: { labels: null } }, false], - [{ metadata: { labels: {} } }, false], - [{ metadata: { labels: { label: "" } } }, true], - [{ metadata: { labels: { lab: "el" } } }, true], - ])("given %j, returns %s", (given, expected) => { - const binding = given as DeepPartial; + [{ filters: { labels: { l: "a", b: "le" } } }, { metadata: { labels: { l: "" } } }, true], + [{ filters: { labels: { l: "a", b: "le" } } }, { metadata: { labels: { l: "a" } } }, true], + [{ filters: { labels: { l: "a", b: "le" } } }, { metadata: { labels: { l: "a", b: "" } } }, true], + [{ filters: { labels: { l: "a", b: "le" } } }, { metadata: { labels: { l: "a", b: "le" } } }, false], + ])("given binding %j and object %j, returns %s", (bnd, obj, expected) => { + const binding = bnd as DeepPartial; + const object = obj as DeepPartial; - const result = sut.carriesLabels(binding); + const result = sut.mismatchedLabels(binding, object); expect(result).toBe(expected); }); @@ -594,66 +342,6 @@ describe("unbindableNamespaces", () => { }); }); -describe("definedEvent", () => { - //[ Binding, result ] - it.each([ - [{}, ""], - [{ event: "" }, ""], - [{ event: "nonsense" }, "nonsense"], - [{ event: Event.Create }, Event.Create], - [{ event: Event.CreateOrUpdate }, Event.CreateOrUpdate], - [{ event: Event.Update }, Event.Update], - [{ event: Event.Delete }, Event.Delete], - ])("given %j, returns '%s'", (given, expected) => { - const binding = given as DeepPartial; - - const result = sut.definedEvent(binding); - - expect(result).toEqual(expected); - }); -}); - -describe("definesDelete", () => { - //[ Binding, result ] - it.each([ - [{}, false], - [{ event: "" }, false], - [{ event: "nonsense" }, false], - [{ event: Event.Create }, false], - [{ event: Event.CreateOrUpdate }, false], - [{ event: Event.Update }, false], - [{ event: Event.Delete }, true], - ])("given %j, returns %s", (given, expected) => { - const binding = given as DeepPartial; - - const result = sut.definesDelete(binding); - - expect(result).toEqual(expected); - }); -}); - -describe("misboundDeleteWithDeletionTimestamp", () => { - //[ Binding, result ] - it.each([ - [{}, false], - [{ event: "" }, false], - [{ event: "nonsense" }, false], - [{ event: Event.Create }, false], - [{ event: Event.CreateOrUpdate }, false], - [{ event: Event.Update }, false], - [{ event: Event.Delete }, false], - [{ event: Event.Delete, filters: {} }, false], - [{ event: Event.Delete, filters: { deletionTimestamp: false } }, false], - [{ event: Event.Delete, filters: { deletionTimestamp: true } }, true], - ])("given %j, returns %s", (given, expected) => { - const binding = given as DeepPartial; - - const result = sut.misboundDeleteWithDeletionTimestamp(binding); - - expect(result).toEqual(expected); - }); -}); - describe("operationMatchesEvent", () => { //[ Operation, Event, result ] it.each([ @@ -762,42 +450,6 @@ describe("mismatchedEvent", () => { }); }); -describe("definedGroup", () => { - //[ Binding, result ] - it.each([ - [{}, ""], - [{ kind: null }, ""], - [{ kind: {} }, ""], - [{ kind: { group: null } }, ""], - [{ kind: { group: "" } }, ""], - [{ kind: { group: "group" } }, "group"], - ])("given %j, returns '%s'", (given, expected) => { - const binding = given as DeepPartial; - - const result = sut.definedGroup(binding); - - expect(result).toEqual(expected); - }); -}); - -describe("definesGroup", () => { - //[ Binding, result ] - it.each([ - [{}, false], - [{ kind: null }, false], - [{ kind: {} }, false], - [{ kind: { group: null } }, false], - [{ kind: { group: "" } }, false], - [{ kind: { group: "group" } }, true], - ])("given %j, returns %s", (given, expected) => { - const binding = given as DeepPartial; - - const result = sut.definesGroup(binding); - - expect(result).toEqual(expected); - }); -}); - describe("declaredGroup", () => { const defaultAdmissionRequest = { uid: "some-uid", @@ -848,42 +500,6 @@ describe("mismatchedGroup", () => { }); }); -describe("definedVersion", () => { - //[ Binding, result ] - it.each([ - [{}, ""], - [{ kind: null }, ""], - [{ kind: {} }, ""], - [{ kind: { version: null } }, ""], - [{ kind: { version: "" } }, ""], - [{ kind: { version: "version" } }, "version"], - ])("given %j, returns '%s'", (given, expected) => { - const binding = given as DeepPartial; - - const result = sut.definedVersion(binding); - - expect(result).toEqual(expected); - }); -}); - -describe("definesVersion", () => { - //[ Binding, result ] - it.each([ - [{}, false], - [{ kind: null }, false], - [{ kind: {} }, false], - [{ kind: { version: null } }, false], - [{ kind: { version: "" } }, false], - [{ kind: { version: "version" } }, true], - ])("given %j, returns %s", (given, expected) => { - const binding = given as DeepPartial; - - const result = sut.definesVersion(binding); - - expect(result).toEqual(expected); - }); -}); - describe("declaredVersion", () => { const defaultAdmissionRequest = { uid: "some-uid", @@ -933,42 +549,6 @@ describe("mismatchedVersion", () => { }); }); -describe("definedKind", () => { - //[ Binding, result ] - it.each([ - [{}, ""], - [{ kind: null }, ""], - [{ kind: {} }, ""], - [{ kind: { kind: null } }, ""], - [{ kind: { kind: "" } }, ""], - [{ kind: { kind: "kind" } }, "kind"], - ])("given %j, returns '%s'", (given, expected) => { - const binding = given as DeepPartial; - - const result = sut.definedKind(binding); - - expect(result).toEqual(expected); - }); -}); - -describe("definesKind", () => { - //[ Binding, result ] - it.each([ - [{}, false], - [{ kind: null }, false], - [{ kind: {} }, false], - [{ kind: { kind: null } }, false], - [{ kind: { kind: "" } }, false], - [{ kind: { kind: "kind" } }, true], - ])("given %j, returns %s", (given, expected) => { - const binding = given as DeepPartial; - - const result = sut.definesKind(binding); - - expect(result).toEqual(expected); - }); -}); - describe("declaredKind", () => { const defaultAdmissionRequest = { uid: "some-uid", @@ -1019,67 +599,6 @@ describe("mismatchedKind", () => { }); }); -describe("definedCategory", () => { - //[ Binding, result ] - it.each([ - [{}, ""], - [{ isValidate: true }, "Validate"], - [{ isMutate: true }, "Mutate"], - [{ isWatch: true }, "Watch"], - [{ isFinalize: true, isWatch: true }, "Finalize"], - ])("given %j, returns %s", (given, expected) => { - const binding = given as DeepPartial; - - const result = sut.definedCategory(binding); - - expect(result).toEqual(expected); - }); -}); - -describe("definedCallback", () => { - const validateCallback = () => {}; - const mutateCallback = () => {}; - const watchCallback = () => {}; - const finalizeCallback = () => {}; - - //[ Binding, result ] - it.each([ - [{}, null], - [{ isValidate: true, validateCallback }, validateCallback], - [{ isMutate: true, mutateCallback }, mutateCallback], - [{ isWatch: true, watchCallback }, watchCallback], - [{ isFinalize: true, finalizeCallback }, finalizeCallback], - ])("given %j, returns %s", (given, expected) => { - const binding = given as DeepPartial; - - const result = sut.definedCallback(binding); - - expect(result).toEqual(expected); - }); -}); - -describe("definedCallbackName", () => { - const validateCallback = () => {}; - const mutateCallback = () => {}; - const watchCallback = () => {}; - const finalizeCallback = () => {}; - - //[ Binding, result ] - it.each([ - [{}, ""], - [{ isValidate: true, validateCallback }, "validateCallback"], - [{ isMutate: true, mutateCallback }, "mutateCallback"], - [{ isWatch: true, watchCallback }, "watchCallback"], - [{ isFinalize: true, finalizeCallback }, "finalizeCallback"], - ])("given %j, returns %s", (given, expected) => { - const binding = given as DeepPartial; - - const result = sut.definedCallbackName(binding); - - expect(result).toEqual(expected); - }); -}); - describe("declaredUid", () => { const defaultAdmissionRequest = { uid: undefined, diff --git a/src/lib/filter/adjudicators/bindingAdjudicators.test.ts b/src/lib/filter/adjudicators/bindingAdjudicators.test.ts new file mode 100644 index 000000000..ed9eecb96 --- /dev/null +++ b/src/lib/filter/adjudicators/bindingAdjudicators.test.ts @@ -0,0 +1,682 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2023-Present The Pepr Authors + +import { expect, describe, it } from "@jest/globals"; +import * as sut from "../adjudicators"; +import { KubernetesObject } from "kubernetes-fluent-client"; +import { Binding, DeepPartial } from "../../types"; +import { Event } from "../../enums"; + +describe("definesDeletionTimestamp", () => { + //[ Binding, result ] + it.each([ + [{}, false], + [{ filters: {} }, false], + [{ filters: { deletionTimestamp: null } }, false], + [{ filters: { deletionTimestamp: false } }, false], + [{ filters: { deletionTimestamp: true } }, true], + ])("given %j, returns %s", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.definesDeletionTimestamp(binding); + + expect(result).toBe(expected); + }); +}); + +describe("ignoresDeletionTimestamp", () => { + //[ Binding, result ] + it.each([ + [{}, true], + [{ filters: {} }, true], + [{ filters: { deletionTimestamp: null } }, true], + [{ filters: { deletionTimestamp: false } }, true], + [{ filters: { deletionTimestamp: true } }, false], + ])("given %j, returns %s", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.ignoresDeletionTimestamp(binding); + + expect(result).toBe(expected); + }); +}); + +describe("definedName", () => { + //[ Binding, result ] + it.each([ + [{}, ""], + [{ filters: {} }, ""], + [{ filters: { name: null } }, ""], + [{ filters: { name: "name" } }, "name"], + ])("given %j, returns '%s'", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.definedName(binding); + + expect(result).toBe(expected); + }); +}); + +describe("definesName", () => { + //[ Binding, result ] + it.each([ + [{}, false], + [{ filters: {} }, false], + [{ filters: { name: null } }, false], + [{ filters: { name: "name" } }, true], + ])("given %j, returns %s", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.definesName(binding); + + expect(result).toBe(expected); + }); +}); + +describe("ignoresName", () => { + //[ Binding, result ] + it.each([ + [{}, true], + [{ filters: {} }, true], + [{ filters: { name: null } }, true], + [{ filters: { name: "name" } }, false], + ])("given %j, returns %s", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.ignoresName(binding); + + expect(result).toBe(expected); + }); +}); + +describe("definedNameRegex", () => { + //[ Binding, result ] + it.each([ + [{}, ""], + [{ filters: {} }, ""], + [{ filters: { regexName: null } }, ""], + [{ filters: { regexName: "n.me" } }, "n.me"], + ])("given %j, returns '%s'", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.definedNameRegex(binding); + + expect(result).toBe(expected); + }); +}); + +describe("definesNameRegex", () => { + //[ Binding, result ] + it.each([ + [{}, false], + [{ filters: {} }, false], + [{ filters: { regexName: null } }, false], + [{ filters: { regexName: "n.me" } }, true], + ])("given %j, returns %s", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.definesNameRegex(binding); + + expect(result).toBe(expected); + }); +}); + +describe("carriedName", () => { + //[ KubernetesObject, result ] + it.each([ + [{}, ""], + [{ metadata: {} }, ""], + [{ metadata: { name: null } }, ""], + [{ metadata: { name: "name" } }, "name"], + ])("given %j, returns '%s'", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.carriedName(binding); + + expect(result).toBe(expected); + }); +}); + +describe("carriesName", () => { + //[ KubernetesObject, result ] + it.each([ + [{}, false], + [{ metadata: {} }, false], + [{ metadata: { name: null } }, false], + [{ metadata: { name: "name" } }, true], + ])("given %j, returns %s", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.carriesName(binding); + + expect(result).toBe(expected); + }); +}); + +describe("missingName", () => { + //[ Binding, result ] + it.each([ + [{}, true], + [{ metadata: {} }, true], + [{ metadata: { name: null } }, true], + [{ metadata: { name: "name" } }, false], + ])("given %j, returns %s", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.missingName(binding); + + expect(result).toBe(expected); + }); +}); + +describe("bindsToNamespace", () => { + //[ Binding, result ] + it.each([ + [{}, false], + [{ kind: {} }, false], + [{ kind: { kind: null } }, false], + [{ kind: { kind: "" } }, false], + [{ kind: { kind: "Namespace" } }, true], + ])("given binding %j returns %s", (bnd, expected) => { + const binding = bnd as DeepPartial; + + const result = sut.bindsToNamespace(binding); + + expect(result).toBe(expected); + }); +}); + +describe("definedNamespaces", () => { + //[ Binding, result ] + it.each([ + [{}, []], + [{ filters: {} }, []], + [{ filters: { namespaces: null } }, []], + [{ filters: { namespaces: [] } }, []], + [{ filters: { namespaces: ["namespace"] } }, ["namespace"]], + [{ filters: { namespaces: ["name", "space"] } }, ["name", "space"]], + ])("given %j, returns %j", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.definedNamespaces(binding); + + expect(result).toEqual(expected); + }); +}); + +describe("definesNamespaces", () => { + //[ Binding, result ] + it.each([ + [{}, false], + [{ filters: {} }, false], + [{ filters: { namespaces: null } }, false], + [{ filters: { namespaces: [] } }, false], + [{ filters: { namespaces: ["namespace"] } }, true], + [{ filters: { namespaces: ["name", "space"] } }, true], + ])("given %j, returns %s", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.definesNamespaces(binding); + + expect(result).toBe(expected); + }); +}); + +describe("definedNamespaceRegexes", () => { + //[ Binding, result ] + it.each([ + [{}, []], + [{ filters: {} }, []], + [{ filters: { regexNamespaces: null } }, []], + [{ filters: { regexNamespaces: [] } }, []], + [{ filters: { regexNamespaces: ["n.mesp.ce"] } }, ["n.mesp.ce"]], + [{ filters: { regexNamespaces: ["n.me", "sp.ce"] } }, ["n.me", "sp.ce"]], + ])("given %j, returns %j", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.definedNamespaceRegexes(binding); + + expect(result).toEqual(expected); + }); +}); + +describe("definesNamespaceRegexes", () => { + //[ Binding, result ] + it.each([ + [{}, false], + [{ filters: {} }, false], + [{ filters: { regexNamespaces: null } }, false], + [{ filters: { regexNamespaces: [] } }, false], + [{ filters: { regexNamespaces: ["n.mesp.ce"] } }, true], + [{ filters: { regexNamespaces: ["n.me", "sp.ce"] } }, true], + ])("given %j, returns %s", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.definesNamespaceRegexes(binding); + + expect(result).toBe(expected); + }); +}); + +describe("carriedNamespace", () => { + //[ KubernetesObject, result ] + it.each([ + [{}, ""], + [{ metadata: {} }, ""], + [{ metadata: { namespace: null } }, ""], + [{ metadata: { namespace: "" } }, ""], + [{ metadata: { namespace: "namespace" } }, "namespace"], + ])("given %j, returns %j", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.carriedNamespace(binding); + + expect(result).toEqual(expected); + }); +}); + +describe("carriesNamespace", () => { + //[ KubernetesObject, result ] + it.each([ + [{}, false], + [{ metadata: {} }, false], + [{ metadata: { namespace: null } }, false], + [{ metadata: { namespace: "" } }, false], + [{ metadata: { namespace: "namespace" } }, true], + ])("given %j, returns %s", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.carriesNamespace(binding); + + expect(result).toBe(expected); + }); +}); + +describe("misboundNamespace", () => { + //[ Binding, result ] + it.each([ + [{ kind: { kind: "Kind" }, filters: { namespaces: [] } }, false], + [{ kind: { kind: "Kind" }, filters: { namespaces: ["namespace"] } }, false], + [{ kind: { kind: "Namespace" }, filters: { namespaces: [] } }, false], + [{ kind: { kind: "Namespace" }, filters: { namespaces: ["namespace"] } }, true], + ])("given %j, returns %s", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.misboundNamespace(binding); + + expect(result).toBe(expected); + }); +}); + +describe("definedAnnotations", () => { + //[ Binding, result ] + it.each([ + [{}, {}], + [{ filters: {} }, {}], + [{ filters: { annotations: null } }, {}], + [{ filters: { annotations: {} } }, {}], + [{ filters: { annotations: { annotation: "" } } }, { annotation: "" }], + [{ filters: { annotations: { anno: "tation" } } }, { anno: "tation" }], + ])("given %j, returns %j", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.definedAnnotations(binding); + + expect(result).toEqual(expected); + }); +}); + +describe("definesAnnotations", () => { + //[ Binding, result ] + it.each([ + [{}, false], + [{ filters: {} }, false], + [{ filters: { annotations: null } }, false], + [{ filters: { annotations: {} } }, false], + [{ filters: { annotations: { annotation: "" } } }, true], + [{ filters: { annotations: { anno: "tation" } } }, true], + ])("given %j, returns %s", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.definesAnnotations(binding); + + expect(result).toBe(expected); + }); +}); + +describe("carriedAnnotations", () => { + //[ KuberneteObject, result ] + it.each([ + [{}, {}], + [{ metadata: {} }, {}], + [{ metadata: { annotations: null } }, {}], + [{ metadata: { annotations: {} } }, {}], + [{ metadata: { annotations: { annotation: "" } } }, { annotation: "" }], + [{ metadata: { annotations: { anno: "tation" } } }, { anno: "tation" }], + ])("given %j, returns %j", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.carriedAnnotations(binding); + + expect(result).toEqual(expected); + }); +}); + +describe("carriesAnnotations", () => { + //[ KubernetesObject, result ] + it.each([ + [{}, false], + [{ metadata: {} }, false], + [{ metadata: { annotations: null } }, false], + [{ metadata: { annotations: {} } }, false], + [{ metadata: { annotations: { annotation: "" } } }, true], + [{ metadata: { annotations: { anno: "tation" } } }, true], + ])("given %j, returns %s", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.carriesAnnotations(binding); + + expect(result).toBe(expected); + }); +}); + +describe("definedLabels", () => { + //[ Binding, result ] + it.each([ + [{}, {}], + [{ filters: {} }, {}], + [{ filters: { labels: null } }, {}], + [{ filters: { labels: {} } }, {}], + [{ filters: { labels: { label: "" } } }, { label: "" }], + [{ filters: { labels: { lab: "el" } } }, { lab: "el" }], + ])("given %j, returns %j", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.definedLabels(binding); + + expect(result).toEqual(expected); + }); +}); + +describe("definesLabels", () => { + //[ Binding, result ] + it.each([ + [{}, false], + [{ filters: {} }, false], + [{ filters: { labels: null } }, false], + [{ filters: { labels: {} } }, false], + [{ filters: { labels: { label: "" } } }, true], + [{ filters: { labels: { lab: "el" } } }, true], + ])("given %j, returns %s", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.definesLabels(binding); + + expect(result).toBe(expected); + }); +}); + +describe("carriedLabels", () => { + //[ KubernetesObject, result ] + it.each([ + [{}, {}], + [{ metadata: {} }, {}], + [{ metadata: { labels: null } }, {}], + [{ metadata: { labels: {} } }, {}], + [{ metadata: { labels: { label: "" } } }, { label: "" }], + [{ metadata: { labels: { lab: "el" } } }, { lab: "el" }], + ])("given %j, returns %j", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.carriedLabels(binding); + + expect(result).toEqual(expected); + }); +}); + +describe("carriesLabels", () => { + //[ KubernetesObject, result ] + it.each([ + [{}, false], + [{ metadata: {} }, false], + [{ metadata: { labels: null } }, false], + [{ metadata: { labels: {} } }, false], + [{ metadata: { labels: { label: "" } } }, true], + [{ metadata: { labels: { lab: "el" } } }, true], + ])("given %j, returns %s", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.carriesLabels(binding); + + expect(result).toBe(expected); + }); +}); + +describe("definedEvent", () => { + //[ Binding, result ] + it.each([ + [{}, ""], + [{ event: "" }, ""], + [{ event: "nonsense" }, "nonsense"], + [{ event: Event.Create }, Event.Create], + [{ event: Event.CreateOrUpdate }, Event.CreateOrUpdate], + [{ event: Event.Update }, Event.Update], + [{ event: Event.Delete }, Event.Delete], + ])("given %j, returns '%s'", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.definedEvent(binding); + + expect(result).toEqual(expected); + }); +}); + +describe("definesDelete", () => { + //[ Binding, result ] + it.each([ + [{}, false], + [{ event: "" }, false], + [{ event: "nonsense" }, false], + [{ event: Event.Create }, false], + [{ event: Event.CreateOrUpdate }, false], + [{ event: Event.Update }, false], + [{ event: Event.Delete }, true], + ])("given %j, returns %s", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.definesDelete(binding); + + expect(result).toEqual(expected); + }); +}); + +describe("misboundDeleteWithDeletionTimestamp", () => { + //[ Binding, result ] + it.each([ + [{}, false], + [{ event: "" }, false], + [{ event: "nonsense" }, false], + [{ event: Event.Create }, false], + [{ event: Event.CreateOrUpdate }, false], + [{ event: Event.Update }, false], + [{ event: Event.Delete }, false], + [{ event: Event.Delete, filters: {} }, false], + [{ event: Event.Delete, filters: { deletionTimestamp: false } }, false], + [{ event: Event.Delete, filters: { deletionTimestamp: true } }, true], + ])("given %j, returns %s", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.misboundDeleteWithDeletionTimestamp(binding); + + expect(result).toEqual(expected); + }); +}); + +describe("definedGroup", () => { + //[ Binding, result ] + it.each([ + [{}, ""], + [{ kind: null }, ""], + [{ kind: {} }, ""], + [{ kind: { group: null } }, ""], + [{ kind: { group: "" } }, ""], + [{ kind: { group: "group" } }, "group"], + ])("given %j, returns '%s'", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.definedGroup(binding); + + expect(result).toEqual(expected); + }); +}); + +describe("definesGroup", () => { + //[ Binding, result ] + it.each([ + [{}, false], + [{ kind: null }, false], + [{ kind: {} }, false], + [{ kind: { group: null } }, false], + [{ kind: { group: "" } }, false], + [{ kind: { group: "group" } }, true], + ])("given %j, returns %s", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.definesGroup(binding); + + expect(result).toEqual(expected); + }); +}); + +describe("definedVersion", () => { + //[ Binding, result ] + it.each([ + [{}, ""], + [{ kind: null }, ""], + [{ kind: {} }, ""], + [{ kind: { version: null } }, ""], + [{ kind: { version: "" } }, ""], + [{ kind: { version: "version" } }, "version"], + ])("given %j, returns '%s'", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.definedVersion(binding); + + expect(result).toEqual(expected); + }); +}); + +describe("definesVersion", () => { + //[ Binding, result ] + it.each([ + [{}, false], + [{ kind: null }, false], + [{ kind: {} }, false], + [{ kind: { version: null } }, false], + [{ kind: { version: "" } }, false], + [{ kind: { version: "version" } }, true], + ])("given %j, returns %s", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.definesVersion(binding); + + expect(result).toEqual(expected); + }); +}); + +describe("definedKind", () => { + //[ Binding, result ] + it.each([ + [{}, ""], + [{ kind: null }, ""], + [{ kind: {} }, ""], + [{ kind: { kind: null } }, ""], + [{ kind: { kind: "" } }, ""], + [{ kind: { kind: "kind" } }, "kind"], + ])("given %j, returns '%s'", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.definedKind(binding); + + expect(result).toEqual(expected); + }); +}); + +describe("definesKind", () => { + //[ Binding, result ] + it.each([ + [{}, false], + [{ kind: null }, false], + [{ kind: {} }, false], + [{ kind: { kind: null } }, false], + [{ kind: { kind: "" } }, false], + [{ kind: { kind: "kind" } }, true], + ])("given %j, returns %s", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.definesKind(binding); + + expect(result).toEqual(expected); + }); +}); + +describe("definedCategory", () => { + //[ Binding, result ] + it.each([ + [{}, ""], + [{ isValidate: true }, "Validate"], + [{ isMutate: true }, "Mutate"], + [{ isWatch: true }, "Watch"], + [{ isFinalize: true, isWatch: true }, "Finalize"], + ])("given %j, returns %s", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.definedCategory(binding); + + expect(result).toEqual(expected); + }); +}); + +describe("definedCallback", () => { + const validateCallback = () => {}; + const mutateCallback = () => {}; + const watchCallback = () => {}; + const finalizeCallback = () => {}; + + //[ Binding, result ] + it.each([ + [{}, null], + [{ isValidate: true, validateCallback }, validateCallback], + [{ isMutate: true, mutateCallback }, mutateCallback], + [{ isWatch: true, watchCallback }, watchCallback], + [{ isFinalize: true, finalizeCallback }, finalizeCallback], + ])("given %j, returns %s", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.definedCallback(binding); + + expect(result).toEqual(expected); + }); +}); + +describe("definedCallbackName", () => { + const validateCallback = () => {}; + const mutateCallback = () => {}; + const watchCallback = () => {}; + const finalizeCallback = () => {}; + + //[ Binding, result ] + it.each([ + [{}, ""], + [{ isValidate: true, validateCallback }, "validateCallback"], + [{ isMutate: true, mutateCallback }, "mutateCallback"], + [{ isWatch: true, watchCallback }, "watchCallback"], + [{ isFinalize: true, finalizeCallback }, "finalizeCallback"], + ])("given %j, returns %s", (given, expected) => { + const binding = given as DeepPartial; + + const result = sut.definedCallbackName(binding); + + expect(result).toEqual(expected); + }); +});