1
1
2
- import { expect , test , describe } from 'vitest'
3
- import { getConnection } from '../state'
2
+ import { expect , test , describe , afterAll , beforeAll , it } from 'vitest'
4
3
import { Tools } from '../../Tools' ;
4
+ import { disposeConnection , newConnection } from '../globalSetup' ;
5
+ import IBMi from '../../IBMi' ;
6
+ import { getJavaHome } from '../../configuration/DebugConfiguration' ;
5
7
6
8
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
+ } ) ;
9
17
18
+ test ( 'sendCommand' , async ( ) => {
10
19
const result = await connection . sendCommand ( {
11
20
command : `echo "Hello world"` ,
12
21
} ) ;
@@ -16,8 +25,6 @@ describe(`connection tests`, {concurrent: true}, () => {
16
25
} )
17
26
18
27
test ( 'sendCommand with home directory' , async ( ) => {
19
- const connection = getConnection ( ) ;
20
-
21
28
const resultA = await connection . sendCommand ( {
22
29
command : `pwd` ,
23
30
directory : `/QSYS.LIB`
@@ -44,8 +51,6 @@ describe(`connection tests`, {concurrent: true}, () => {
44
51
} ) ;
45
52
46
53
test ( 'sendCommand with environment variables' , async ( ) => {
47
- const connection = getConnection ( ) ;
48
-
49
54
const result = await connection . sendCommand ( {
50
55
command : `echo "$vara $varB $VARC"` ,
51
56
env : {
@@ -60,8 +65,6 @@ describe(`connection tests`, {concurrent: true}, () => {
60
65
} ) ;
61
66
62
67
test ( 'getTempRemote' , ( ) => {
63
- const connection = getConnection ( ) ;
64
-
65
68
const fileA = connection . getTempRemote ( `/some/file` ) ;
66
69
const fileB = connection . getTempRemote ( `/some/badfile` ) ;
67
70
const fileC = connection . getTempRemote ( `/some/file` ) ;
@@ -71,8 +74,6 @@ describe(`connection tests`, {concurrent: true}, () => {
71
74
} )
72
75
73
76
test ( 'parseMemberPath (simple)' , ( ) => {
74
- const connection = getConnection ( ) ;
75
-
76
77
const memberA = connection . parserMemberPath ( `/thelib/thespf/thembr.mbr` ) ;
77
78
78
79
expect ( memberA ?. asp ) . toBeUndefined ( ) ;
@@ -84,8 +85,6 @@ describe(`connection tests`, {concurrent: true}, () => {
84
85
} )
85
86
86
87
test ( 'parseMemberPath (ASP)' , ( ) => {
87
- const connection = getConnection ( ) ;
88
-
89
88
const memberA = connection . parserMemberPath ( `/theasp/thelib/thespf/thembr.mbr` ) ;
90
89
91
90
expect ( memberA ?. asp ) . toBe ( `THEASP` ) ;
@@ -97,8 +96,6 @@ describe(`connection tests`, {concurrent: true}, () => {
97
96
} )
98
97
99
98
test ( 'parseMemberPath (no root)' , ( ) => {
100
- const connection = getConnection ( ) ;
101
-
102
99
const memberA = connection . parserMemberPath ( `thelib/thespf/thembr.mbr` ) ;
103
100
104
101
expect ( memberA ?. asp ) . toBe ( undefined ) ;
@@ -110,8 +107,6 @@ describe(`connection tests`, {concurrent: true}, () => {
110
107
} ) ;
111
108
112
109
test ( 'parseMemberPath (no extension)' , ( ) => {
113
- const connection = getConnection ( ) ;
114
-
115
110
const memberA = connection . parserMemberPath ( `/thelib/thespf/thembr` ) ;
116
111
117
112
expect ( memberA ?. asp ) . toBe ( undefined ) ;
@@ -127,16 +122,12 @@ describe(`connection tests`, {concurrent: true}, () => {
127
122
} ) ;
128
123
129
124
test ( 'parseMemberPath (invalid length)' , ( ) => {
130
- const connection = getConnection ( ) ;
131
-
132
125
expect (
133
126
( ) => { connection . parserMemberPath ( `/thespf/thembr.mbr` ) }
134
127
) . toThrow ( `Invalid path: /thespf/thembr.mbr. Use format LIB/SPF/NAME.ext` ) ;
135
128
} ) ;
136
129
137
130
test ( 'runCommand (ILE)' , async ( ) => {
138
- const connection = getConnection ( ) ;
139
-
140
131
const result = await connection . runCommand ( {
141
132
command : `DSPJOB OPTION(*DFNA)` ,
142
133
environment : `ile`
@@ -147,7 +138,7 @@ describe(`connection tests`, {concurrent: true}, () => {
147
138
} )
148
139
149
140
test ( 'runCommand (ILE, with error)' , async ( ) => {
150
- const result = await getConnection ( ) . runCommand ( {
141
+ const result = await connection . runCommand ( {
151
142
command : `CHKOBJ OBJ(QSYS/NOEXIST) OBJTYPE(*DTAARA)` ,
152
143
noLibList : true
153
144
} ) ;
@@ -156,9 +147,7 @@ describe(`connection tests`, {concurrent: true}, () => {
156
147
expect ( result ?. stderr ) . toBeTruthy ( ) ;
157
148
} ) ;
158
149
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 ( ) ;
162
151
163
152
const ogLibl = config ! . libraryList . slice ( 0 ) ;
164
153
@@ -190,8 +179,6 @@ describe(`connection tests`, {concurrent: true}, () => {
190
179
} ) ;
191
180
192
181
test ( 'runCommand (ILE, library list order from variable)' , async ( ) => {
193
- const connection = getConnection ( ) ;
194
-
195
182
const result = await connection ?. runCommand ( {
196
183
command : `DSPLIBL` ,
197
184
environment : `ile` ,
@@ -209,9 +196,7 @@ describe(`connection tests`, {concurrent: true}, () => {
209
196
expect ( qtempIndex < qsysincIndex ) . toBeTruthy ( ) ;
210
197
} ) ;
211
198
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 ( ) ;
215
200
216
201
const ogLibl = config ! . libraryList . slice ( 0 ) ;
217
202
@@ -233,9 +218,7 @@ describe(`connection tests`, {concurrent: true}, () => {
233
218
expect ( qtempIndex < qsysincIndex ) . toBeTruthy ( ) ;
234
219
} ) ;
235
220
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 ( ) ! ;
239
222
let temp ;
240
223
241
224
await connection . withTempDirectory ( async tempDir => {
@@ -265,8 +248,7 @@ describe(`connection tests`, {concurrent: true}, () => {
265
248
266
249
test ( 'upperCaseName' , ( ) => {
267
250
{
268
- const connection = getConnection ( ) ;
269
- const variantsBackup = connection . variantChars . local ;
251
+ const variantsBackup = connection . variantChars . local ;
270
252
271
253
try {
272
254
//CCSID 297 variants
@@ -285,5 +267,24 @@ describe(`connection tests`, {concurrent: true}, () => {
285
267
connection . variantChars . local = variantsBackup ;
286
268
}
287
269
}
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
+ } ) ;
289
290
} )
0 commit comments