Skip to content

Commit

Permalink
Merge branch 'main' into 959-refactor-store-code
Browse files Browse the repository at this point in the history
  • Loading branch information
samayer12 authored Oct 28, 2024
2 parents 7ad91c6 + 7260348 commit cfb86da
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cli-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
run: echo "PEPR=${GITHUB_WORKSPACE}/pepr" >> "$GITHUB_ENV"

- name: setup node
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: 20
cache-dependency-path: pepr
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/commitlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0

- name: Install commitlint
run: npm install --save-dev @commitlint/{config-conventional,cli}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/container-scan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Use Node.js latest
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: 20
cache: "npm"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: setup node
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: 20
cache-dependency-path: pepr
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Use Node.js latest
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: latest
cache: "npm"
Expand All @@ -30,7 +30,7 @@ jobs:
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
Expand All @@ -46,7 +46,7 @@ jobs:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Use Node.js 22
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: 22
cache: "npm"
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pepr-excellent-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
run: echo "PEPR=${GITHUB_WORKSPACE}/pepr" >> "$GITHUB_ENV"

- name: setup node
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: 20
cache: "npm"
Expand Down Expand Up @@ -120,7 +120,7 @@ jobs:
run: echo "PEPR_EXCELLENT_EXAMPLES_PATH=${GITHUB_WORKSPACE}/pepr-excellent-examples" >> "$GITHUB_ENV"

- name: setup node
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: 20
cache: "npm"
Expand Down Expand Up @@ -175,7 +175,7 @@ jobs:
run: echo "PEPR_EXCELLENT_EXAMPLES_PATH=${GITHUB_WORKSPACE}/pepr-excellent-examples" >> "$GITHUB_ENV"

- name: setup node
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: 20
cache: "npm"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1

- name: Use Node.js 20
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: 20
registry-url: "https://registry.npmjs.org"
Expand Down Expand Up @@ -67,7 +67,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Set up Node registry authentication
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: 20
registry-url: "https://registry.npmjs.org"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/soak-interrupts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
run: echo "PEPR=${GITHUB_WORKSPACE}/pepr" >> "$GITHUB_ENV"

- name: setup node
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: 20
cache: "npm"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/soak.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
run: echo "PEPR=${GITHUB_WORKSPACE}/pepr" >> "$GITHUB_ENV"

- name: setup node
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: 20
cache: "npm"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/uds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
run: echo "PEPR=${GITHUB_WORKSPACE}/pepr" >> "$GITHUB_ENV"

- name: setup node
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: 20
cache: "npm"
Expand Down Expand Up @@ -79,7 +79,7 @@ jobs:
run: echo "UDS_CORE=${GITHUB_WORKSPACE}/uds-core" >> "$GITHUB_ENV"

- name: setup node
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: 20
cache: "npm"
Expand Down
86 changes: 86 additions & 0 deletions src/lib/capability.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,92 @@ describe("Capability", () => {
expect(mockLog.info).toHaveBeenCalledWith("Reconcile action log");
});

it("should use user-provided alias for finalizer with reconcile", async () => {
const capability = new Capability(capabilityConfig);

const mockReconcileCallback: WatchLogAction<typeof V1Pod> = jest.fn(
async (update, phase, logger: typeof Log = mockLog) => {
logger.info("external api call (reconcile-create-alias): reconcile/callback");
},
);

const mockFinalizeCallback: FinalizeAction<typeof V1Pod> = jest.fn(
async (update: V1Pod, logger: typeof Log = mockLog) => {
logger.info("Finalize action log");
},
);

// Set up a When binding with a user-provided alias and Finalize
// Chain .Reconcile() with the correct function signature before .Finalize()
capability
.When(a.Pod)
.IsCreatedOrUpdated()
.Alias("custom-finalizer-alias")
.Reconcile(mockReconcileCallback)
.Finalize(mockFinalizeCallback);

// Find the finalize binding
const finalizeBinding = capability.bindings.find(binding => binding.finalizeCallback);

expect(finalizeBinding).toBeDefined(); // Ensure the finalize binding exists

// Simulate calling the finalize action
const testPod = new V1Pod();

if (finalizeBinding?.finalizeCallback) {
await finalizeBinding.finalizeCallback(testPod);
}

// Assertions to ensure the user-provided alias is used in the logger
expect(mockFinalizeCallback).toHaveBeenCalledWith(testPod, expect.anything());
expect(mockLog.child).toHaveBeenCalledWith({ alias: "custom-finalizer-alias" });
expect(mockLog.info).toHaveBeenCalledWith("Executing finalize action with alias: custom-finalizer-alias");
expect(mockLog.info).toHaveBeenCalledWith("Finalize action log");
});

it("should use user-provided alias for finalizer with watch", async () => {
const capability = new Capability(capabilityConfig);

const mockWatchCallback: WatchLogAction<typeof V1Pod> = jest.fn(
async (update, phase, logger: typeof Log = mockLog) => {
logger.info("external api call (watch-create-alias): watch/callback");
},
);

const mockFinalizeCallback: FinalizeAction<typeof V1Pod> = jest.fn(
async (update: V1Pod, logger: typeof Log = mockLog) => {
logger.info("Finalize action log");
},
);

// Set up a When binding with a user-provided alias and Finalize
// Chain .Watch() with the correct function signature before .Finalize()
capability
.When(a.Pod)
.IsCreatedOrUpdated()
.Alias("custom-finalizer-alias")
.Watch(mockWatchCallback)
.Finalize(mockFinalizeCallback);

// Find the finalize binding
const finalizeBinding = capability.bindings.find(binding => binding.finalizeCallback);

expect(finalizeBinding).toBeDefined(); // Ensure the finalize binding exists

// Simulate calling the finalize action
const testPod = new V1Pod();

if (finalizeBinding?.finalizeCallback) {
await finalizeBinding.finalizeCallback(testPod);
}

// Assertions to ensure the user-provided alias is used in the logger
expect(mockFinalizeCallback).toHaveBeenCalledWith(testPod, expect.anything());
expect(mockLog.child).toHaveBeenCalledWith({ alias: "custom-finalizer-alias" });
expect(mockLog.info).toHaveBeenCalledWith("Executing finalize action with alias: custom-finalizer-alias");
expect(mockLog.info).toHaveBeenCalledWith("Finalize action log");
});

it("should use child logger for finalize callback", async () => {
const capability = new Capability(capabilityConfig);

Expand Down

0 comments on commit cfb86da

Please sign in to comment.