Skip to content

Commit

Permalink
AUT-1984: Add debug logging to sidecar tests
Browse files Browse the repository at this point in the history
If the `RUNNER_DEBUG` environment variable is set to `1`, the logs from
the sidecar container will be streamed to the console. This is useful
for debugging test failures.

This is automatically set when the GitHub Actions job is rerun with the
"Enable debug logging" option checked. Otherwise, the test can be run
on the CLI with `RUNNER_DEBUG=1 yarn test:sidecar`
  • Loading branch information
whi-tw committed Apr 10, 2024
1 parent 48624d9 commit fe2adc3
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/basic-auth-sidecar/basic-auth-sidecar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ describe("BasicAuthSidecar", function () {

let sourceIp: string;

const isDebug: boolean = process.env.RUNNER_DEBUG === "1";

// let backendContainer: StartedTestContainer;
let sidecarContainer: StartedTestContainer;

Expand Down Expand Up @@ -112,6 +114,18 @@ describe("BasicAuthSidecar", function () {
)
.start();

if (isDebug) {
// if RUNNER_DEBUG is set, stream logs to console
// this is set if the gha job is rerun with 'Enable debug logging' checked.

/* eslint-disable no-console */
(await sidecarContainer.logs())
.on("data", (line) => console.log(line))
.on("err", (line) => console.error(line))
.on("end", () => console.log("Stream closed"));
/* eslint-enable no-console */
}

sidecarRequester = chai
.request(
`http://${sidecarContainer.getHost()}:${sidecarContainer.getFirstMappedPort()}`
Expand Down Expand Up @@ -232,6 +246,10 @@ describe("BasicAuthSidecar", function () {
});

it("should not be required if the request is made from an allowed IP", async () => {
if (isDebug) {
// eslint-disable-next-line no-console
console.log("sourceIp", sourceIp);
}
await startSidecarContainer({
BASIC_AUTH_USERNAME: "test",
BASIC_AUTH_PASSWORD: "test",
Expand Down

0 comments on commit fe2adc3

Please sign in to comment.