Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c4b26f3

Browse files
authored
test: verify that enterprise tests are being run (#12871)
1 parent a2b28f8 commit c4b26f3

File tree

6 files changed

+72
-32
lines changed

6 files changed

+72
-32
lines changed

Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,9 @@ install: build/coder_$(VERSION)_$(GOOS)_$(GOARCH)$(GOOS_BIN_EXT)
382382
cp "$<" "$$output_file"
383383
.PHONY: install
384384

385-
BOLD := $(shell tput bold)
386-
GREEN := $(shell tput setaf 2)
387-
RESET := $(shell tput sgr0)
385+
BOLD := $(shell tput bold 2>/dev/null)
386+
GREEN := $(shell tput setaf 2 2>/dev/null)
387+
RESET := $(shell tput sgr0 2>/dev/null)
388388

389389
fmt: fmt/eslint fmt/prettier fmt/terraform fmt/shfmt fmt/go
390390
.PHONY: fmt

site/e2e/constants.ts

+3
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,7 @@ export const gitAuth = {
3333
installationsPath: "/installations",
3434
};
3535

36+
export const requireEnterpriseTests = Boolean(
37+
process.env.CODER_E2E_REQUIRE_ENTERPRISE_TESTS,
38+
);
3639
export const enterpriseLicense = process.env.CODER_E2E_ENTERPRISE_LICENSE ?? "";

site/e2e/global.setup.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { test, expect } from "@playwright/test";
1+
import { expect, test } from "@playwright/test";
22
import { Language } from "pages/CreateUserPage/CreateUserForm";
33
import * as constants from "./constants";
44
import { storageState } from "./playwright.config";
@@ -18,7 +18,12 @@ test("setup deployment", async ({ page }) => {
1818
await page.getByTestId("button-select-template").isVisible();
1919

2020
// Setup license
21-
if (constants.enterpriseLicense) {
21+
if (constants.requireEnterpriseTests || constants.enterpriseLicense) {
22+
// Make sure that we have something that looks like a real license
23+
expect(constants.enterpriseLicense).toBeTruthy();
24+
expect(constants.enterpriseLicense.length).toBeGreaterThan(92); // the signature alone should be this long
25+
expect(constants.enterpriseLicense.split(".").length).toBe(3); // otherwise it's invalid
26+
2227
await page.goto("/deployment/licenses", { waitUntil: "domcontentloaded" });
2328

2429
await page.getByText("Add a license").click();

site/e2e/helpers.ts

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
coderPort,
1919
enterpriseLicense,
2020
prometheusPort,
21+
requireEnterpriseTests,
2122
} from "./constants";
2223
import {
2324
Agent,
@@ -33,6 +34,10 @@ import {
3334

3435
// requiresEnterpriseLicense will skip the test if we're not running with an enterprise license
3536
export function requiresEnterpriseLicense() {
37+
if (requireEnterpriseTests) {
38+
return;
39+
}
40+
3641
test.skip(!enterpriseLicense);
3742
}
3843

site/e2e/reporter.ts

+44-27
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ import type {
1111
import axios from "axios";
1212
import * as fs from "fs/promises";
1313
import type { Writable } from "stream";
14-
import { coderdPProfPort } from "./constants";
14+
import { coderdPProfPort, enterpriseLicense } from "./constants";
1515

1616
class CoderReporter implements Reporter {
1717
config: FullConfig | null = null;
1818
testOutput = new Map<string, Array<[Writable, string]>>();
1919
passedCount = 0;
20+
skippedCount = 0;
2021
failedTests: TestCase[] = [];
2122
timedOutTests: TestCase[] = [];
2223

@@ -31,45 +32,56 @@ class CoderReporter implements Reporter {
3132
}
3233

3334
onStdOut(chunk: string, test?: TestCase, _?: TestResult): void {
34-
for (const line of filteredServerLogLines(chunk)) {
35-
console.log(`[stdout] ${line}`);
36-
}
35+
// If there's no associated test, just print it now
3736
if (!test) {
37+
for (const line of logLines(chunk)) {
38+
console.log(`[stdout] ${line}`);
39+
}
3840
return;
3941
}
42+
// Will be printed if the test fails
4043
this.testOutput.get(test.id)!.push([process.stdout, chunk]);
4144
}
4245

4346
onStdErr(chunk: string, test?: TestCase, _?: TestResult): void {
44-
for (const line of filteredServerLogLines(chunk)) {
45-
console.error(`[stderr] ${line}`);
46-
}
47+
// If there's no associated test, just print it now
4748
if (!test) {
49+
for (const line of logLines(chunk)) {
50+
console.error(`[stderr] ${line}`);
51+
}
4852
return;
4953
}
54+
// Will be printed if the test fails
5055
this.testOutput.get(test.id)!.push([process.stderr, chunk]);
5156
}
5257

5358
async onTestEnd(test: TestCase, result: TestResult) {
54-
console.log(`==> Finished test ${test.title}: ${result.status}`);
59+
try {
60+
if (test.expectedStatus === "skipped") {
61+
console.log(`==> Skipping test ${test.title}`);
62+
this.skippedCount++;
63+
return;
64+
}
5565

56-
if (result.status === "passed") {
57-
this.passedCount++;
58-
}
66+
console.log(`==> Finished test ${test.title}: ${result.status}`);
5967

60-
if (result.status === "failed") {
61-
this.failedTests.push(test);
62-
}
68+
if (result.status === "passed") {
69+
this.passedCount++;
70+
return;
71+
}
6372

64-
if (result.status === "timedOut") {
65-
this.timedOutTests.push(test);
66-
}
73+
if (result.status === "failed") {
74+
this.failedTests.push(test);
75+
}
76+
77+
if (result.status === "timedOut") {
78+
this.timedOutTests.push(test);
79+
}
6780

68-
const fsTestTitle = test.title.replaceAll(" ", "-");
69-
const outputFile = `test-results/debug-pprof-goroutine-${fsTestTitle}.txt`;
70-
await exportDebugPprof(outputFile);
81+
const fsTestTitle = test.title.replaceAll(" ", "-");
82+
const outputFile = `test-results/debug-pprof-goroutine-${fsTestTitle}.txt`;
83+
await exportDebugPprof(outputFile);
7184

72-
if (result.status !== "passed") {
7385
console.log(`Data from pprof has been saved to ${outputFile}`);
7486
console.log("==> Output");
7587
const output = this.testOutput.get(test.id)!;
@@ -90,13 +102,22 @@ class CoderReporter implements Reporter {
90102
console.log(attachment);
91103
}
92104
}
105+
} finally {
106+
this.testOutput.delete(test.id);
93107
}
94-
this.testOutput.delete(test.id);
95108
}
96109

97110
onEnd(result: FullResult) {
98111
console.log(`==> Tests ${result.status}`);
112+
if (!enterpriseLicense) {
113+
console.log(
114+
"==> Enterprise tests were skipped, because no license was provided",
115+
);
116+
}
99117
console.log(`${this.passedCount} passed`);
118+
if (this.skippedCount > 0) {
119+
console.log(`${this.skippedCount} skipped`);
120+
}
100121
if (this.failedTests.length > 0) {
101122
console.log(`${this.failedTests.length} failed`);
102123
for (const test of this.failedTests) {
@@ -112,11 +133,7 @@ class CoderReporter implements Reporter {
112133
}
113134
}
114135

115-
const shouldPrintLine = (line: string) =>
116-
[" error=EOF", "coderd: audit_log"].every((noise) => !line.includes(noise));
117-
118-
const filteredServerLogLines = (chunk: string): string[] =>
119-
chunk.trimEnd().split("\n").filter(shouldPrintLine);
136+
const logLines = (chunk: string): string[] => chunk.trimEnd().split("\n");
120137

121138
const exportDebugPprof = async (outputFile: string) => {
122139
const response = await axios.get(

site/e2e/tests/enterprise.spec.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { expect, test } from "@playwright/test";
2+
import { requiresEnterpriseLicense } from "../helpers";
3+
4+
test("license was added successfully", async ({ page }) => {
5+
requiresEnterpriseLicense();
6+
7+
await page.goto("/deployment/licenses", { waitUntil: "domcontentloaded" });
8+
const license = page.locator(".MuiPaper-root", { hasText: "#1" });
9+
await expect(license).toBeVisible();
10+
});

0 commit comments

Comments
 (0)