Skip to content

Commit

Permalink
Added "Listing objects with variants" unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Seb Julliand <[email protected]>
  • Loading branch information
sebjulliand committed Aug 9, 2024
1 parent a5dc4f6 commit f7acb72
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/api/IBMiContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ export default class IBMiContent {
const singleEntry = filters.filterType !== 'regex' ? singleGenericName(filters.object) : undefined;
const nameFilter = parseFilter(filters.object, filters.filterType);
const objectFilter = filters.object && (nameFilter.noFilter || singleEntry) && filters.object !== `*` ? this.ibmi.upperCaseName(filters.object) : undefined;
const objectNameLike = () => objectFilter ? ` and t.SYSTEM_TABLE_NAME ${(objectFilter.includes('*') ? ` like ` : ` = `)} '${objectFilter.replace('*', '%')}'` : '';
const objectNameLike = () => objectFilter ? ` and t.SYSTEM_TABLE_NAME ${(objectFilter.includes('*') ? ` like ` : ` = `)} '${this.ibmi.sysNameInAmerican(objectFilter).replace('*', '%')}'` : '';
const objectName = () => objectFilter ? `, OBJECT_NAME => '${objectFilter}'` : '';

const typeFilter = filters.types && filters.types.length > 1 ? (t: string) => filters.types?.includes(t) : undefined;
Expand Down
70 changes: 69 additions & 1 deletion src/testing/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { TestSuite } from ".";
import { Tools } from "../api/Tools";
import { getMemberUri } from "../filesystems/qsys/QSysFs";
import { instance } from "../instantiate";
import { CommandResult } from "../typings";
import { CommandResult, IBMiObject } from "../typings";

export const ContentSuite: TestSuite = {
name: `Content API tests`,
Expand Down Expand Up @@ -786,6 +786,74 @@ export const ContentSuite: TestSuite = {
throw new Error("No temporary library defined in configuration");
}
}
},
{
name: "Listing objects with variants",
test: async () => {
const connection = instance.getConnection();
const content = instance.getConnection()?.content;
if (connection && content && connection.getEncoding().ccsid !== 37) {
const ccsid = connection.getEncoding().ccsid;
let library = `TESTLIB${connection.variantChars.local}`;
let skipLibrary = false;
const sourceFile = `TESTFIL${connection.variantChars.local}`;
const members: string[] = [];
for (let i = 0; i < 5; i++) {
members.push(`TSTMBR${connection.variantChars.local}${i}`);
}
try {
const crtLib = await connection.runCommand({ command: `CRTLIB LIB(${library}) TYPE(*PROD)`, noLibList: true });
if (Tools.parseMessages(crtLib.stderr).findId("CPD0032")) {
//Not authorized: carry on, skip library name test
library = connection.config?.tempLibrary!;
skipLibrary = true
}
const crtSrcPF = await connection.runCommand({ command: `CRTSRCPF FILE(${library}/${sourceFile}) RCDLEN(112) CCSID(${ccsid})`, noLibList: true });
if ((crtLib.code === 0 || skipLibrary) && crtSrcPF.code === 0) {
for (const member of members) {
const addPFM = await connection.runCommand({ command: `ADDPFM FILE(${library}/${sourceFile}) MBR(${member}) SRCTYPE(TXT)`, noLibList: true });
if (addPFM.code !== 0) {
throw new Error(`Failed to create member ${member}: ${addPFM.stderr}`);
}
}
}
else {
throw new Error(`Failed to create library and source file: ${crtLib.stderr || crtLib.stderr}`)
}

if (!skipLibrary) {
const [expectedLibrary] = await content.getLibraries({ library });
assert.ok(expectedLibrary);
assert.strictEqual(library, expectedLibrary.name);
}

const checkFile = (expectedObject: IBMiObject) => {
assert.ok(expectedObject);
assert.ok(expectedObject.sourceFile, `${expectedObject.name} not a source file`);
assert.strictEqual(expectedObject.name, sourceFile);
assert.strictEqual(expectedObject.library, library);
};

const [expectedObject] = await content.getObjectList({ library, object: sourceFile, types: ["*ALL"] });
checkFile(expectedObject);

const [expectedSourceFile] = await content.getObjectList({ library, object: sourceFile, types: ["*SRCPF"] });
checkFile(expectedSourceFile);

const expectedMembers = await content.getMemberList({ library, sourceFile });
assert.ok(expectedMembers);
assert.ok(expectedMembers.every(member => members.find(m => m === member.name)));
}
finally {
if (!skipLibrary && await content.checkObject({ library: "QSYS", name: library, type: "*LIB" })) {
await connection.runCommand({ command: `DLTLIB LIB(${library})`, noLibList: true })
}
if (skipLibrary && await content.checkObject({ library, name: sourceFile, type: "*FILE" })) {
await connection.runCommand({ command: `DLTF FILE(${library}/${sourceFile})`, noLibList: true })
}
}
}
}
}
]
};

0 comments on commit f7acb72

Please sign in to comment.