Skip to content

Commit

Permalink
chore: merge in KFC update
Browse files Browse the repository at this point in the history
Signed-off-by: Case Wylie <[email protected]>
  • Loading branch information
cmwylie19 committed Dec 3, 2024
1 parent ebd0053 commit aeaf4db
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 48 deletions.
17 changes: 11 additions & 6 deletions journey/pepr-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@

import { afterAll, expect, it } from "@jest/globals";
import { ChildProcessWithoutNullStreams, spawn } from "child_process";
import { Agent } from "https";
import { fetch } from "kubernetes-fluent-client";
import { RequestInit } from "node-fetch";
import { RequestInit, Agent } from "undici";
import { cwd } from "./entrypoint.test";
import { sleep } from "./k8s";

const fetchBaseUrl = "https://localhost:3000";
const fetchOpts: RequestInit = {
agent: new Agent({
// Avoid tls issues for self-signed certs
rejectUnauthorized: false,
method: "GET",
headers: {
"Content-Type": "application/json; charset=UTF-8",
},
dispatcher: new Agent({
// disable keep-alive https://github.com/nodejs/undici/issues/2522#issuecomment-1859213319
pipelining: 0,
connect: {
rejectUnauthorized: false,
},
}),
};

Expand Down Expand Up @@ -78,7 +84,6 @@ export function peprDev() {
} else {
// Abort all further processing
success = true;

// Finish the test
done();
}
Expand Down
43 changes: 12 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
"husky": "^9.1.6",
"jest": "29.7.0",
"js-yaml": "^4.1.0",
"nock": "^13.5.4",
"ts-jest": "29.2.5"
"ts-jest": "29.2.5",
"undici": "^7.0.0"
},
"peerDependencies": {
"@types/prompts": "2.4.9",
Expand Down
28 changes: 19 additions & 9 deletions src/templates/capabilities/hello-pepr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
fetchStatus,
kind,
} from "pepr";
import nock from "nock";
import { MockAgent, setGlobalDispatcher } from "undici";

/**
* The HelloPepr Capability is an example capability to demonstrate some general concepts of Pepr.
Expand Down Expand Up @@ -273,14 +273,24 @@ When(a.ConfigMap)
.WithLabel("chuck-norris")
.Mutate(cm => cm.SetLabel("got-jokes", "true"))
.Watch(async cm => {
const jokeURL = "https://icanhazdadjoke.com/";

// Set up Nock to mock the API calls globally with header matching
nock(jokeURL).get("/").reply(200, {
id: "R7UfaahVfFd",
joke: "Funny joke goes here.",
status: 200,
});
const jokeURL = "https://icanhazdadjoke.com";

const mockAgent: MockAgent = new MockAgent();
setGlobalDispatcher(mockAgent);
const mockClient = mockAgent.get(jokeURL);
mockClient.intercept({ path: "/", method: "GET" }).reply(
200,
{
id: "R7UfaahVfFd",
joke: "Funny joke goes here.",
status: 200,
},
{
headers: {
"Content-Type": "application/json; charset=utf-8",
},
},
);

// Try/catch is not needed as a response object will always be returned
const response = await fetch<TheChuckNorrisJoke>(jokeURL, {
Expand Down

0 comments on commit aeaf4db

Please sign in to comment.