Skip to content

Commit da1bb6e

Browse files
committed
Run integration tests on KinD
- Introduce another environment variable in the tests, `IS_OPENSHIFT`, which indicates if the cluster is OpenShift or another k8s - Set `IS_OPENSHIFT` to true when running on Jenkins - Rewrite the tests to skip tests of OpenShift-specific features when the cluster isn't OpenShift - Modify the CI GitHub Action to run the integration tests on KinD on Linux - Report combined coverage of the unit and integration test *minor annoyance:* When deleting a namespace in the teardown step of tests, the command wouldn't return when running on a non-OpenShift Kubernetes cluster. (Note that it works fine when running the command on CLI). In order to prevent this from causing timeout errors, I don't `await` these calls. Closes #2871 Signed-off-by: David Thompson <[email protected]>
1 parent df9a58b commit da1bb6e

File tree

17 files changed

+223
-116
lines changed

17 files changed

+223
-116
lines changed

.github/workflows/continuous-integration-workflow.yml

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,6 @@ jobs:
4444
with:
4545
run: npm run test:coverage --silent
4646

47-
# Upload coverage to codecov.io
48-
- name: Codecov
49-
uses: codecov/codecov-action@40a12dcee2df644d47232dde008099a3e9e4f865 #v3.1.2
50-
if: runner.os == 'Linux'
51-
with:
52-
file: ./out/coverage/coverage-final.json
53-
5447
# UI tests fail under linux
5548
# Run UI tests
5649
- name: Run UI Tests
@@ -62,6 +55,36 @@ jobs:
6255
run: npm run public-ui-test
6356
options: -screen 0 1920x1080x24
6457

58+
- uses: engineerd/setup-kind@aa272fe2a7309878ffc2a81c56cfe3ef108ae7d0 #v0.5.0
59+
if: (success() || failure()) && runner.os == 'Linux'
60+
name: Start cluster
61+
with:
62+
version: v0.11.1
63+
64+
- name: Configure cluster
65+
if: (success() || failure()) && runner.os == 'Linux'
66+
run: |
67+
curl -sL https://github.com/operator-framework/operator-lifecycle-manager/releases/download/v0.19.1/install.sh | bash -s v0.19.1
68+
kubectl create -f https://operatorhub.io/install/service-binding-operator.yaml
69+
kubectl create -f https://operatorhub.io/install/stable/cloud-native-postgresql.yaml
70+
nb=0
71+
echo -n "Waiting for operator to show up "
72+
while [ "$nb" != "2" ]
73+
do
74+
echo -n "."
75+
sleep 1
76+
nb=`kubectl get pods -n operators --no-headers --ignore-not-found | grep Running | wc -l`
77+
done
78+
echo CLUSTER_URL=`kubectl cluster-info | sed -n -e "s/\x1B\[[0-9;]*[a-zA-Z]//g" -e '1s/.*running at \(.*\)$/\1/p'` >> $GITHUB_ENV
79+
80+
- name: Build and run integration tests
81+
if: (success() || failure()) && runner.os == 'Linux'
82+
uses: coactions/setup-xvfb@b6b4fcfb9f5a895edadc3bc76318fae0ac17c8b3 #v1.0.1
83+
env:
84+
NODE_OPTIONS: --max_old_space_size=16384
85+
with:
86+
run: npm run test-integration:coverage --silent
87+
6588
# Archiving integration tests artifacts
6689
- name: Upload test artifacts
6790
uses: actions/upload-artifact@v3
@@ -72,3 +95,9 @@ jobs:
7295
test-resources/screenshots/*.png
7396
retention-days: 2
7497

98+
# Upload coverage to codecov.io
99+
- name: Codecov
100+
uses: codecov/codecov-action@40a12dcee2df644d47232dde008099a3e9e4f865 #v3.1.2
101+
if: (success() || failure()) && runner.os == 'Linux'
102+
with:
103+
files: ./coverage/unit/coverage-final.json,./coverage/integration/coverage-final.json

coverconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"enabled": true,
33
"relativeSourcePath": "../../src",
4-
"relativeCoverageDir": "../../coverage",
4+
"relativeCoverageDir": "../../../coverage",
55
"ignorePatterns": [
66
"**/node_modules/**"
77
],

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"compile:checkWebviews": "tsc -p ./src/webview -noEmit",
5858
"compile:webviews": "node ./build/esbuild.mjs",
5959
"watch": "node ./build/esbuild-watch.mjs",
60-
"clean": "shx rm -rf out/build out/coverage out/src out/test out/tools out/test-resources out/*Viewer out/**.tsbuildinfo",
60+
"clean": "shx rm -rf out/build out/src out/test out/tools out/test-resources out/*Viewer out/**.tsbuildinfo",
6161
"lint": "eslint . --ext .ts --quiet",
6262
"lint-fix": "eslint . --ext .ts --fix",
6363
"lint-nic": "eslint . --ext .ts --no-inline-config",
@@ -69,7 +69,6 @@
6969
"test:instrument": "shx rm -rf out/src-orig && shx mv out/src out/src-orig && istanbul instrument --complete-copy --embed-source --output out/src out/src-orig",
7070
"test:coverage": "npm run build && npm run test:instrument && node ./out/build/install-vscode.js && node ./out/build/run-tests.js unit",
7171
"update-deps": "ncu --upgrade --loglevel verbose --packageFile package.json && npm update",
72-
"coverage:upload": "codecov -f coverage/coverage-final.json",
7372
"build": "npm run clean && npm run lint && npm run compile && npm run bundle-tools",
7473
"cluster-ui-test": "extest setup-and-run out/test/ui/cluster-ui-test.js -o test/ui/settings.json -m test/ui/.mocharc.js -e ./test-resources/extensions -c max -i",
7574
"public-ui-test": "extest setup-and-run out/test/ui/public-ui-test.js -o test/ui/settings.json -m test/ui/.mocharc.js -e ./test-resources/extensions -c max -i"

src/cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export class CliChannel implements Cli {
8989
this.odoChannel.show();
9090
}
9191

92-
async execute(cmd: string, opts: cp.ExecOptions = {}): Promise<CliExitData> {
92+
execute(cmd: string, opts: cp.ExecOptions = {}): Promise<CliExitData> {
9393
return new Promise<CliExitData>((resolve) => {
9494
if (opts.maxBuffer === undefined) {
9595
opts.maxBuffer = 2 * 1024 * 1024;
@@ -139,7 +139,7 @@ export class CliChannel implements Cli {
139139
return optsCopy;
140140
}
141141

142-
async executeTool(command: CommandText, opts?: cp.ExecOptions, fail = false): Promise<CliExitData> {
142+
async executeTool(command: CommandText, opts?: cp.ExecOptions, fail = true): Promise<CliExitData> {
143143
const commandActual = command.toString();
144144
const commandPrivacy = command.privacyMode(true).toString();
145145
const [cmd] = commandActual.split(' ');

src/explorer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
238238
result = [...await this.odo3.getDeploymentConfigs(), ...await this.odo3.getDeployments(), ...await Helm.getHelmReleases()];
239239
}
240240
// don't show Open In Developer Dashboard if not openshift cluster
241-
const openshiftResources = await CliChannel.getInstance().executeTool(Command.isOpenshiftCluster());
241+
const openshiftResources = await CliChannel.getInstance().executeTool(Command.isOpenshiftCluster(), undefined, false);
242242
let isOpenshiftCluster = true;
243243
if (openshiftResources.stdout.length === 0){
244244
isOpenshiftCluster = false;

src/odo/command.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ export class Command {
260260
return new CommandText('oc whoami -t');
261261
}
262262

263+
/**
264+
* Only works for OpenShift clusters
265+
*/
263266
static showConsoleUrl(): CommandText {
264267
return new CommandText('oc get configmaps console-public -n openshift-config-managed -o json');
265268
}

src/openshift/project.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ import { CliChannel } from '../cli';
1010
import { OpenShiftExplorer } from '../explorer';
1111
import { getInstance as getOdoInstance } from '../odo';
1212
import { Progress } from '../util/progress';
13-
import { VsCommandError, vsCommand } from '../vscommand';
13+
import { vsCommand, VsCommandError } from '../vscommand';
1414
import OpenShiftItem from './openshiftItem';
1515

1616
export class Command {
1717
static setActiveProject(name: string) {
18-
return new CommandText('oc', `project ${name}`);
18+
return new CommandText('odo', `set namespace ${name}`);
1919
}
2020

2121
static deleteProject(name: string) {
22-
return new CommandText('oc delete project', name, [new CommandOption('--wait=true')])
22+
return new CommandText('odo delete namespace', name, [new CommandOption('--wait=true'), new CommandOption('-f')])
2323
}
2424

2525
static getAll(namespace: string) {

test/coverage.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,10 @@
99

1010
import paths = require('path');
1111
import fs = require('fs');
12-
12+
import * as mkdirp from 'mkdirp';
1313
const istanbul = require('istanbul');
1414
const remapIstanbul = require('remap-istanbul');
1515

16-
function _mkDirIfExists(dir: string): void {
17-
if (!fs.existsSync(dir)) {
18-
fs.mkdirSync(dir);
19-
}
20-
}
21-
2216
export interface TestRunnerOptions {
2317
relativeCoverageDir?: string;
2418
relativeSourcePath?: string;
@@ -43,7 +37,7 @@ export class CoverageRunner {
4337
*
4438
* @memberOf CoverageRunner
4539
*/
46-
public reportCoverage(): void {
40+
public async reportCoverage(): Promise<void> {
4741
// istanbul.hook.unhookRequire();
4842

4943
if (typeof global[this.coverageVar] === 'undefined' || Object.keys(global[this.coverageVar]).length === 0) {
@@ -58,8 +52,7 @@ export class CoverageRunner {
5852
const coverageFile = paths.resolve(reportingDir, `coverage${pidExt}.json`);
5953

6054
// yes, do this again since some test runners could clean the dir initially created
61-
_mkDirIfExists(reportingDir);
62-
55+
await mkdirp(reportingDir);
6356
fs.writeFileSync(coverageFile, JSON.stringify(cov), 'utf8');
6457

6558
const remappedCollector = remapIstanbul.remap(cov, {
@@ -74,5 +67,6 @@ export class CoverageRunner {
7467
reporter.write(remappedCollector, true, () => {
7568
console.log(`Reports written to ${reportingDir}`);
7669
});
70+
7771
}
7872
}

0 commit comments

Comments
 (0)