Skip to content

Commit c7ce8eb

Browse files
committed
fix test cases
Signed-off-by: Jeromy Cannon <[email protected]>
1 parent 9c305ca commit c7ce8eb

File tree

6 files changed

+68
-42
lines changed

6 files changed

+68
-42
lines changed

src/commands/init.mjs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ import { Listr } from 'listr2'
1818
import path from 'path'
1919
import { BaseCommand } from './base.mjs'
2020
import * as core from '../core/index.mjs'
21-
import { constants } from '../core/index.mjs'
21+
import { constants, Templates } from '../core/index.mjs'
2222
import * as fs from 'fs'
2323
import { FullstackTestingError, IllegalArgumentError } from '../core/errors.mjs'
2424
import * as flags from './flags.mjs'
2525
import chalk from 'chalk'
26+
import * as version from '../../version.mjs'
2627

2728
/**
2829
* Defines the core functionalities of 'init' command
@@ -64,6 +65,13 @@ export class InitCommand extends BaseCommand {
6465
let cacheDir = this.configManager.getFlag(flags.cacheDir)
6566
if (!cacheDir) {
6667
cacheDir = constants.SOLO_CACHE_DIR
68+
this.configManager.setFlag(flags.cacheDir, cacheDir)
69+
}
70+
71+
let releaseTag = this.configManager.getFlag(flags.releaseTag)
72+
if (!releaseTag) {
73+
releaseTag = version.HEDERA_PLATFORM_VERSION
74+
this.configManager.setFlag(flags.releaseTag, releaseTag)
6775
}
6876

6977
const tasks = new Listr([
@@ -101,12 +109,17 @@ export class InitCommand extends BaseCommand {
101109
{
102110
title: `Copy templates in '${cacheDir}'`,
103111
task: (ctx, _) => {
112+
const stagingDir = Templates.renderStagingDir(
113+
self.configManager.getFlag(flags.cacheDir),
114+
self.configManager.getFlag(flags.releaseTag)
115+
)
116+
104117
const resources = ['templates', 'profiles']
105118
for (const dirName of resources) {
106119
const srcDir = path.resolve(path.join(constants.RESOURCES_DIR, dirName))
107120
if (!fs.existsSync(srcDir)) continue
108121

109-
const destDir = path.resolve(path.join(cacheDir, dirName))
122+
const destDir = path.resolve(path.join(stagingDir, dirName))
110123
if (!fs.existsSync(destDir)) {
111124
fs.mkdirSync(destDir, { recursive: true })
112125
}

src/commands/node.mjs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,10 @@ export class NodeCommand extends BaseCommand {
431431
config.releasePrefix = Templates.prepareReleasePrefix(config.releaseTag)
432432
config.buildZipFile = `${config.cacheDir}/${config.releasePrefix}/build-${config.releaseTag}.zip`
433433
config.keysDir = path.join(validatePath(config.cacheDir), 'keys')
434-
config.stagingDir = Templates.renderStagingDir(configManager, flags)
434+
config.stagingDir = Templates.renderStagingDir(
435+
configManager.getFlag(flags.cacheDir),
436+
configManager.getFlag(flags.releaseTag)
437+
)
435438
config.stagingKeysDir = path.join(validatePath(config.stagingDir), 'keys')
436439

437440
if (!await k8.hasNamespace(config.namespace)) {
@@ -768,7 +771,10 @@ export class NodeCommand extends BaseCommand {
768771
nodeIds: helpers.parseNodeIds(self.configManager.getFlag(flags.nodeIDs))
769772
}
770773

771-
ctx.config.stagingDir = Templates.renderStagingDir(self.configManager, flags)
774+
ctx.config.stagingDir = Templates.renderStagingDir(
775+
self.configManager.getFlag(flags.cacheDir),
776+
self.configManager.getFlag(flags.releaseTag)
777+
)
772778

773779
if (!await self.k8.hasNamespace(ctx.config.namespace)) {
774780
throw new FullstackTestingError(`namespace ${ctx.config.namespace} does not exist`)
@@ -1402,8 +1408,8 @@ export class NodeCommand extends BaseCommand {
14021408
task: async (ctx, task) => {
14031409
const values = { hedera: { nodes: [] } }
14041410
let maxAccountNumber = 0
1405-
/** @type {Map<string,NodeInfo>} **/
1406-
const nodeMap = new Map()
1411+
1412+
const nodeAccountMap = /** @type {Map<string,string>} **/ new Map()
14071413

14081414
for (/** @type {NetworkNodeServices} **/ const networkNodeServices of ctx.config.serviceMap.values()) {
14091415
values.hedera.nodes.push({
@@ -1413,10 +1419,7 @@ export class NodeCommand extends BaseCommand {
14131419
maxAccountNumber = maxAccountNumber > AccountId.fromString(networkNodeServices.accountId).num
14141420
? maxAccountNumber
14151421
: AccountId.fromString(networkNodeServices.accountId).num
1416-
nodeMap.set(networkNodeServices.nodeName, {
1417-
nodeName: networkNodeServices.nodeName,
1418-
accountId: networkNodeServices.accountId
1419-
})
1422+
nodeAccountMap.set(networkNodeServices.nodeName, networkNodeServices.accountId)
14201423
}
14211424

14221425
for (const nodeId of ctx.config.nodeIds) {
@@ -1426,10 +1429,7 @@ export class NodeCommand extends BaseCommand {
14261429
accountId: accountId.toString(),
14271430
name: nodeId
14281431
})
1429-
nodeMap.set(nodeId, {
1430-
nodeName: nodeId,
1431-
accountId: accountId.toString()
1432-
})
1432+
nodeAccountMap.set(nodeId, accountId.toString())
14331433
}
14341434

14351435
let valuesArg = ''
@@ -1440,7 +1440,7 @@ export class NodeCommand extends BaseCommand {
14401440
index++
14411441
}
14421442

1443-
const valuesFilePath = await this.profileManager.prepareValuesForNodeAdd(ctx.config.profileName, nodeMap)
1443+
const valuesFilePath = await this.profileManager.prepareValuesForNodeAdd(ctx.config.profileName, nodeAccountMap)
14441444
valuesArg += this.prepareValuesFiles(valuesFilePath)
14451445

14461446
await self.chartManager.upgrade(

src/core/profile_manager.mjs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,10 @@ export class ProfileManager {
159159
this._setChartItems(`hedera.nodes.${nodeIndex}`, profile.consensus, yamlRoot)
160160
}
161161

162-
const stagingDir = Templates.renderStagingDir(this.configManager, flags)
162+
const stagingDir = Templates.renderStagingDir(
163+
this.configManager.getFlag(flags.cacheDir),
164+
this.configManager.getFlag(flags.releaseTag)
165+
)
163166

164167
const configTxtPath = this.prepareConfigTxt(
165168
this.configManager.getFlag(flags.namespace),
@@ -173,7 +176,7 @@ export class ProfileManager {
173176
this._setFileContentsAsValue('hedera.configMaps.log4j2Xml', `${stagingDir}/templates/log4j2.xml`, yamlRoot)
174177
this._setFileContentsAsValue('hedera.configMaps.settingsTxt', `${stagingDir}/templates/settings.txt`, yamlRoot)
175178
this._setFileContentsAsValue('hedera.configMaps.applicationProperties', `${stagingDir}/templates/application.properties`, yamlRoot)
176-
this._setFileContentsAsValue('hedera.configMaps.apiPermissionsProperties', `${stagingDir}/templates/api-permissions.properties`, yamlRoot)
179+
this._setFileContentsAsValue('hedera.configMaps.apiPermissionsProperties', `${stagingDir}/templates/api-permission.properties`, yamlRoot)
177180
this._setFileContentsAsValue('hedera.configMaps.bootstrapProperties', `${stagingDir}/templates/bootstrap.properties`, yamlRoot)
178181
if (this.configManager.getFlag(flags.applicationEnv)) {
179182
this._setFileContentsAsValue('hedera.configMaps.applicationEnv', this.configManager.getFlag(flags.applicationEnv), yamlRoot)
@@ -272,7 +275,10 @@ export class ProfileManager {
272275
const configTxtPath = this.prepareConfigTxt(
273276
this.configManager.getFlag(flags.namespace),
274277
nodeMap,
275-
Templates.renderStagingDir(this.configManager, flags),
278+
Templates.renderStagingDir(
279+
this.configManager.getFlag(flags.cacheDir),
280+
this.configManager.getFlag(flags.releaseTag)
281+
),
276282
this.configManager.getFlag(flags.releaseTag),
277283
this.configManager.getFlag(flags.app),
278284
this.configManager.getFlag(flags.chainId))

src/core/templates.mjs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,11 @@ export class Templates {
124124
return new x509.Name(`CN=${nodeId},ST=${state},L=${locality},O=${org},OU=${orgUnit},C=${country}`)
125125
}
126126

127-
static renderStagingDir (configManager, flags) {
128-
if (!configManager) throw new MissingArgumentError('configManager is required')
129-
const cacheDir = configManager.getFlag(flags.cacheDir)
127+
static renderStagingDir (cacheDir, releaseTag) {
130128
if (!cacheDir) {
131129
throw new IllegalArgumentError('cacheDir cannot be empty')
132130
}
133131

134-
const releaseTag = configManager.getFlag(flags.releaseTag)
135132
if (!releaseTag) {
136133
throw new IllegalArgumentError('releaseTag cannot be empty')
137134
}

test/unit/core/platform_installer.test.mjs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -103,24 +103,6 @@ describe('PackageInstaller', () => {
103103
})
104104
})
105105

106-
describe('prepareConfigTxt', () => {
107-
it('should fail for missing nodeIDs', async () => {
108-
await expect(installer.prepareConfigTxt([], './test', '0.42.0')).rejects.toThrow(MissingArgumentError)
109-
})
110-
111-
it('should fail for missing destPath', async () => {
112-
await expect(installer.prepareConfigTxt(['node0'], '', '0.42.0')).rejects.toThrow(MissingArgumentError)
113-
})
114-
115-
it('should fail for missing release tag', async () => {
116-
await expect(installer.prepareConfigTxt(['node0'], `${os.tmpdir()}/config.txt`, '')).rejects.toThrow(MissingArgumentError)
117-
})
118-
119-
it('should fail for invalid destPath', async () => {
120-
await expect(installer.prepareConfigTxt(['node0'], '/INVALID/config.txt', '0.42.0')).rejects.toThrow(IllegalArgumentError)
121-
})
122-
})
123-
124106
describe('copyGossipKeys', () => {
125107
it('should fail for missing podName', async () => {
126108
await expect(installer.copyGossipKeys('', os.tmpdir())).rejects.toThrow(MissingArgumentError)

test/unit/core/profile_manager.test.mjs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@ import fs from 'fs'
1919
import * as yaml from 'js-yaml'
2020
import path from 'path'
2121
import { flags } from '../../../src/commands/index.mjs'
22-
import { ConfigManager, ProfileManager } from '../../../src/core/index.mjs'
23-
import { getTmpDir, testLogger } from '../../test_util.js'
22+
import {
23+
ConfigManager,
24+
constants,
25+
ProfileManager, Templates
26+
} from '../../../src/core/index.mjs'
27+
import { getTestCacheDir, getTmpDir, testLogger } from '../../test_util.js'
28+
import * as version from '../../../version.mjs'
2429

2530
const tmpDir = getTmpDir()
2631
const configFile = path.join(tmpDir, 'resource-manager.config')
@@ -62,6 +67,27 @@ describe('ProfileManager', () => {
6267
])('determine chart values for a profile', (input) => {
6368
it(`should determine FST chart values [profile = ${input.profileName}]`, async () => {
6469
configManager.setFlag(flags.profileFile, input.profileFile)
70+
configManager.setFlag(flags.cacheDir, getTestCacheDir('ProfileManager'))
71+
configManager.setFlag(flags.releaseTag, version.HEDERA_PLATFORM_VERSION)
72+
73+
const stagingDir = Templates.renderStagingDir(
74+
configManager.getFlag(flags.cacheDir),
75+
configManager.getFlag(flags.releaseTag)
76+
)
77+
78+
const resources = ['templates', 'profiles']
79+
for (const dirName of resources) {
80+
const srcDir = path.resolve(path.join(constants.RESOURCES_DIR, dirName))
81+
if (!fs.existsSync(srcDir)) continue
82+
83+
const destDir = path.resolve(path.join(stagingDir, dirName))
84+
if (!fs.existsSync(destDir)) {
85+
fs.mkdirSync(destDir, { recursive: true })
86+
}
87+
88+
fs.cpSync(srcDir, destDir, { recursive: true })
89+
}
90+
6591
profileManager.loadProfiles(true)
6692
const valuesFile = await profileManager.prepareValuesForFstChart(input.profileName)
6793
expect(valuesFile).not.toBeNull()
@@ -93,6 +119,8 @@ describe('ProfileManager', () => {
93119

94120
it(`should determine mirror-node chart values [profile = ${input.profileName}]`, async () => {
95121
configManager.setFlag(flags.profileFile, input.profileFile)
122+
configManager.setFlag(flags.cacheDir, getTestCacheDir('ProfileManager'))
123+
configManager.setFlag(flags.releaseTag, version.HEDERA_PLATFORM_VERSION)
96124
profileManager.loadProfiles(true)
97125
const valuesFile = await profileManager.prepareValuesForMirrorNodeChart(input.profileName)
98126
expect(fs.existsSync(valuesFile)).toBeTruthy()

0 commit comments

Comments
 (0)