Skip to content

Commit

Permalink
No more global setup for the connection since not all suites require …
Browse files Browse the repository at this point in the history
…a connection

Signed-off-by: worksofliam <[email protected]>
  • Loading branch information
worksofliam committed Jan 17, 2025
1 parent 1c2bbc6 commit 85b5e3b
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 178 deletions.
4 changes: 2 additions & 2 deletions src/api/IBMi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1097,12 +1097,12 @@ export default class IBMi {
*/
getTempRemote(key: string) {
if (this.tempRemoteFiles[key] !== undefined) {
console.log(`Using existing temp: ${this.tempRemoteFiles[key]}`);
// console.log(`Using existing temp: ${this.tempRemoteFiles[key]}`);
return this.tempRemoteFiles[key];
} else
if (this.config) {
let value = path.posix.join(this.config.tempDir, `vscodetemp-${Tools.makeid()}`);
console.log(`Using new temp: ${value}`);
// console.log(`Using new temp: ${value}`);
this.tempRemoteFiles[key] = value;
return value;
}
Expand Down
33 changes: 5 additions & 28 deletions src/api/tests/globalSetup.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import assert from "assert";
import IBMi from "../IBMi";
import { ENV_CREDS } from "./env";
import { getConnection, setConnection } from "./state";
import { afterAll, beforeAll, expect } from "vitest";
import { CodeForIStorage } from "../configuration/storage/CodeForIStorage";
import { VirtualConfig } from "../configuration/config/VirtualConfig";
import { VirtualStorage } from "../configuration/storage/BaseStorage";
import { CustomQSh } from "../components/cqsh";
import path from "path";
import { CopyToImport } from "../components/copyToImport";
Expand Down Expand Up @@ -71,28 +68,8 @@ export async function newConnection() {
return conn;
}

beforeAll(async () => {
const virtualStorage = testStorage;

IBMi.GlobalStorage = new CodeForIStorage(virtualStorage);
IBMi.connectionManager.configMethod = testConfig;

await testStorage.load();
await testConfig.load();

const conn = await newConnection();

setConnection(conn);
}, 10000000);

afterAll(async () => {
const conn = getConnection();

if (conn) {
await conn.dispose();
await testStorage.save();
await testConfig.save();
} else {
assert.fail(`Connection was not set`);
}
})
export function disposeConnection(conn: IBMi) {
conn.dispose();

Check failure on line 72 in src/api/tests/globalSetup.ts

View workflow job for this annotation

GitHub Actions / Test runner

tests/suites/components.test.ts > Component Tests

TypeError: Cannot read properties of undefined (reading 'dispose') ❯ Module.disposeConnection tests/globalSetup.ts:72:8 ❯ tests/suites/components.test.ts:15:5

Check failure on line 72 in src/api/tests/globalSetup.ts

View workflow job for this annotation

GitHub Actions / Test runner

tests/suites/connection.test.ts > connection tests

TypeError: Cannot read properties of undefined (reading 'dispose') ❯ Module.disposeConnection tests/globalSetup.ts:72:8 ❯ tests/suites/connection.test.ts:15:5

Check failure on line 72 in src/api/tests/globalSetup.ts

View workflow job for this annotation

GitHub Actions / Test runner

tests/suites/content.test.ts > Content Tests

TypeError: Cannot read properties of undefined (reading 'dispose') ❯ Module.disposeConnection tests/globalSetup.ts:72:8 ❯ tests/suites/content.test.ts:17:5

Check failure on line 72 in src/api/tests/globalSetup.ts

View workflow job for this annotation

GitHub Actions / Test runner

tests/suites/encoding.test.ts > Encoding tests

TypeError: Cannot read properties of undefined (reading 'dispose') ❯ Module.disposeConnection tests/globalSetup.ts:72:8 ❯ tests/suites/encoding.test.ts:49:5

Check failure on line 72 in src/api/tests/globalSetup.ts

View workflow job for this annotation

GitHub Actions / Test runner

tests/suites/search.test.ts > Search Tests

TypeError: Cannot read properties of undefined (reading 'dispose') ❯ Module.disposeConnection tests/globalSetup.ts:72:8 ❯ tests/suites/search.test.ts:14:5
testStorage.save();
testConfig.save();
}
11 changes: 0 additions & 11 deletions src/api/tests/state.ts

This file was deleted.

14 changes: 10 additions & 4 deletions src/api/tests/suites/components.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import { describe, it, expect } from 'vitest';
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
import { GetMemberInfo } from '../../components/getMemberInfo';
import { GetNewLibl } from '../../components/getNewLibl';
import { Tools } from '../../Tools';
import { getConnection } from '../state';
import IBMi from '../../IBMi';
import { disposeConnection, newConnection } from '../globalSetup';

describe('Component Tests', () => {
let connection: IBMi
beforeAll(async () => {
connection = await newConnection();
})

afterAll(async () => {
disposeConnection(connection);
});

it('Get new libl', async () => {
const connection = getConnection();
const component = connection.getComponent<GetNewLibl>(GetNewLibl.ID);

if (component) {
Expand All @@ -20,7 +27,6 @@ describe('Component Tests', () => {
});

it('Check getMemberInfo', async () => {
const connection = getConnection();
const component = connection?.getComponent<GetMemberInfo>(GetMemberInfo.ID)!;

expect(component).toBeTruthy();
Expand Down
75 changes: 38 additions & 37 deletions src/api/tests/suites/connection.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@

import { expect, test, describe } from 'vitest'
import { getConnection } from '../state'
import { expect, test, describe, afterAll, beforeAll, it } from 'vitest'
import { Tools } from '../../Tools';
import { disposeConnection, newConnection } from '../globalSetup';
import IBMi from '../../IBMi';
import { getJavaHome } from '../../configuration/DebugConfiguration';

describe(`connection tests`, {concurrent: true}, () => {
test('sendCommand', async () => {
const connection = getConnection();
let connection: IBMi
beforeAll(async () => {
connection = await newConnection();
})

afterAll(async () => {
disposeConnection(connection);
});

test('sendCommand', async () => {
const result = await connection.sendCommand({
command: `echo "Hello world"`,
});
Expand All @@ -16,8 +25,6 @@ describe(`connection tests`, {concurrent: true}, () => {
})

test('sendCommand with home directory', async () => {
const connection = getConnection();

const resultA = await connection.sendCommand({
command: `pwd`,
directory: `/QSYS.LIB`
Expand All @@ -44,8 +51,6 @@ describe(`connection tests`, {concurrent: true}, () => {
});

test('sendCommand with environment variables', async () => {
const connection = getConnection();

const result = await connection.sendCommand({
command: `echo "$vara $varB $VARC"`,
env: {
Expand All @@ -60,8 +65,6 @@ describe(`connection tests`, {concurrent: true}, () => {
});

test('getTempRemote', () => {
const connection = getConnection();

const fileA = connection.getTempRemote(`/some/file`);
const fileB = connection.getTempRemote(`/some/badfile`);
const fileC = connection.getTempRemote(`/some/file`);
Expand All @@ -71,8 +74,6 @@ describe(`connection tests`, {concurrent: true}, () => {
})

test('parseMemberPath (simple)', () => {
const connection = getConnection();

const memberA = connection.parserMemberPath(`/thelib/thespf/thembr.mbr`);

expect(memberA?.asp).toBeUndefined();
Expand All @@ -84,8 +85,6 @@ describe(`connection tests`, {concurrent: true}, () => {
})

test('parseMemberPath (ASP)', () => {
const connection = getConnection();

const memberA = connection.parserMemberPath(`/theasp/thelib/thespf/thembr.mbr`);

expect(memberA?.asp).toBe(`THEASP`);
Expand All @@ -97,8 +96,6 @@ describe(`connection tests`, {concurrent: true}, () => {
})

test('parseMemberPath (no root)', () => {
const connection = getConnection();

const memberA = connection.parserMemberPath(`thelib/thespf/thembr.mbr`);

expect(memberA?.asp).toBe(undefined);
Expand All @@ -110,8 +107,6 @@ describe(`connection tests`, {concurrent: true}, () => {
});

test('parseMemberPath (no extension)', () => {
const connection = getConnection();

const memberA = connection.parserMemberPath(`/thelib/thespf/thembr`);

expect(memberA?.asp).toBe(undefined);
Expand All @@ -127,16 +122,12 @@ describe(`connection tests`, {concurrent: true}, () => {
});

test('parseMemberPath (invalid length)', () => {
const connection = getConnection();

expect(
() => { connection.parserMemberPath(`/thespf/thembr.mbr`) }
).toThrow(`Invalid path: /thespf/thembr.mbr. Use format LIB/SPF/NAME.ext`);
});

test('runCommand (ILE)', async () => {
const connection = getConnection();

const result = await connection.runCommand({
command: `DSPJOB OPTION(*DFNA)`,
environment: `ile`
Expand All @@ -147,7 +138,7 @@ describe(`connection tests`, {concurrent: true}, () => {
})

test('runCommand (ILE, with error)', async () => {
const result = await getConnection().runCommand({
const result = await connection.runCommand({
command: `CHKOBJ OBJ(QSYS/NOEXIST) OBJTYPE(*DTAARA)`,
noLibList: true
});
Expand All @@ -156,9 +147,7 @@ describe(`connection tests`, {concurrent: true}, () => {
expect(result?.stderr).toBeTruthy();
});

test('runCommand (ILE, custom library list)', async () => {
const connection = getConnection();
const config = connection.getConfig();
test('runCommand (ILE, custom library list)', async () => { const config = connection.getConfig();

const ogLibl = config!.libraryList.slice(0);

Expand Down Expand Up @@ -190,8 +179,6 @@ describe(`connection tests`, {concurrent: true}, () => {
});

test('runCommand (ILE, library list order from variable)', async () => {
const connection = getConnection();

const result = await connection?.runCommand({
command: `DSPLIBL`,
environment: `ile`,
Expand All @@ -209,9 +196,7 @@ describe(`connection tests`, {concurrent: true}, () => {
expect(qtempIndex < qsysincIndex).toBeTruthy();
});

test('runCommand (ILE, library order from config)', async () => {
const connection = getConnection();
const config = connection.getConfig();
test('runCommand (ILE, library order from config)', async () => { const config = connection.getConfig();

const ogLibl = config!.libraryList.slice(0);

Expand All @@ -233,9 +218,7 @@ describe(`connection tests`, {concurrent: true}, () => {
expect(qtempIndex < qsysincIndex).toBeTruthy();
});

test('withTempDirectory and countFiles', async () => {
const connection = getConnection();
const content = connection.getContent()!;
test('withTempDirectory and countFiles', async () => { const content = connection.getContent()!;
let temp;

await connection.withTempDirectory(async tempDir => {
Expand Down Expand Up @@ -265,8 +248,7 @@ describe(`connection tests`, {concurrent: true}, () => {

test('upperCaseName', () => {
{
const connection = getConnection();
const variantsBackup = connection.variantChars.local;
const variantsBackup = connection.variantChars.local;

try {
//CCSID 297 variants
Expand All @@ -285,5 +267,24 @@ describe(`connection tests`, {concurrent: true}, () => {
connection.variantChars.local = variantsBackup;
}
}
})
});

it('Check Java versions', async () => {
if (connection.remoteFeatures.jdk80) {
const jdk8 = getJavaHome(connection, '8');
expect(jdk8).toBe(connection.remoteFeatures.jdk80);
}

if (connection.remoteFeatures.jdk11) {
const jdk11 = getJavaHome(connection, '11');
expect(jdk11).toBe(connection.remoteFeatures.jdk11);
}

if (connection.remoteFeatures.jdk17) {
const jdk17 = getJavaHome(connection, '17');
expect(jdk17).toBe(connection.remoteFeatures.jdk17);
}

expect(getJavaHome(connection, '666')).toBeUndefined();
});
})
Loading

0 comments on commit 85b5e3b

Please sign in to comment.