-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: worksofliam <[email protected]>
- Loading branch information
1 parent
1927af7
commit 57a4c99
Showing
2 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}, | ||
] | ||
}; |