Skip to content

Commit

Permalink
refactored and migrated all tests
Browse files Browse the repository at this point in the history
Signed-off-by: instamenta <instamenta@abv.bg>
  • Loading branch information
instamenta committed Oct 4, 2024
1 parent 9d34c3d commit eaebb12
Show file tree
Hide file tree
Showing 15 changed files with 167 additions and 152 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"access": "public"
},
"scripts": {
"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/*'",
"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/.*\\",
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules JEST_SUITE_NAME=\"Unit Tests\" jest --runInBand --detectOpenHandles --forceExit --coverage --coverageDirectory='coverage/unit' --testPathIgnorePatterns=\".*/e2e/.*\"",
"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/.*\"",
"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.*\"",
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/commands/node_update.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe('Node update', () => {
flags.quiet.constName
])
await nodeCmd.accountManager.close()
}).timeout(30 * MINUTES) //! Might be an overkill
}).timeout(30 * MINUTES)

balanceQueryShouldSucceed(nodeCmd.accountManager, nodeCmd, namespace)

Expand Down
2 changes: 1 addition & 1 deletion test/setup.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
*/
'use strict'
import chai from 'chai'
import * as chai from 'chai'
import chaiAsPromised from 'chai-as-promised'

// eslint-disable-next-line no-unused-vars
Expand Down
9 changes: 5 additions & 4 deletions test/test_add.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ import {
import { flags } from '../src/commands/index.mjs'
import { getNodeLogs } from '../src/core/helpers.mjs'
import { NodeCommand } from '../src/commands/node.mjs'
import { MINUTES } from '../src/core/constants.mjs'

export function testNodeAdd (localBuildPath
) {
describe('Node add should success', () => {
const suffix = localBuildPath.substring(0, 5)
const defaultTimeout = 120_000
const defaultTimeout = 2 * MINUTES
const namespace = 'node-add' + suffix
const argv = getDefaultArgv()
argv[flags.nodeIDs.name] = 'node1,node2,node3'
Expand All @@ -56,7 +57,7 @@ export function testNodeAdd (localBuildPath
let existingNodeIdsPrivateKeysHash

after(async () => {
this.timeout(600_000)
this.timeout(10 * MINUTES)

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

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

balanceQueryShouldSucceed(nodeCmd.accountManager, nodeCmd, namespace)

Expand Down
26 changes: 13 additions & 13 deletions test/test_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import {
AccountCreateTransaction, Hbar, HbarUnit,
PrivateKey
} from '@hashgraph/sdk'
import { ROOT_CONTAINER } from '../src/core/constants.mjs'
import { MINUTES, ROOT_CONTAINER, SECONDS } from '../src/core/constants.mjs'
import crypto from 'crypto'
import { AccountCommand } from '../src/commands/account.mjs'
import { SoloError } from '../src/core/errors.mjs'
Expand Down Expand Up @@ -212,23 +212,23 @@ export function bootstrapNetwork (testName, argv,

while (await k8.hasNamespace(namespace)) {
testLogger.debug(`Namespace ${namespace} still exist. Waiting...`)
await sleep(1_500)
await sleep(1.5 * SECONDS)
}
}

if (!await chartManager.isChartInstalled(constants.FULLSTACK_SETUP_NAMESPACE, constants.FULLSTACK_CLUSTER_SETUP_CHART)) {
await clusterCmd.setup(argv)
}
}).timeout(120_000)
}).timeout(2 * MINUTES)

it('generate key files', async () => {
await expect(nodeCmd.keys(argv)).should.eventually.be.ok
await expect(nodeCmd.keys(argv)).to.eventually.be.ok
expect(nodeCmd.getUnusedConfigs(NodeCommand.KEYS_CONFIGS_NAME)).to.deep.equal([
flags.cacheDir.constName,
flags.devMode.constName,
flags.quiet.constName
])
}).timeout(120_000)
}).timeout(2 * MINUTES)

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

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

it('should succeed with node start command', async () => {
try {
await expect(nodeCmd.start(argv)).should.eventually.be.ok
await expect(nodeCmd.start(argv)).to.eventually.be.ok
} catch (e) {
nodeCmd.logger.showUserError(e)
expect(e).to.be.null
}
}).timeout(1_800_000)
}).timeout(30 * MINUTES)
}
})

Expand All @@ -293,8 +293,8 @@ export function balanceQueryShouldSucceed (accountManager, cmd, namespace) {
cmd.logger.showUserError(e)
expect(e).to.be.null
}
await sleep(1000)
}).timeout(120_000)
await sleep(1 * SECONDS)
}).timeout(2 * MINUTES)
}

export function accountCreationShouldSucceed (accountManager, nodeCmd, namespace) {
Expand Down Expand Up @@ -325,7 +325,7 @@ export function accountCreationShouldSucceed (accountManager, nodeCmd, namespace
nodeCmd.logger.showUserError(e)
expect(e).to.be.null
}
}).timeout(120_000)
}).timeout(2 * MINUTES)
}

export async function getNodeIdsPrivateKeysHash (networkNodeServicesMap, namespace, k8, destDir) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('DependencyManager', () => {
describe('checkDependency', () => {
it('should fail during invalid dependency check', async () => {
await expect(depManager.checkDependency('INVALID_PROGRAM'))
.should.eventually.be.rejectedWith(new SoloError("Dependency 'INVALID_PROGRAM' is not found"))
.to.eventually.be.rejectedWith(new SoloError("Dependency 'INVALID_PROGRAM' is not found"))
})

it('should succeed during helm dependency check', async () => {
Expand Down
38 changes: 23 additions & 15 deletions test/unit/core/dependency_managers/helm_dependency_manager.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,28 @@ describe('HelmDependencyManager', () => {
expect(helmDependencyManager.isInstalled()).to.be.ok
})

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

await helmDependencyManager.uninstall()
expect(helmDependencyManager.isInstalled()).not.to.be.ok
await expect(helmDependencyManager.install(getTestCacheDir())).should.eventually.be.ok
expect(helmDependencyManager.isInstalled()).should.eventually.be.ok
fs.rmSync(tmpDir, { recursive: true })
}
)
if (fs.existsSync(tmpDir)) {
fs.rmSync(tmpDir, { recursive: true })
}

await helmDependencyManager.uninstall()
expect(helmDependencyManager.isInstalled()).not.to.be.ok

await expect(helmDependencyManager.install(getTestCacheDir())).to.eventually.be.ok
expect(helmDependencyManager.isInstalled()).to.eventually.be.ok

fs.rmSync(tmpDir, { recursive: true })
})
})
})
})
1 change: 0 additions & 1 deletion test/unit/core/k8.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*
*/
import { expect } from 'chai'
import sinon from 'sinon'

import { constants, K8 } from '../../../src/core/index.mjs'
Expand Down
3 changes: 2 additions & 1 deletion test/unit/core/key_manager.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import fs from 'fs'
import os from 'os'
import path from 'path'
import { constants, logging, KeyManager } from '../../../src/core/index.mjs'
import { SECONDS } from '../../../src/core/constants.mjs'

describe('KeyManager', () => {
const logger = logging.NewLogger('debug', true)
Expand Down Expand Up @@ -78,5 +79,5 @@ describe('KeyManager', () => {
})).to.eventually.be.ok

fs.rmSync(tmpDir, { recursive: true })
}).timeout(20_000)
}).timeout(20 * SECONDS)
})
8 changes: 4 additions & 4 deletions test/unit/core/logging.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ describe('Logging', () => {
const meta = logger.prepMeta()

logger.error('Error log')
expect(loggerSpy).should.have.been.calledWith('error', 'Error log', meta)
expect(loggerSpy).to.have.been.calledWith('error', 'Error log', meta)

logger.warn('Warn log')
expect(loggerSpy).should.have.been.calledWith('warn', 'Warn log', meta)
expect(loggerSpy).to.have.been.calledWith('warn', 'Warn log', meta)

logger.info('Info log')
expect(loggerSpy).should.have.been.calledWith('info', 'Info log', meta)
expect(loggerSpy).to.have.been.calledWith('info', 'Info log', meta)

logger.debug('Debug log')
expect(loggerSpy).should.have.been.calledWith('debug', 'Debug log', meta)
expect(loggerSpy).to.have.been.calledWith('debug', 'Debug log', meta)
})
})
12 changes: 6 additions & 6 deletions test/unit/core/package_downloader.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,21 @@ describe('PackageDownloader', () => {

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

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

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

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

it('should succeed with a valid release artifact URL', async () => {
Expand Down
22 changes: 11 additions & 11 deletions test/unit/core/platform_installer.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,24 @@ describe('PackageInstaller', () => {

describe('validatePlatformReleaseDir', () => {
it('should fail for missing path', async () => {
await installer.validatePlatformReleaseDir('').should.be.rejectedWith(MissingArgumentError)
await expect(installer.validatePlatformReleaseDir('')).to.eventually.be.rejectedWith(MissingArgumentError)
})

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

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

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

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

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

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

describe('extractPlatform', () => {
it('should fail for missing pod name', async () => {
await installer.fetchPlatform('', 'v0.42.5').should.be.rejectedWith(MissingArgumentError)
await expect(installer.fetchPlatform('', 'v0.42.5')).to.eventually.be.rejectedWith(MissingArgumentError)
})
it('should fail for missing tag', async () => {
await installer.fetchPlatform('network-node1-0', '').should.be.rejectedWith(MissingArgumentError)
await expect(installer.fetchPlatform('network-node1-0', '')).to.eventually.be.rejectedWith(MissingArgumentError)
})
})

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

it('should fail for missing stagingDir path', async () => {
await installer.copyGossipKeys('node1', '').should.be.rejectedWith(MissingArgumentError)
await expect(installer.copyGossipKeys('node1', '')).to.eventually.be.rejectedWith(MissingArgumentError)
})
})
})
Loading

0 comments on commit eaebb12

Please sign in to comment.