Skip to content

Commit eaebb12

Browse files
committed
refactored and migrated all tests
Signed-off-by: instamenta <[email protected]>
1 parent 9d34c3d commit eaebb12

15 files changed

+167
-152
lines changed

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"access": "public"
1212
},
1313
"scripts": {
14-
"test:mocha": "cross-env NODE_OPTIONS=--experimental-vm-modules MOCHA_SUITE_NAME=\"Unit Tests\" mocha --recursive --timeout 10000 --exit --reporter spec --check-leaks --coverage --coverage-report=text --exclude 'test/e2e/*'",
14+
"test:mocha": "cross-env NODE_OPTIONS=--experimental-vm-modules MOCHA_SUITE_NAME=\"Unit Tests\" mocha --recursive --reporter spec --check-leaks --coverage --coverage-report=text --exclude .*/e2e/.*\\",
1515
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules JEST_SUITE_NAME=\"Unit Tests\" jest --runInBand --detectOpenHandles --forceExit --coverage --coverageDirectory='coverage/unit' --testPathIgnorePatterns=\".*/e2e/.*\"",
1616
"test-e2e-all": "NODE_OPTIONS=--experimental-vm-modules JEST_SUITE_NAME='Jest E2E All Tests' JEST_JUNIT_OUTPUT_NAME='junit-e2e.xml' jest --runInBand --detectOpenHandles --forceExit --coverage --coverageDirectory='coverage/e2e' --testPathIgnorePatterns=\".*/unit/.*\"",
1717
"test-e2e-standard": "NODE_OPTIONS=--experimental-vm-modules JEST_SUITE_NAME='Jest E2E Standard Tests' JEST_JUNIT_OUTPUT_NAME='junit-e2e-standard.xml' jest --runInBand --detectOpenHandles --forceExit --coverage --coverageDirectory='coverage/e2e-standard' --testPathIgnorePatterns=\".*/unit/.*\" --testPathIgnorePatterns=\".*/e2e/commands/mirror_node.*\" --testPathIgnorePatterns=\".*/e2e/commands/node.*\" --testPathIgnorePatterns=\".*/e2e/commands/separate_node.*\" --testPathIgnorePatterns=\".*/e2e/commands/relay.*\"",

Diff for: test/e2e/commands/node_update.test.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ describe('Node update', () => {
9898
flags.quiet.constName
9999
])
100100
await nodeCmd.accountManager.close()
101-
}).timeout(30 * MINUTES) //! Might be an overkill
101+
}).timeout(30 * MINUTES)
102102

103103
balanceQueryShouldSucceed(nodeCmd.accountManager, nodeCmd, namespace)
104104

Diff for: test/setup.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*/
1717
'use strict'
18-
import chai from 'chai'
18+
import * as chai from 'chai'
1919
import chaiAsPromised from 'chai-as-promised'
2020

2121
// eslint-disable-next-line no-unused-vars

Diff for: test/test_add.mjs

+5-4
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ import {
2727
import { flags } from '../src/commands/index.mjs'
2828
import { getNodeLogs } from '../src/core/helpers.mjs'
2929
import { NodeCommand } from '../src/commands/node.mjs'
30+
import { MINUTES } from '../src/core/constants.mjs'
3031

3132
export function testNodeAdd (localBuildPath
3233
) {
3334
describe('Node add should success', () => {
3435
const suffix = localBuildPath.substring(0, 5)
35-
const defaultTimeout = 120_000
36+
const defaultTimeout = 2 * MINUTES
3637
const namespace = 'node-add' + suffix
3738
const argv = getDefaultArgv()
3839
argv[flags.nodeIDs.name] = 'node1,node2,node3'
@@ -56,7 +57,7 @@ export function testNodeAdd (localBuildPath
5657
let existingNodeIdsPrivateKeysHash
5758

5859
after(async () => {
59-
this.timeout(600_000)
60+
this.timeout(10 * MINUTES)
6061

6162
await getNodeLogs(k8, namespace)
6263
await nodeCmd.accountManager.close()
@@ -73,7 +74,7 @@ export function testNodeAdd (localBuildPath
7374
it('should succeed with init command', async () => {
7475
const status = await accountCmd.init(argv)
7576
expect(status).to.be.ok
76-
}).timeout(450_000)
77+
}).timeout(8 * MINUTES)
7778

7879
it('should add a new node to the network successfully', async () => {
7980
await nodeCmd.add(argv)
@@ -85,7 +86,7 @@ export function testNodeAdd (localBuildPath
8586
flags.adminKey.constName
8687
])
8788
await nodeCmd.accountManager.close()
88-
}).timeout(800_000)
89+
}).timeout(12 * MINUTES)
8990

9091
balanceQueryShouldSucceed(nodeCmd.accountManager, nodeCmd, namespace)
9192

Diff for: test/test_util.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import {
4747
AccountCreateTransaction, Hbar, HbarUnit,
4848
PrivateKey
4949
} from '@hashgraph/sdk'
50-
import { ROOT_CONTAINER } from '../src/core/constants.mjs'
50+
import { MINUTES, ROOT_CONTAINER, SECONDS } from '../src/core/constants.mjs'
5151
import crypto from 'crypto'
5252
import { AccountCommand } from '../src/commands/account.mjs'
5353
import { SoloError } from '../src/core/errors.mjs'
@@ -212,23 +212,23 @@ export function bootstrapNetwork (testName, argv,
212212

213213
while (await k8.hasNamespace(namespace)) {
214214
testLogger.debug(`Namespace ${namespace} still exist. Waiting...`)
215-
await sleep(1_500)
215+
await sleep(1.5 * SECONDS)
216216
}
217217
}
218218

219219
if (!await chartManager.isChartInstalled(constants.FULLSTACK_SETUP_NAMESPACE, constants.FULLSTACK_CLUSTER_SETUP_CHART)) {
220220
await clusterCmd.setup(argv)
221221
}
222-
}).timeout(120_000)
222+
}).timeout(2 * MINUTES)
223223

224224
it('generate key files', async () => {
225-
await expect(nodeCmd.keys(argv)).should.eventually.be.ok
225+
await expect(nodeCmd.keys(argv)).to.eventually.be.ok
226226
expect(nodeCmd.getUnusedConfigs(NodeCommand.KEYS_CONFIGS_NAME)).to.deep.equal([
227227
flags.cacheDir.constName,
228228
flags.devMode.constName,
229229
flags.quiet.constName
230230
])
231-
}).timeout(120_000)
231+
}).timeout(2 * MINUTES)
232232

233233
it('should succeed with network deploy', async () => {
234234
await networkCmd.deploy(argv)
@@ -245,13 +245,13 @@ export function bootstrapNetwork (testName, argv,
245245
flags.quiet.constName,
246246
flags.settingTxt.constName
247247
])
248-
}).timeout(180_000)
248+
}).timeout(2 * MINUTES)
249249

250250
if (startNodes) {
251251
it('should succeed with node setup command', async () => {
252252
// cache this, because `solo node setup.finalize()` will reset it to false
253253
try {
254-
await expect(nodeCmd.setup(argv)).should.eventually.be.ok
254+
await expect(nodeCmd.setup(argv)).to.eventually.be.ok
255255
expect(nodeCmd.getUnusedConfigs(NodeCommand.SETUP_CONFIGS_NAME)).to.deep.equal([
256256
flags.app.constName,
257257
flags.appConfig.constName,
@@ -261,16 +261,16 @@ export function bootstrapNetwork (testName, argv,
261261
nodeCmd.logger.showUserError(e)
262262
expect(e).be.null
263263
}
264-
}).timeout(240_000)
264+
}).timeout(4 * MINUTES)
265265

266266
it('should succeed with node start command', async () => {
267267
try {
268-
await expect(nodeCmd.start(argv)).should.eventually.be.ok
268+
await expect(nodeCmd.start(argv)).to.eventually.be.ok
269269
} catch (e) {
270270
nodeCmd.logger.showUserError(e)
271271
expect(e).to.be.null
272272
}
273-
}).timeout(1_800_000)
273+
}).timeout(30 * MINUTES)
274274
}
275275
})
276276

@@ -293,8 +293,8 @@ export function balanceQueryShouldSucceed (accountManager, cmd, namespace) {
293293
cmd.logger.showUserError(e)
294294
expect(e).to.be.null
295295
}
296-
await sleep(1000)
297-
}).timeout(120_000)
296+
await sleep(1 * SECONDS)
297+
}).timeout(2 * MINUTES)
298298
}
299299

300300
export function accountCreationShouldSucceed (accountManager, nodeCmd, namespace) {
@@ -325,7 +325,7 @@ export function accountCreationShouldSucceed (accountManager, nodeCmd, namespace
325325
nodeCmd.logger.showUserError(e)
326326
expect(e).to.be.null
327327
}
328-
}).timeout(120_000)
328+
}).timeout(2 * MINUTES)
329329
}
330330

331331
export async function getNodeIdsPrivateKeysHash (networkNodeServicesMap, namespace, k8, destDir) {

Diff for: test/unit/core/dependency_managers/dependency_manager.test.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('DependencyManager', () => {
3232
describe('checkDependency', () => {
3333
it('should fail during invalid dependency check', async () => {
3434
await expect(depManager.checkDependency('INVALID_PROGRAM'))
35-
.should.eventually.be.rejectedWith(new SoloError("Dependency 'INVALID_PROGRAM' is not found"))
35+
.to.eventually.be.rejectedWith(new SoloError("Dependency 'INVALID_PROGRAM' is not found"))
3636
})
3737

3838
it('should succeed during helm dependency check', async () => {

Diff for: test/unit/core/dependency_managers/helm_dependency_manager.test.mjs

+23-15
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,28 @@ describe('HelmDependencyManager', () => {
5050
expect(helmDependencyManager.isInstalled()).to.be.ok
5151
})
5252

53-
it.each(
54-
[{ osPlatform: 'linux', osArch: 'x64' }, { osRelease: 'linux', osArch: 'amd64' }, { osRelease: 'windows', osArch: 'amd64' }],
55-
'should be able to install helm base on os and architecture',
56-
async (input) => {
57-
const helmDependencyManager = new HelmDependencyManager(downloader, zippy, testLogger, tmpDir, input.osPlatform, input.osArch)
58-
if (fs.existsSync(tmpDir)) {
59-
fs.rmSync(tmpDir, { recursive: true })
60-
}
53+
const testCases = [
54+
{ osPlatform: 'linux', osArch: 'x64' },
55+
{ osRelease: 'linux', osArch: 'amd64' },
56+
{ osRelease: 'windows', osArch: 'amd64' }
57+
]
58+
describe('Helm Installation Tests', () => {
59+
testCases.forEach((input) => {
60+
it(`should be able to install helm for osPlatform: ${input.osPlatform || input.osRelease}, osArch: ${input.osArch}`, async () => {
61+
const helmDependencyManager = new HelmDependencyManager(downloader, zippy, testLogger, tmpDir, input.osPlatform, input.osArch)
6162

62-
await helmDependencyManager.uninstall()
63-
expect(helmDependencyManager.isInstalled()).not.to.be.ok
64-
await expect(helmDependencyManager.install(getTestCacheDir())).should.eventually.be.ok
65-
expect(helmDependencyManager.isInstalled()).should.eventually.be.ok
66-
fs.rmSync(tmpDir, { recursive: true })
67-
}
68-
)
63+
if (fs.existsSync(tmpDir)) {
64+
fs.rmSync(tmpDir, { recursive: true })
65+
}
66+
67+
await helmDependencyManager.uninstall()
68+
expect(helmDependencyManager.isInstalled()).not.to.be.ok
69+
70+
await expect(helmDependencyManager.install(getTestCacheDir())).to.eventually.be.ok
71+
expect(helmDependencyManager.isInstalled()).to.eventually.be.ok
72+
73+
fs.rmSync(tmpDir, { recursive: true })
74+
})
75+
})
76+
})
6977
})

Diff for: test/unit/core/k8.test.mjs

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* limitations under the License.
1515
*
1616
*/
17-
import { expect } from 'chai'
1817
import sinon from 'sinon'
1918

2019
import { constants, K8 } from '../../../src/core/index.mjs'

Diff for: test/unit/core/key_manager.test.mjs

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import fs from 'fs'
1818
import os from 'os'
1919
import path from 'path'
2020
import { constants, logging, KeyManager } from '../../../src/core/index.mjs'
21+
import { SECONDS } from '../../../src/core/constants.mjs'
2122

2223
describe('KeyManager', () => {
2324
const logger = logging.NewLogger('debug', true)
@@ -78,5 +79,5 @@ describe('KeyManager', () => {
7879
})).to.eventually.be.ok
7980

8081
fs.rmSync(tmpDir, { recursive: true })
81-
}).timeout(20_000)
82+
}).timeout(20 * SECONDS)
8283
})

Diff for: test/unit/core/logging.test.mjs

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ describe('Logging', () => {
3737
const meta = logger.prepMeta()
3838

3939
logger.error('Error log')
40-
expect(loggerSpy).should.have.been.calledWith('error', 'Error log', meta)
40+
expect(loggerSpy).to.have.been.calledWith('error', 'Error log', meta)
4141

4242
logger.warn('Warn log')
43-
expect(loggerSpy).should.have.been.calledWith('warn', 'Warn log', meta)
43+
expect(loggerSpy).to.have.been.calledWith('warn', 'Warn log', meta)
4444

4545
logger.info('Info log')
46-
expect(loggerSpy).should.have.been.calledWith('info', 'Info log', meta)
46+
expect(loggerSpy).to.have.been.calledWith('info', 'Info log', meta)
4747

4848
logger.debug('Debug log')
49-
expect(loggerSpy).should.have.been.calledWith('debug', 'Debug log', meta)
49+
expect(loggerSpy).to.have.been.calledWith('debug', 'Debug log', meta)
5050
})
5151
})

Diff for: test/unit/core/package_downloader.test.mjs

+6-6
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,21 @@ describe('PackageDownloader', () => {
3737

3838
describe('fetchFile', () => {
3939
it('should fail if source URL is missing', async () => {
40-
await downloader.fetchFile('', os.tmpdir()).should.be.rejected('package URL is required')
40+
await expect(downloader.fetchFile('', os.tmpdir())).to.eventually.be.rejected('package URL is required')
4141
})
4242

4343
it('should fail if destination path is missing', async () => {
44-
await downloader.fetchFile('https://localhost', '').should.be.rejected('destination path is required')
44+
await expect(downloader.fetchFile('https://localhost', '')).to.eventually.be.rejected('destination path is required')
4545
})
4646

4747
it('should fail with a malformed URL', async () => {
48-
await downloader.fetchFile('INVALID_URL', os.tmpdir())
49-
.should.be.rejectedWith(IllegalArgumentError, "package URL 'INVALID_URL' is invalid")
48+
await expect(downloader.fetchFile('INVALID_URL', os.tmpdir()))
49+
.to.eventually.be.rejectedWith(IllegalArgumentError, "package URL 'INVALID_URL' is invalid")
5050
})
5151

5252
it('should fail with an invalid URL', async () => {
53-
await downloader.fetchFile('https://localhost/INVALID_FILE', os.tmpdir())
54-
.should.be.rejectedWith(ResourceNotFoundError, "package URL 'https://localhost/INVALID_FILE' does not exist")
53+
await expect(downloader.fetchFile('https://localhost/INVALID_FILE', os.tmpdir()))
54+
.to.eventually.be.rejectedWith(ResourceNotFoundError, "package URL 'https://localhost/INVALID_FILE' does not exist")
5555
})
5656

5757
it('should succeed with a valid release artifact URL', async () => {

Diff for: test/unit/core/platform_installer.test.mjs

+11-11
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,24 @@ describe('PackageInstaller', () => {
3737

3838
describe('validatePlatformReleaseDir', () => {
3939
it('should fail for missing path', async () => {
40-
await installer.validatePlatformReleaseDir('').should.be.rejectedWith(MissingArgumentError)
40+
await expect(installer.validatePlatformReleaseDir('')).to.eventually.be.rejectedWith(MissingArgumentError)
4141
})
4242

4343
it('should fail for invalid path', async () => {
44-
await installer.validatePlatformReleaseDir('/INVALID').should.be.rejectedWith(IllegalArgumentError)
44+
await expect(installer.validatePlatformReleaseDir('/INVALID')).to.eventually.be.rejectedWith(IllegalArgumentError)
4545
})
4646

4747
it('should fail if directory does not have data/apps directory', async () => {
4848
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'installer-'))
4949
fs.mkdirSync(`${tmpDir}/${core.constants.HEDERA_DATA_LIB_DIR}`, { recursive: true })
50-
await installer.validatePlatformReleaseDir(tmpDir).should.be.rejectedWith(IllegalArgumentError)
50+
await expect(installer.validatePlatformReleaseDir(tmpDir)).to.eventually.be.rejectedWith(IllegalArgumentError)
5151
fs.rmSync(tmpDir, { recursive: true })
5252
})
5353

5454
it('should fail if directory does not have data/libs directory', async () => {
5555
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'installer-'))
5656
fs.mkdirSync(`${tmpDir}/${core.constants.HEDERA_DATA_APPS_DIR}`, { recursive: true })
57-
await installer.validatePlatformReleaseDir(tmpDir).should.be.rejectedWith(IllegalArgumentError)
57+
await expect(installer.validatePlatformReleaseDir(tmpDir)).to.eventually.be.rejectedWith(IllegalArgumentError)
5858
fs.rmSync(tmpDir, { recursive: true })
5959
})
6060

@@ -63,7 +63,7 @@ describe('PackageInstaller', () => {
6363
fs.mkdirSync(`${tmpDir}/${core.constants.HEDERA_DATA_APPS_DIR}`, { recursive: true })
6464
fs.mkdirSync(`${tmpDir}/${core.constants.HEDERA_DATA_LIB_DIR}`, { recursive: true })
6565
fs.writeFileSync(`${tmpDir}/${core.constants.HEDERA_DATA_LIB_DIR}/test.jar`, '')
66-
await installer.validatePlatformReleaseDir().should.be.rejectedWith(MissingArgumentError)
66+
await expect(installer.validatePlatformReleaseDir()).to.eventually.be.rejectedWith(MissingArgumentError)
6767
fs.rmSync(tmpDir, { recursive: true })
6868
})
6969

@@ -72,7 +72,7 @@ describe('PackageInstaller', () => {
7272
fs.mkdirSync(`${tmpDir}/${core.constants.HEDERA_DATA_APPS_DIR}`, { recursive: true })
7373
fs.writeFileSync(`${tmpDir}/${core.constants.HEDERA_DATA_APPS_DIR}/app.jar`, '')
7474
fs.mkdirSync(`${tmpDir}/${core.constants.HEDERA_DATA_LIB_DIR}`, { recursive: true })
75-
await installer.validatePlatformReleaseDir().should.be.rejectedWith(MissingArgumentError)
75+
await expect(installer.validatePlatformReleaseDir()).to.eventually.be.rejectedWith(MissingArgumentError)
7676
fs.rmSync(tmpDir, { recursive: true })
7777
})
7878

@@ -82,27 +82,27 @@ describe('PackageInstaller', () => {
8282
fs.writeFileSync(`${tmpDir}/${core.constants.HEDERA_DATA_APPS_DIR}/app.jar`, '')
8383
fs.mkdirSync(`${tmpDir}/${core.constants.HEDERA_DATA_LIB_DIR}`, { recursive: true })
8484
fs.writeFileSync(`${tmpDir}/${core.constants.HEDERA_DATA_LIB_DIR}/lib-1.jar`, '')
85-
await installer.validatePlatformReleaseDir().should.be.rejectedWith(MissingArgumentError)
85+
await expect(installer.validatePlatformReleaseDir()).to.eventually.be.rejectedWith(MissingArgumentError)
8686
fs.rmSync(tmpDir, { recursive: true })
8787
})
8888
})
8989

9090
describe('extractPlatform', () => {
9191
it('should fail for missing pod name', async () => {
92-
await installer.fetchPlatform('', 'v0.42.5').should.be.rejectedWith(MissingArgumentError)
92+
await expect(installer.fetchPlatform('', 'v0.42.5')).to.eventually.be.rejectedWith(MissingArgumentError)
9393
})
9494
it('should fail for missing tag', async () => {
95-
await installer.fetchPlatform('network-node1-0', '').should.be.rejectedWith(MissingArgumentError)
95+
await expect(installer.fetchPlatform('network-node1-0', '')).to.eventually.be.rejectedWith(MissingArgumentError)
9696
})
9797
})
9898

9999
describe('copyGossipKeys', () => {
100100
it('should fail for missing podName', async () => {
101-
await installer.copyGossipKeys('', os.tmpdir()).should.be.rejectedWith(MissingArgumentError)
101+
await expect(installer.copyGossipKeys('', os.tmpdir())).to.eventually.be.rejectedWith(MissingArgumentError)
102102
})
103103

104104
it('should fail for missing stagingDir path', async () => {
105-
await installer.copyGossipKeys('node1', '').should.be.rejectedWith(MissingArgumentError)
105+
await expect(installer.copyGossipKeys('node1', '')).to.eventually.be.rejectedWith(MissingArgumentError)
106106
})
107107
})
108108
})

0 commit comments

Comments
 (0)