Skip to content

Commit 1606901

Browse files
authored
Migrated OpenPolicyInstallerV0 task to Node10 (#16836)
Co-authored-by: Stanislav Balia <[email protected]>
1 parent 54890ae commit 1606901

21 files changed

+995
-150
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ Tasks/NuGetToolInstallerV0/ @phil-hodgson @aasim
317317

318318
Tasks/NuGetToolInstallerV1/ @phil-hodgson @aasim
319319

320-
Tasks/OpenPolicyAgentInstallerV0/ @Anumita
320+
Tasks/OpenPolicyAgentInstallerV0/
321321

322322
Tasks/PackerBuildV0/ @bishal-pdmsft
323323

Lines changed: 98 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,109 @@
11
import fs = require('fs');
22
import assert = require('assert');
33
import path = require('path');
4+
import * as ttm from 'azure-pipelines-task-lib/mock-test';
45

56
describe('OpenPolicyAgentInstallerV0 Suite', function () {
6-
before(() => {
7+
it('Task should have succeeded with no issues', (done: Mocha.Done) => {
8+
const tp: string = path.join(__dirname, 'L0ValidRunShouldSucceed.js');
9+
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
10+
11+
tr.run();
12+
assert.strictEqual(tr.errorIssues.length, 0);
13+
assert.strictEqual(tr.stderr.length, 0);
14+
assert(tr.stdOutContained('VerifyOpaInstallation'));
15+
assert(tr.succeeded, 'task should have succeeded');
16+
done();
17+
}).timeout(20000);
18+
19+
it('Invalid semver versino should fail', (done: Mocha.Done) => {
20+
const tp: string = path.join(__dirname, 'L0InvalidSemVerVersionShouldFail.js');
21+
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
22+
23+
tr.run();
24+
assert.strictEqual(tr.errorIssues.length, 1);
25+
assert(tr.stdOutContained('NotAValidSemverVersion'));
26+
assert(tr.failed, 'task should have fail');
27+
done();
28+
});
29+
30+
it('Download OPA from location should fail', (done: Mocha.Done) => {
31+
const tp: string = path.join(__dirname, 'L0DownloadOpaFromLocationShouldFail.js');
32+
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
33+
34+
tr.run();
35+
assert.strictEqual(tr.errorIssues.length, 1);
36+
assert(tr.stdOutContained('DownloadOpaFailedFromLocation'));
37+
assert(tr.failed, 'task should have fail');
38+
done();
39+
});
40+
41+
it('getStableOpaVersion should log "OpaLatestNotKnown" exception and fail', (done: Mocha.Done) => {
42+
const tp: string = path.join(__dirname, 'L0DownloadOpaFromLocationShouldFail.js');
43+
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
44+
45+
tr.run();
46+
assert.strictEqual(tr.errorIssues.length, 1);
47+
assert(tr.stdOutContained('OpaLatestNotKnown'));
48+
assert(tr.failed, 'task should have fail');
49+
done();
50+
});
51+
52+
it('Download stable OPA version for Windows should fail', (done: Mocha.Done) => {
53+
const tp: string = path.join(__dirname, 'L0DownloadOpaForWindowsShouldFail.js');
54+
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
55+
56+
tr.run();
57+
assert.strictEqual(tr.errorIssues.length, 1);
58+
assert(tr.stdOutContained('https://github.com/open-policy-agent/opa/releases/download/v0.13.5/opa_windows_amd64.exe'));
59+
assert(tr.stdOutContained('DownloadOpaFailedFromLocation'));
60+
assert(tr.failed, 'task should have fail');
61+
done();
62+
});
63+
64+
it('Download stable OPA version for Linux should fail', (done: Mocha.Done) => {
65+
const tp: string = path.join(__dirname, 'L0DownloadOpaForLinuxShouldFail.js');
66+
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
67+
68+
tr.run();
69+
assert.strictEqual(tr.errorIssues.length, 1);
70+
assert(tr.stdOutContained('https://github.com/open-policy-agent/opa/releases/download/v0.13.5/opa_linux_amd64'));
71+
assert(tr.stdOutContained('DownloadOpaFailedFromLocation'));
72+
assert(tr.failed, 'task should have fail');
73+
done();
774
});
875

9-
after(() => {
76+
it('Download stable OPA version for MacOS should fail', (done: Mocha.Done) => {
77+
const tp: string = path.join(__dirname, 'L0DownloadOpaForMacOsShouldFail.js');
78+
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
79+
80+
tr.run();
81+
assert.strictEqual(tr.errorIssues.length, 1);
82+
assert(tr.stdOutContained('https://github.com/open-policy-agent/opa/releases/download/v0.13.5/opa_darwin_amd64'));
83+
assert(tr.stdOutContained('DownloadOpaFailedFromLocation'));
84+
assert(tr.failed, 'task should have fail');
85+
done();
1086
});
1187

12-
it('Does a basic hello world test', function(done: MochaDone) {
13-
// TODO - add real tests
88+
it('Download stable OPA version for unknown OS type should fail', (done: Mocha.Done) => {
89+
const tp: string = path.join(__dirname, 'L0DownloadOpaForUnknownOsTypeShouldFail.js');
90+
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
91+
92+
tr.run();
93+
assert.strictEqual(tr.errorIssues.length, 1);
94+
assert(tr.stdOutContained('Unknown OS type'));
95+
assert(tr.failed, 'task should have fail');
96+
done();
97+
});
98+
99+
it('Download specific OPA version should fail', (done: Mocha.Done) => {
100+
const tp: string = path.join(__dirname, 'L0DownloadSpecificOpaVersionShouldFail.js');
101+
const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
102+
103+
tr.run();
104+
assert.strictEqual(tr.errorIssues.length, 1);
105+
assert(tr.stdOutContained('https://github.com/open-policy-agent/opa/releases/download/v1.0.0'));
106+
assert(tr.failed, 'task should have fail');
14107
done();
15108
});
16-
});
109+
});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import tmrm = require('azure-pipelines-task-lib/mock-run');
2+
import path = require('path');
3+
import { registerMockedFsLib, registerMockedTaskLib, registerMockedToolLib, registerMockedToolRunner } from './OpenPolicyAgentInstallerTestHelper';
4+
5+
const taskPath = path.join(__dirname, '..', 'src', 'opatoolinstaller.js');
6+
const tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);
7+
8+
//mocking taskLib
9+
registerMockedTaskLib(tr);
10+
11+
//simple mock for ToolRunner class
12+
registerMockedToolRunner(tr);
13+
14+
//mocking fs methods
15+
registerMockedFsLib(tr);
16+
17+
//mocking task lib methods
18+
registerMockedToolLib(tr, {findLocalToolFuncReturnValue: null, throwInPromise: true});
19+
20+
tr.registerMock('os', { type: () => 'Linux'});
21+
22+
tr.run();
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import tmrm = require('azure-pipelines-task-lib/mock-run');
2+
import path = require('path');
3+
import { registerMockedFsLib, registerMockedTaskLib, registerMockedToolLib, registerMockedToolRunner } from './OpenPolicyAgentInstallerTestHelper';
4+
5+
const taskPath = path.join(__dirname, '..', 'src', 'opatoolinstaller.js');
6+
const tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);
7+
8+
//mocking taskLib
9+
registerMockedTaskLib(tr);
10+
11+
//simple mock for ToolRunner class
12+
registerMockedToolRunner(tr);
13+
14+
//mocking fs methods
15+
registerMockedFsLib(tr);
16+
17+
//mocking task lib methods
18+
registerMockedToolLib(tr, {findLocalToolFuncReturnValue: null, throwInPromise: true});
19+
20+
tr.registerMock('os', { type: () => 'Darwin'});
21+
22+
tr.run();
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import tmrm = require('azure-pipelines-task-lib/mock-run');
2+
import path = require('path');
3+
import { registerMockedFsLib, registerMockedTaskLib, registerMockedToolLib, registerMockedToolRunner } from './OpenPolicyAgentInstallerTestHelper';
4+
5+
const taskPath = path.join(__dirname, '..', 'src', 'opatoolinstaller.js');
6+
const tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);
7+
8+
//mocking taskLib
9+
registerMockedTaskLib(tr);
10+
11+
//simple mock for ToolRunner class
12+
registerMockedToolRunner(tr);
13+
14+
//mocking fs methods
15+
registerMockedFsLib(tr);
16+
17+
//mocking task lib methods
18+
registerMockedToolLib(tr, {findLocalToolFuncReturnValue: null, throwInPromise: true});
19+
20+
tr.registerMock('os', { type: () => 'some other os'});
21+
22+
tr.run();
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import tmrm = require('azure-pipelines-task-lib/mock-run');
2+
import path = require('path');
3+
import { registerMockedFsLib, registerMockedTaskLib, registerMockedToolLib, registerMockedToolRunner } from './OpenPolicyAgentInstallerTestHelper';
4+
5+
const taskPath = path.join(__dirname, '..', 'src', 'opatoolinstaller.js');
6+
const tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);
7+
8+
//mocking taskLib
9+
registerMockedTaskLib(tr);
10+
11+
//simple mock for ToolRunner class
12+
registerMockedToolRunner(tr);
13+
14+
//mocking fs methods
15+
registerMockedFsLib(tr);
16+
17+
//mocking task lib methods
18+
registerMockedToolLib(tr, {findLocalToolFuncReturnValue: null, throwInPromise: true});
19+
20+
tr.registerMock('os', { type: () => 'Windows_NT'});
21+
22+
tr.run();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import tmrm = require('azure-pipelines-task-lib/mock-run');
2+
import path = require('path');
3+
import { registerMockedFsLib, registerMockedTaskLib, registerMockedToolLib, registerMockedToolRunner } from './OpenPolicyAgentInstallerTestHelper';
4+
5+
const taskPath = path.join(__dirname, '..', 'src', 'opatoolinstaller.js');
6+
const tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);
7+
8+
//mocking taskLib
9+
registerMockedTaskLib(tr);
10+
11+
//simple mock for ToolRunner class
12+
registerMockedToolRunner(tr);
13+
14+
//mocking fs methods
15+
registerMockedFsLib(tr);
16+
17+
//mocking task lib methods
18+
registerMockedToolLib(tr, {findLocalToolFuncReturnValue: null, throwInPromise: true});
19+
20+
tr.run();
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import tmrm = require('azure-pipelines-task-lib/mock-run');
2+
import path = require('path');
3+
import { registerMockedFsLib, registerMockedTaskLib, registerMockedToolLib, registerMockedToolRunner } from './OpenPolicyAgentInstallerTestHelper';
4+
5+
const taskPath = path.join(__dirname, '..', 'src', 'opatoolinstaller.js');
6+
const tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);
7+
8+
tr.setInput('opaVersion', ' = 1.0.0 ');
9+
10+
//mocking taskLib
11+
registerMockedTaskLib(tr);
12+
13+
//simple mock for ToolRunner class
14+
registerMockedToolRunner(tr);
15+
16+
//mocking fs methods
17+
registerMockedFsLib(tr);
18+
19+
//mocking task lib methods
20+
registerMockedToolLib(tr, {findLocalToolFuncReturnValue: null, throwInPromise: true, cleanVersionFuncReturnValue: '1.0.0'});
21+
22+
tr.run();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import tmrm = require('azure-pipelines-task-lib/mock-run');
2+
import path = require('path');
3+
import { registerMockedFsLib, registerMockedTaskLib, registerMockedToolLib, registerMockedToolRunner } from './OpenPolicyAgentInstallerTestHelper';
4+
5+
const taskPath = path.join(__dirname, '..', 'src', 'opatoolinstaller.js');
6+
const tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);
7+
8+
//mocking taskLib
9+
registerMockedTaskLib(tr);
10+
11+
//simple mock for ToolRunner class
12+
registerMockedToolRunner(tr);
13+
14+
//mocking fs methods
15+
registerMockedFsLib(tr);
16+
17+
//mocking task lib methods
18+
registerMockedToolLib(tr, {findLocalToolFuncReturnValue: null, throwInPromise: true});
19+
20+
tr.run();
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import tmrm = require('azure-pipelines-task-lib/mock-run');
2+
import path = require('path');
3+
import { registerMockedFsLib, registerMockedTaskLib, registerMockedToolLib, registerMockedToolRunner } from './OpenPolicyAgentInstallerTestHelper';
4+
5+
const taskPath = path.join(__dirname, '..', 'src', 'opatoolinstaller.js');
6+
const tr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);
7+
8+
tr.setInput('opaVersion', 'someVersion');
9+
10+
//mocking taskLib
11+
registerMockedTaskLib(tr);
12+
13+
//simple mock for ToolRunner class
14+
registerMockedToolRunner(tr);
15+
16+
//mocking fs methods
17+
registerMockedFsLib(tr);
18+
19+
//mocking task lib methods
20+
registerMockedToolLib(tr, {cleanVersionFuncReturnValue: null});
21+
22+
tr.run();

0 commit comments

Comments
 (0)