Skip to content

Commit

Permalink
Start of test cases
Browse files Browse the repository at this point in the history
Signed-off-by: worksofliam <[email protected]>
  • Loading branch information
worksofliam committed Jan 14, 2025
1 parent 1927af7 commit 57a4c99
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/api/IBMi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,19 @@ export default class IBMi {
return this.iAspInfo;
}

getIAspDetail(by: string|number) {
let asp: AspInfo|undefined;
if (typeof by === 'string') {
asp = this.iAspInfo.find(asp => asp.name === by);
} else {
asp = this.iAspInfo.find(asp => asp.id === by);
}

if (asp) {
return asp;
}
}

getIAspName(by: string|number): string|undefined {
let asp: AspInfo|undefined;
if (typeof by === 'string') {
Expand Down
76 changes: 76 additions & 0 deletions src/testing/asp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import assert from "assert";
import { randomInt } from "crypto";
import { posix } from "path";
import tmp from 'tmp';
import util, { TextDecoder } from 'util';
import { Uri, workspace } from "vscode";
import { TestSuite } from ".";
import { Tools } from "../api/Tools";
import { getMemberUri } from "../filesystems/qsys/QSysFs";
import { instance } from "../instantiate";
import { CommandResult } from "../typings";
import IBMi from "../api/IBMi";
import { Search } from "../api/Search";

const LIBNAME = `VSCODELIBT`;
const SPFNAME = `VSCODESPFT`;
const MBRNAME = `VSCODEMBRT`;

function checkAsps(connection: IBMi) {
const asps = connection.getAllIAsps();
assert.ok(asps?.length, `ASP list is empty`);

const currentAsp = connection.getCurrentIAspName();
assert.ok(currentAsp, `Current ASP not defined`);
}

async function ensureLibExists(connection: IBMi) {
const detail = connection.getIAspDetail(connection.getCurrentIAspName()!)!;
const res = await connection.runCommand({command: `CRTLIB LIB(${LIBNAME}) ASP(${detail.id})`});
}

async function createTempRpgle(connection: IBMi) {
const content = connection.getContent();

await connection.runCommand({
command: `CRTSRCPF ${LIBNAME}/${SPFNAME} MBR(*NONE)`,
environment: `ile`
});

await connection.runCommand({
command: `ADDPFM FILE(${LIBNAME}/${SPFNAME}) MBR(${MBRNAME}) `,
environment: `ile`
});

const baseContent = `**FREE\ndsply 'hello world';`;

const uploadResult = await content?.uploadMemberContent(undefined, LIBNAME, SPFNAME, MBRNAME, baseContent);
assert.ok(uploadResult);
}

export const AspSuite: TestSuite = {
name: `ASP API tests`,
before: async () => {
const connection = instance.getConnection()!;
checkAsps(connection);
await ensureLibExists(connection);
},
tests: [
{
name: `Read members in ASP and base`, test: async () => {
const connection = instance.getConnection()!;
checkAsps(connection);

await ensureLibExists(connection);
await createTempRpgle(connection);

const aspUri = getMemberUri({ asp: connection.getCurrentIAspName(), library: LIBNAME, file: SPFNAME, name: MBRNAME, extension: `rpgle` });

// We have to read it first to create the alias!
const aspMbrContents = await workspace.fs.readFile(aspUri);

assert.ok(aspMbrContents);
}
},
]
};

0 comments on commit 57a4c99

Please sign in to comment.