-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
144 lines (126 loc) · 5.04 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import * as shell from '@RUNTIME@/bin/libs/shell'
import * as testCases from './testCases';
import * as print from './lib/print';
import * as ds from './lib/ds';
import * as misc from './lib/misc';
import * as env from './lib/env';
const RUNTIME='@RUNTIME@'
const ZWE=`${RUNTIME}/bin/zwe`;
const EXPORT = `export ZWE_PRIVATE_CLI_LIBRARY_LOADED=''`; // Bypassing the bug
const SEVERITY = { INFO: 0, OTHER: 1, ERROR: 2 }
const PRINT = true;
const TESTS = {
...testCases.ALL
}
function subStringInResult(expected, included, result, results, skipCounter) {
if (expected) {
const INCLUDED_INFO = included == true ? SEVERITY.INFO : SEVERITY.ERROR;
const INCLUDED_ERROR = included == true ? SEVERITY.ERROR : SEVERITY.INFO;
let expectedArray = [];
if (typeof expected == 'object') {
expectedArray = expected;
} else {
expectedArray[0] = expected;
}
for (let str in expectedArray) {
if (result.out.includes(expectedArray[str])) {
results.push(print.formatMsg(INCLUDED_INFO, PRINT, skipCounter, `'${expectedArray[str]}' found`, ''));
} else {
results.push(print.formatMsg(INCLUDED_ERROR, PRINT, skipCounter, `'${expectedArray[str]}' not found`, ''));
}
}
}
}
let results = [];
const total = Object.keys(TESTS).length;
const totalLength = total.toString().length;
let currentTest = 1;
let afterEnvironment = [];
// For sure, unset ZWE_CLI_PARAMETER_CONFIG
env.exportEnv('ZWE_CLI_PARAMETER_CONFIG', '');
const loopStart = Date.now();
for (let test in TESTS) {
let counter = `${currentTest.toString().padStart(totalLength)}/${total}`;
currentTest++
let rest = `${ZWE} ${TESTS[test].parms}`;
let expectedRC = 0;
let expectedOut = undefined;
let expectedSubStr = undefined;
let expectedSubStrX = undefined;
let description = undefined;
if (typeof TESTS[test].expected == 'number') {
expectedRC = TESTS[test].expected % 256;
}
if (typeof TESTS[test].expected == 'object') {
expectedRC = TESTS[test].expected.rc == undefined ? 0 : (TESTS[test].expected.rc % 256);
expectedOut = TESTS[test].expected.out;
expectedSubStr = TESTS[test].expected.substr;
expectedSubStrX = TESTS[test].expected.substrx;
}
if (TESTS[test].desc) {
description = TESTS[test].desc;
}
// *** Before actions ***
print.debug(`${counter}`, rest, print.YELLOW);
if (TESTS[test].environment) {
TESTS[test].environment.forEach(env => {
if (env[2] === undefined) {
afterEnvironment.push([env[0], '']);
}
if (env[2] === ENV_RESTORE) {
afterEnvironment.push([env[0], `${std.getenv(`${env[0]}`)}`]);
}
env.exportEnv(env[0], env[1]);
})
}
if (TESTS[test].before) {
ds.allocJCL(TESTS[test].before.allocJCL);
ds.allocLoad(TESTS[test].before.allocLoad);
ds.listMB(TESTS[test].before.listMB);
ds.listDS(TESTS[test].before.listDS)
ds.deleteDS(TESTS[test].before.deleteDS);
misc.shellCmd(TESTS[test].before.shellCmd);
}
const result = shell.execOutSync('sh', '-c', `${EXPORT} && ${ZWE} ${TESTS[test].parms}`);
print.debug('Output', "\n" + result.out);
let info = `expected rc=${expectedRC.toString().padStart(3)}, result rc=${result.rc.toString().padStart(3)}`;
if (result.rc == expectedRC) {
results.push(print.formatMsg(SEVERITY.INFO, PRINT, counter, info, rest));
} else {
results.push(print.formatMsg(SEVERITY.ERROR, PRINT, counter, info, rest));
}
const skipCounter = ' '.repeat(counter.length);
if (expectedOut || expectedOut == '') {
if (result.out == expectedOut) {
results.push(print.formatMsg(SEVERITY.INFO, PRINT, skipCounter, 'output match', ''));
} else {
results.push(print.formatMsg(SEVERITY.ERROR, PRINT, skipCounter, 'output not matched', ''));
}
}
if (description) {
results.push(print.formatMsg(SEVERITY.OTHER, PRINT, skipCounter, 'Description', description));
}
subStringInResult(expectedSubStr, true, result, results, skipCounter);
subStringInResult(expectedSubStrX, false, result, results, skipCounter);
// *** After actions ***
if (afterEnvironment.length) {
afterEnvironment.forEach(env => {
env.exportEnv(env[0], env[1]);
})
}
if (TESTS[test].after) {
ds.allocJCL(TESTS[test].after.allocJCL);
ds.allocLoad(TESTS[test].after.allocLoad);
ds.listMB(TESTS[test].after.listMB);
ds.listDS(TESTS[test].after.listDS)
ds.deleteDS(TESTS[test].after.deleteDS);
misc.shellCmd(TESTS[test].after.shellCmd);
}
print.debug(`${counter}`, '-'.repeat(32) + "\n", print.YELLOW);
}
const loopEnd = Date.now();
print.debug('Time elapsed', `${new Date(loopEnd-loopStart).toISOString().slice(11,19)}`)
console.log(print.CYAN + `${print.decorate('test overview')}` + print.RESET);
results.forEach(res => {
console.log(res);
})