-
Notifications
You must be signed in to change notification settings - Fork 135
Expand file tree
/
Copy pathasp.test.ts
More file actions
93 lines (75 loc) · 2.74 KB
/
asp.test.ts
File metadata and controls
93 lines (75 loc) · 2.74 KB
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
import assert from "assert";
import { afterAll, beforeAll, beforeEach, describe, expect, it } from "vitest";
import IBMi from "../../IBMi";
import { SearchTools } from "../../SearchTools";
import { CONNECTION_TIMEOUT, disposeConnection, newConnection } from "../connection";
const LIBNAME = `VSCODELIBT`;
const SPFNAME = `VSCODESPFT`;
const MBRNAME = `VSCODEMBRT`;
function checkAsps(connection: IBMi) {
const asps = connection.getAllIAsps();
if (asps.length === 0) return false;
const currentAsp = connection.getCurrentIAspName();
if (!currentAsp) return false;
return true;
}
async function ensureLibExists(connection: IBMi) {
const detail = connection.getIAspDetail(connection.getCurrentIAspName()!)!;
const res = await connection.runCommand({ command: `QSYS/CRTLIB LIB(${LIBNAME}) ASPDEV(${detail.name})` });
if (res.code) {
assert.strictEqual(res.code, 0, res.stderr || res.stdout);
}
}
async function createTempRpgle(connection: IBMi) {
const content = connection.getContent();
await connection.runCommand({
command: `QSYS/CRTSRCPF ${LIBNAME}/${SPFNAME} MBR(*NONE)`,
environment: `ile`
});
await connection.runCommand({
command: `QSYS/ADDPFM FILE(${LIBNAME}/${SPFNAME}) MBR(${MBRNAME}) `,
environment: `ile`
});
const baseContent = `**FREE\ndsply 'hello world';`;
return await content?.uploadMemberContent(LIBNAME, SPFNAME, MBRNAME, baseContent);
}
describe(`iASP tests`, { concurrent: true }, () => {
let connection: IBMi
let skipAsp = false;
beforeAll(async () => {
connection = await newConnection();
if (checkAsps(connection)) {
await ensureLibExists(connection);
await createTempRpgle(connection);
} else {
console.log(`Skipping iASP tests, no ASPs found.`);
skipAsp = true;
}
}, CONNECTION_TIMEOUT)
afterAll(async () => {
await connection.runCommand({ command: `QSYS/DLTLIB LIB(${LIBNAME})` });
await disposeConnection(connection);
});
beforeEach((t) => {
if (skipAsp) {
t.skip();
}
});
it('Read members in ASP and base', async () => {
const aspMbrContents = await connection.getContent()?.downloadMemberContent(LIBNAME, SPFNAME, MBRNAME);
assert.ok(aspMbrContents);
});
it('can find ASP members via search', async () => {
const searchResults = await SearchTools.searchMembers(connection, LIBNAME, SPFNAME, `hello world`, `*`);
expect(searchResults.hits.length).toBeGreaterThan(0);
// TODO: additional expects
});
it('can resolve member info from ASP', async () => {
const resolved = await connection.getContent().memberResolve(MBRNAME, [
{ library: `QSYS`, name: `QSYSINC` },
{ library: LIBNAME, name: SPFNAME }
]);
expect(resolved).toBeDefined();
//TODO: additional expects
});
});