Skip to content

Commit 85b5e3b

Browse files
committed
No more global setup for the connection since not all suites require a connection
Signed-off-by: worksofliam <[email protected]>
1 parent 1c2bbc6 commit 85b5e3b

File tree

10 files changed

+122
-178
lines changed

10 files changed

+122
-178
lines changed

src/api/IBMi.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,12 +1097,12 @@ export default class IBMi {
10971097
*/
10981098
getTempRemote(key: string) {
10991099
if (this.tempRemoteFiles[key] !== undefined) {
1100-
console.log(`Using existing temp: ${this.tempRemoteFiles[key]}`);
1100+
// console.log(`Using existing temp: ${this.tempRemoteFiles[key]}`);
11011101
return this.tempRemoteFiles[key];
11021102
} else
11031103
if (this.config) {
11041104
let value = path.posix.join(this.config.tempDir, `vscodetemp-${Tools.makeid()}`);
1105-
console.log(`Using new temp: ${value}`);
1105+
// console.log(`Using new temp: ${value}`);
11061106
this.tempRemoteFiles[key] = value;
11071107
return value;
11081108
}

src/api/tests/globalSetup.ts

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import assert from "assert";
22
import IBMi from "../IBMi";
33
import { ENV_CREDS } from "./env";
4-
import { getConnection, setConnection } from "./state";
54
import { afterAll, beforeAll, expect } from "vitest";
65
import { CodeForIStorage } from "../configuration/storage/CodeForIStorage";
7-
import { VirtualConfig } from "../configuration/config/VirtualConfig";
8-
import { VirtualStorage } from "../configuration/storage/BaseStorage";
96
import { CustomQSh } from "../components/cqsh";
107
import path from "path";
118
import { CopyToImport } from "../components/copyToImport";
@@ -71,28 +68,8 @@ export async function newConnection() {
7168
return conn;
7269
}
7370

74-
beforeAll(async () => {
75-
const virtualStorage = testStorage;
76-
77-
IBMi.GlobalStorage = new CodeForIStorage(virtualStorage);
78-
IBMi.connectionManager.configMethod = testConfig;
79-
80-
await testStorage.load();
81-
await testConfig.load();
82-
83-
const conn = await newConnection();
84-
85-
setConnection(conn);
86-
}, 10000000);
87-
88-
afterAll(async () => {
89-
const conn = getConnection();
90-
91-
if (conn) {
92-
await conn.dispose();
93-
await testStorage.save();
94-
await testConfig.save();
95-
} else {
96-
assert.fail(`Connection was not set`);
97-
}
98-
})
71+
export function disposeConnection(conn: IBMi) {
72+
conn.dispose();
73+
testStorage.save();
74+
testConfig.save();
75+
}

src/api/tests/state.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/api/tests/suites/components.test.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
import { describe, it, expect } from 'vitest';
1+
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
22
import { GetMemberInfo } from '../../components/getMemberInfo';
33
import { GetNewLibl } from '../../components/getNewLibl';
44
import { Tools } from '../../Tools';
5-
import { getConnection } from '../state';
5+
import IBMi from '../../IBMi';
6+
import { disposeConnection, newConnection } from '../globalSetup';
67

78
describe('Component Tests', () => {
9+
let connection: IBMi
10+
beforeAll(async () => {
11+
connection = await newConnection();
12+
})
813

14+
afterAll(async () => {
15+
disposeConnection(connection);
16+
});
917

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

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

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

2632
expect(component).toBeTruthy();

src/api/tests/suites/connection.test.ts

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11

2-
import { expect, test, describe } from 'vitest'
3-
import { getConnection } from '../state'
2+
import { expect, test, describe, afterAll, beforeAll, it } from 'vitest'
43
import { Tools } from '../../Tools';
4+
import { disposeConnection, newConnection } from '../globalSetup';
5+
import IBMi from '../../IBMi';
6+
import { getJavaHome } from '../../configuration/DebugConfiguration';
57

68
describe(`connection tests`, {concurrent: true}, () => {
7-
test('sendCommand', async () => {
8-
const connection = getConnection();
9+
let connection: IBMi
10+
beforeAll(async () => {
11+
connection = await newConnection();
12+
})
13+
14+
afterAll(async () => {
15+
disposeConnection(connection);
16+
});
917

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

1827
test('sendCommand with home directory', async () => {
19-
const connection = getConnection();
20-
2128
const resultA = await connection.sendCommand({
2229
command: `pwd`,
2330
directory: `/QSYS.LIB`
@@ -44,8 +51,6 @@ describe(`connection tests`, {concurrent: true}, () => {
4451
});
4552

4653
test('sendCommand with environment variables', async () => {
47-
const connection = getConnection();
48-
4954
const result = await connection.sendCommand({
5055
command: `echo "$vara $varB $VARC"`,
5156
env: {
@@ -60,8 +65,6 @@ describe(`connection tests`, {concurrent: true}, () => {
6065
});
6166

6267
test('getTempRemote', () => {
63-
const connection = getConnection();
64-
6568
const fileA = connection.getTempRemote(`/some/file`);
6669
const fileB = connection.getTempRemote(`/some/badfile`);
6770
const fileC = connection.getTempRemote(`/some/file`);
@@ -71,8 +74,6 @@ describe(`connection tests`, {concurrent: true}, () => {
7174
})
7275

7376
test('parseMemberPath (simple)', () => {
74-
const connection = getConnection();
75-
7677
const memberA = connection.parserMemberPath(`/thelib/thespf/thembr.mbr`);
7778

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

8687
test('parseMemberPath (ASP)', () => {
87-
const connection = getConnection();
88-
8988
const memberA = connection.parserMemberPath(`/theasp/thelib/thespf/thembr.mbr`);
9089

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

9998
test('parseMemberPath (no root)', () => {
100-
const connection = getConnection();
101-
10299
const memberA = connection.parserMemberPath(`thelib/thespf/thembr.mbr`);
103100

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

112109
test('parseMemberPath (no extension)', () => {
113-
const connection = getConnection();
114-
115110
const memberA = connection.parserMemberPath(`/thelib/thespf/thembr`);
116111

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

129124
test('parseMemberPath (invalid length)', () => {
130-
const connection = getConnection();
131-
132125
expect(
133126
() => { connection.parserMemberPath(`/thespf/thembr.mbr`) }
134127
).toThrow(`Invalid path: /thespf/thembr.mbr. Use format LIB/SPF/NAME.ext`);
135128
});
136129

137130
test('runCommand (ILE)', async () => {
138-
const connection = getConnection();
139-
140131
const result = await connection.runCommand({
141132
command: `DSPJOB OPTION(*DFNA)`,
142133
environment: `ile`
@@ -147,7 +138,7 @@ describe(`connection tests`, {concurrent: true}, () => {
147138
})
148139

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

159-
test('runCommand (ILE, custom library list)', async () => {
160-
const connection = getConnection();
161-
const config = connection.getConfig();
150+
test('runCommand (ILE, custom library list)', async () => { const config = connection.getConfig();
162151

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

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

192181
test('runCommand (ILE, library list order from variable)', async () => {
193-
const connection = getConnection();
194-
195182
const result = await connection?.runCommand({
196183
command: `DSPLIBL`,
197184
environment: `ile`,
@@ -209,9 +196,7 @@ describe(`connection tests`, {concurrent: true}, () => {
209196
expect(qtempIndex < qsysincIndex).toBeTruthy();
210197
});
211198

212-
test('runCommand (ILE, library order from config)', async () => {
213-
const connection = getConnection();
214-
const config = connection.getConfig();
199+
test('runCommand (ILE, library order from config)', async () => { const config = connection.getConfig();
215200

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

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

236-
test('withTempDirectory and countFiles', async () => {
237-
const connection = getConnection();
238-
const content = connection.getContent()!;
221+
test('withTempDirectory and countFiles', async () => { const content = connection.getContent()!;
239222
let temp;
240223

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

266249
test('upperCaseName', () => {
267250
{
268-
const connection = getConnection();
269-
const variantsBackup = connection.variantChars.local;
251+
const variantsBackup = connection.variantChars.local;
270252

271253
try {
272254
//CCSID 297 variants
@@ -285,5 +267,24 @@ describe(`connection tests`, {concurrent: true}, () => {
285267
connection.variantChars.local = variantsBackup;
286268
}
287269
}
288-
})
270+
});
271+
272+
it('Check Java versions', async () => {
273+
if (connection.remoteFeatures.jdk80) {
274+
const jdk8 = getJavaHome(connection, '8');
275+
expect(jdk8).toBe(connection.remoteFeatures.jdk80);
276+
}
277+
278+
if (connection.remoteFeatures.jdk11) {
279+
const jdk11 = getJavaHome(connection, '11');
280+
expect(jdk11).toBe(connection.remoteFeatures.jdk11);
281+
}
282+
283+
if (connection.remoteFeatures.jdk17) {
284+
const jdk17 = getJavaHome(connection, '17');
285+
expect(jdk17).toBe(connection.remoteFeatures.jdk17);
286+
}
287+
288+
expect(getJavaHome(connection, '666')).toBeUndefined();
289+
});
289290
})

0 commit comments

Comments
 (0)