diff --git a/src/commands/node.ts b/src/commands/node.ts index d38d6fdb2..e48b41b91 100644 --- a/src/commands/node.ts +++ b/src/commands/node.ts @@ -798,9 +798,9 @@ export class NodeCommand extends BaseCommand { const self = this if (localBuildPath !== '') { return self.uploadPlatformSoftware(nodeAliases, podNames, task, localBuildPath) - } + } return self.fetchPlatformSoftware(nodeAliases, podNames, releaseTag, task, self.platformInstaller) - + } fetchPlatformSoftware (nodeAliases: NodeAliases, podNames: Record, releaseTag: string, @@ -1214,7 +1214,6 @@ export class NodeCommand extends BaseCommand { // reset flags so that keys are not regenerated later self.configManager.setFlag(flags.generateGossipKeys, false) self.configManager.setFlag(flags.generateTlsKeys, false) - self.configManager.persist() } } ]) @@ -1844,7 +1843,6 @@ export class NodeCommand extends BaseCommand { // reset flags so that keys are not regenerated later self.configManager.setFlag(flags.generateGossipKeys, false) self.configManager.setFlag(flags.generateTlsKeys, false) - self.configManager.persist() } } ] @@ -2652,7 +2650,6 @@ export class NodeCommand extends BaseCommand { // reset flags so that keys are not regenerated later self.configManager.setFlag(flags.generateGossipKeys, false) self.configManager.setFlag(flags.generateTlsKeys, false) - self.configManager.persist() } } ], { @@ -2869,7 +2866,6 @@ export class NodeCommand extends BaseCommand { // reset flags so that keys are not regenerated later self.configManager.setFlag(flags.generateGossipKeys, false) self.configManager.setFlag(flags.generateTlsKeys, false) - self.configManager.persist() } } ] diff --git a/src/commands/prompts.ts b/src/commands/prompts.ts index b16ed0c8c..4ca79f962 100644 --- a/src/commands/prompts.ts +++ b/src/commands/prompts.ts @@ -503,8 +503,6 @@ export async function execute (task: ListrTaskWrapper, configMana const input = await prompt(task, configManager.getFlag(flag)) configManager.setFlag(flag, input) } - - configManager.persist() } /** diff --git a/src/commands/relay.ts b/src/commands/relay.ts index d6b1f88ba..e28e67a2c 100644 --- a/src/commands/relay.ts +++ b/src/commands/relay.ts @@ -236,7 +236,6 @@ export class RelayCommand extends BaseCommand { // reset nodeAlias self.configManager.setFlag(flags.nodeAliasesUnparsed, '') - self.configManager.persist() } }, { @@ -316,7 +315,6 @@ export class RelayCommand extends BaseCommand { // reset nodeAliasesUnparsed self.configManager.setFlag(flags.nodeAliasesUnparsed, '') - self.configManager.persist() }, skip: (ctx) => !ctx.config.isChartInstalled } diff --git a/src/core/config_manager.ts b/src/core/config_manager.ts index 064e1bdd1..7e636323f 100644 --- a/src/core/config_manager.ts +++ b/src/core/config_manager.ts @@ -14,15 +14,11 @@ * limitations under the License. * */ -import fs from 'fs' import { SoloError, MissingArgumentError } from './errors.ts' -import { constants } from './index.ts' import { SoloLogger } from './logging.ts' import * as flags from '../commands/flags.ts' import * as paths from 'path' import * as helpers from './helpers.ts' -import * as yaml from 'js-yaml' -import { yamlToObject } from './helpers.ts' import type * as yargs from 'yargs' import { type CommandFlag } from '../types/index.js' @@ -35,26 +31,12 @@ import { type CommandFlag } from '../types/index.js' export class ConfigManager { config!: Record - constructor (private readonly logger: SoloLogger, private readonly cachedConfigFile = constants.SOLO_CONFIG_FILE) { + constructor (private readonly logger: SoloLogger) { if (!logger || !(logger instanceof SoloLogger)) throw new MissingArgumentError('An instance of core/SoloLogger is required') - if (!cachedConfigFile) throw new MissingArgumentError('cached config file path is required') this.reset() } - /** - * Load the cached config - */ - load () { - try { - if (fs.existsSync(this.cachedConfigFile)) { - this.config = yamlToObject(this.cachedConfigFile) as Record - } - } catch (e: Error | any) { - throw new SoloError(`failed to initialize config manager: ${e.message}`, e) - } - } - /** Reset config */ reset () { this.config = { @@ -69,8 +51,7 @@ export class ConfigManager { * * It uses the below precedence for command flag values: * 1. User input of the command flag - * 2. Cached config value of the command flag. - * 3. Default value of the command flag if the command is not 'init'. + * 2. Default value of the command flag if the command is not 'init'. */ applyPrecedence (argv: yargs.Argv, aliases: any): yargs.Argv { for (const key of Object.keys(aliases)) { @@ -93,7 +74,7 @@ export class ConfigManager { } /** Update the config using the argv */ - update (argv: object | any = {}, persist: boolean = false) { + update (argv: object | any = {}) { if (argv && Object.keys(argv).length > 0) { for (const flag of flags.allFlags) { if (flag.name === flags.force.name) { @@ -147,23 +128,6 @@ export class ConfigManager { } this.config.updatedAt = new Date().toISOString() - - if (persist) { - this.persist() - } - } - } - - /** Persist the config in the cached config file */ - persist () { - try { - this.config.updatedAt = new Date().toISOString() - const newYaml = yaml.dump(this.config) - fs.writeFileSync(this.cachedConfigFile, newYaml) - // refresh config with the file contents - this.load() - } catch (e: Error | any) { - throw new SoloError(`failed to persis config: ${e.message}`, e) } } @@ -194,9 +158,4 @@ export class ConfigManager { getVersion (): string { return this.config.version } - - /** Get last updated at timestamp */ - getUpdatedAt (): string { - return this.config.updatedAt - } } diff --git a/src/core/constants.ts b/src/core/constants.ts index 1164d53fe..d06d0e314 100644 --- a/src/core/constants.ts +++ b/src/core/constants.ts @@ -30,7 +30,6 @@ export const SOLO_CACHE_DIR = path.join(SOLO_HOME_DIR, 'cache') export const SOLO_VALUES_DIR = path.join(SOLO_CACHE_DIR, 'values-files') export const DEFAULT_NAMESPACE = 'default' export const HELM = 'helm' -export const SOLO_CONFIG_FILE = path.join(SOLO_HOME_DIR, 'solo.yaml') export const RESOURCES_DIR = normalize(path.join(ROOT_DIR, 'resources')) export const TEMP_DIR = normalize(path.join(ROOT_DIR, 'temp')) diff --git a/src/index.ts b/src/index.ts index 92cdb876e..ed8349449 100644 --- a/src/index.ts +++ b/src/index.ts @@ -46,7 +46,7 @@ export function main (argv: any) { const zippy = new Zippy(logger) const helmDepManager = new HelmDependencyManager(downloader, zippy, logger) const depManagerMap = new Map() - .set(constants.HELM, helmDepManager) + .set(constants.HELM, helmDepManager) const depManager = new DependencyManager(logger, depManagerMap) const helm = new Helm(logger) @@ -79,7 +79,9 @@ export function main (argv: any) { } const processArguments = (argv: any, yargs: any) => { - argv._[0] === 'init' ? configManager.reset() : configManager.load() + if (argv._[0] === 'init') { + configManager.reset() + } // Set default cluster name and namespace from kubernetes context // these will be overwritten if user has entered the flag values explicitly @@ -92,7 +94,7 @@ export function main (argv: any) { argv = configManager.applyPrecedence(argv, yargs.parsed.aliases) // update and persist config - configManager.update(argv, true) + configManager.update(argv) logger.showUser(chalk.cyan('\n******************************* Solo *********************************************')) logger.showUser(chalk.cyan('Version\t\t\t:'), chalk.yellow(configManager.getVersion())) @@ -105,19 +107,19 @@ export function main (argv: any) { } return yargs(hideBin(argv)) - .usage('Usage:\n $0 [options]') - .alias('h', 'help') - .alias('v', 'version') - // @ts-ignore - .command(commands.Initialize(opts)) - .strict() - // @ts-ignore - .option(flags.devMode.name, flags.devMode.definition) - .wrap(120) - .demand(1, 'Select a command') - // @ts-ignore - .middleware(processArguments, false) // applyBeforeValidate = false as otherwise middleware is called twice - .parse() + .usage('Usage:\n $0 [options]') + .alias('h', 'help') + .alias('v', 'version') + // @ts-ignore + .command(commands.Initialize(opts)) + .strict() + // @ts-ignore + .option(flags.devMode.name, flags.devMode.definition) + .wrap(120) + .demand(1, 'Select a command') + // @ts-ignore + .middleware(processArguments, false) // applyBeforeValidate = false as otherwise middleware is called twice + .parse() } catch (e: Error | any) { logger.showUserError(e) process.exit(1) diff --git a/test/e2e/commands/account.test.ts b/test/e2e/commands/account.test.ts index 9094bec3c..41ed974cd 100644 --- a/test/e2e/commands/account.test.ts +++ b/test/e2e/commands/account.test.ts @@ -144,7 +144,7 @@ e2eTestSuite(testName, argv, undefined, undefined, undefined, undefined, undefin try { argv[flags.privateKey.name] = constants.GENESIS_KEY argv[flags.amount.name] = 777 - configManager.update(argv, true) + configManager.update(argv) await expect(accountCmd.create(argv)).to.eventually.be.ok @@ -166,7 +166,7 @@ e2eTestSuite(testName, argv, undefined, undefined, undefined, undefined, undefin try { argv[flags.amount.name] = 0 argv[flags.accountId.name] = accountId1 - configManager.update(argv, true) + configManager.update(argv) await expect(accountCmd.update(argv)).to.eventually.be.ok @@ -188,7 +188,7 @@ e2eTestSuite(testName, argv, undefined, undefined, undefined, undefined, undefin argv[flags.accountId.name] = accountId2 argv[flags.privateKey.name] = constants.GENESIS_KEY argv[flags.amount.name] = 333 - configManager.update(argv, true) + configManager.update(argv) await expect(accountCmd.update(argv)).to.eventually.be.ok @@ -208,7 +208,7 @@ e2eTestSuite(testName, argv, undefined, undefined, undefined, undefined, undefin it('should be able to get account-1', async () => { try { argv[flags.accountId.name] = accountId1 - configManager.update(argv, true) + configManager.update(argv) await expect(accountCmd.get(argv)).to.eventually.be.ok // @ts-ignore to access the private property @@ -227,7 +227,7 @@ e2eTestSuite(testName, argv, undefined, undefined, undefined, undefined, undefin it('should be able to get account-2', async () => { try { argv[flags.accountId.name] = accountId2 - configManager.update(argv, true) + configManager.update(argv) await expect(accountCmd.get(argv)).to.eventually.be.ok // @ts-ignore to access the private property @@ -249,7 +249,7 @@ e2eTestSuite(testName, argv, undefined, undefined, undefined, undefined, undefin try { argv[flags.ecdsaPrivateKey.name] = ecdsaPrivateKey.toString() argv[flags.setAlias.name] = true - configManager.update(argv, true) + configManager.update(argv) await expect(accountCmd.create(argv)).to.eventually.be.ok diff --git a/test/e2e/commands/cluster.test.ts b/test/e2e/commands/cluster.test.ts index f65bfacc7..2c1357136 100644 --- a/test/e2e/commands/cluster.test.ts +++ b/test/e2e/commands/cluster.test.ts @@ -65,7 +65,7 @@ describe('ClusterCommand', () => { await k8.deleteNamespace(namespace) argv[flags.clusterSetupNamespace.name] = constants.SOLO_SETUP_NAMESPACE - configManager.update(argv, true) + configManager.update(argv) await clusterCmd.setup(argv) // restore solo-cluster-setup for other e2e tests to leverage do { await sleep(5 * SECONDS) @@ -85,13 +85,13 @@ describe('ClusterCommand', () => { it('solo cluster setup should fail with invalid cluster name', async () => { argv[flags.clusterSetupNamespace.name] = 'INVALID' - configManager.update(argv, true) + configManager.update(argv) await expect(clusterCmd.setup(argv)).to.be.rejectedWith('Error on cluster setup') }).timeout(MINUTES) it('solo cluster setup should work with valid args', async () => { argv[flags.clusterSetupNamespace.name] = namespace - configManager.update(argv, true) + configManager.update(argv) await expect(clusterCmd.setup(argv)).to.eventually.be.ok }).timeout(MINUTES) @@ -111,7 +111,7 @@ describe('ClusterCommand', () => { // helm list would return an empty list if given invalid namespace it('solo cluster reset should fail with invalid cluster name', async () => { argv[flags.clusterSetupNamespace.name] = 'INVALID' - configManager.update(argv, true) + configManager.update(argv) try { await expect(clusterCmd.reset(argv)).to.be.rejectedWith('Error on cluster reset') @@ -123,7 +123,7 @@ describe('ClusterCommand', () => { it('solo cluster reset should work with valid args', async () => { argv[flags.clusterSetupNamespace.name] = namespace - configManager.update(argv, true) + configManager.update(argv) await expect(clusterCmd.reset(argv)).to.eventually.be.ok }).timeout(MINUTES) }) diff --git a/test/e2e/commands/network.test.ts b/test/e2e/commands/network.test.ts index 50cafe7a8..3f33185bc 100644 --- a/test/e2e/commands/network.test.ts +++ b/test/e2e/commands/network.test.ts @@ -123,7 +123,7 @@ describe('NetworkCommand', () => { argv[flags.deletePvcs.name] = true argv[flags.deleteSecrets.name] = true argv[flags.force.name] = true - configManager.update(argv, true) + configManager.update(argv) try { await expect(networkCmd.destroy(argv)).to.eventually.be.ok diff --git a/test/e2e/e2e_node_util.ts b/test/e2e/e2e_node_util.ts index 38352361f..e353a68e3 100644 --- a/test/e2e/e2e_node_util.ts +++ b/test/e2e/e2e_node_util.ts @@ -23,17 +23,15 @@ import { balanceQueryShouldSucceed, e2eTestSuite, getDefaultArgv, - getTestConfigManager, HEDERA_PLATFORM_VERSION_TAG, - TEST_CLUSTER + TEST_CLUSTER, testLogger } from '../test_util.ts' import { getNodeLogs, sleep } from '../../src/core/helpers.ts' import { NodeCommand } from '../../src/commands/node.ts' import { MINUTES, SECONDS } from '../../src/core/constants.ts' import type { NodeAlias } from '../../src/types/aliases.ts' -import { NodeAliases } from '../../src/types/aliases.ts' import type { ListrTaskWrapper } from 'listr2' -import type { K8 } from '../../src/core/index.ts' +import { ConfigManager, type K8 } from '../../src/core/index.ts' export function e2eNodeKeyRefreshTest (testName: string, mode: string, releaseTag = HEDERA_PLATFORM_VERSION_TAG) { const namespace = testName @@ -174,8 +172,8 @@ export function e2eNodeKeyRefreshTest (testName: string, mode: string, releaseTa async function nodeRefreshTestSetup (argv: Record, testName: string, k8: K8, nodeAliases: string) { argv[flags.nodeAliasesUnparsed.name] = nodeAliases - const configManager = getTestConfigManager(`${testName}-solo.yaml`) - configManager.update(argv, true) + const configManager = new ConfigManager(testLogger) + configManager.update(argv) const podArray = await k8.getPodsByLabel( [`app=network-${nodeAliases}`, diff --git a/test/e2e/integration/core/platform_installer_e2e.test.ts b/test/e2e/integration/core/platform_installer_e2e.test.ts index ba1ca07bb..cb70703b7 100644 --- a/test/e2e/integration/core/platform_installer_e2e.test.ts +++ b/test/e2e/integration/core/platform_installer_e2e.test.ts @@ -50,7 +50,6 @@ e2eTestSuite(namespace, argv, undefined, undefined, undefined, undefined, undefi describe('PackageInstallerE2E', async () => { const k8 = bootstrapResp.opts.k8 const accountManager = bootstrapResp.opts.accountManager - const configManager = bootstrapResp.opts.configManager const installer = bootstrapResp.opts.platformInstaller const podName = 'network-node1-0' const packageVersion = 'v0.42.5' @@ -68,7 +67,6 @@ e2eTestSuite(namespace, argv, undefined, undefined, undefined, undefined, undefi if (!fs.existsSync(testCacheDir)) { fs.mkdirSync(testCacheDir) } - configManager.load() }) describe('fetchPlatform', () => { diff --git a/test/test_util.ts b/test/test_util.ts index 85abc0a37..cea164a77 100644 --- a/test/test_util.ts +++ b/test/test_util.ts @@ -80,14 +80,6 @@ export function getTmpDir () { return fs.mkdtempSync(path.join(os.tmpdir(), 'solo-')) } -/** - * Return a config manager with the specified config file name - * @param fileName solo config file name - */ -export function getTestConfigManager (fileName = 'solo-test.config') { - return new ConfigManager(testLogger, path.join(getTestCacheDir(), fileName)) -} - /** Get argv with defaults */ export function getDefaultArgv () { const argv: Record = {} @@ -138,8 +130,8 @@ export function bootstrapTestVariables ( ): BootstrapResponse { const namespace: string = argv[flags.namespace.name] || 'bootstrap-ns' const cacheDir: string = argv[flags.cacheDir.name] || getTestCacheDir(testName) - const configManager = getTestConfigManager(`${testName}-solo.yaml`) - configManager.update(argv, true) + const configManager = new ConfigManager(testLogger) + configManager.update(argv) const downloader = new PackageDownloader(testLogger) const zippy = new Zippy(testLogger) diff --git a/test/unit/core/config_manager.test.ts b/test/unit/core/config_manager.test.ts index 688126271..db8a24206 100644 --- a/test/unit/core/config_manager.test.ts +++ b/test/unit/core/config_manager.test.ts @@ -15,46 +15,16 @@ * */ import { expect } from 'chai' -import { describe, it, after } from 'mocha' +import { describe, it } from 'mocha' -import os from 'os' -import path from 'path' import { ConfigManager } from '../../../src/core/index.ts' import * as flags from '../../../src/commands/flags.ts' -import fs from 'fs' import { testLogger } from '../../test_util.ts' -import * as helpers from '../../../src/core/helpers.ts' -import { yamlToObject } from '../../../src/core/helpers.ts' describe('ConfigManager', () => { - it('should persist config', () => { - const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'config-')) - const tmpFile = path.join(tmpDir, 'test.yaml') - - expect(fs.existsSync(tmpFile)).to.not.be.ok - const cm = new ConfigManager(testLogger, tmpFile) - cm.persist() - expect(fs.existsSync(tmpFile)).to.be.ok - - const cachedConfig = yamlToObject(tmpFile) - - expect(cachedConfig.version).to.equal(helpers.packageVersion()) - expect(cachedConfig.flags).to.deep.equal({}) - expect(cachedConfig.updatedAt).not.to.equal('') - - expect(cachedConfig.updatedAt).to.equal(cm.getUpdatedAt()) - expect(cachedConfig.version).to.equal(cm.getVersion()) - expect(cachedConfig.flags).to.deep.equal(cm.config.flags) - - fs.rmSync(tmpDir, { recursive: true }) - }) - describe('update values using argv', () => { - const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'config-')) - const tmpFile = path.join(tmpDir, 'test.yaml') - it('should update string flag value', () => { - const cm = new ConfigManager(testLogger, tmpFile) + const cm = new ConfigManager(testLogger) const argv = {} argv[flags.releaseTag.name] = 'v0.42.5' @@ -70,7 +40,7 @@ describe('ConfigManager', () => { }) it('should update number flag value', () => { - const cm = new ConfigManager(testLogger, tmpFile) + const cm = new ConfigManager(testLogger) const argv = {} argv[flags.replicaCount.name] = 1 @@ -86,7 +56,7 @@ describe('ConfigManager', () => { }) it('should update boolean flag value', () => { - const cm = new ConfigManager(testLogger, tmpFile) + const cm = new ConfigManager(testLogger) // boolean values should work const argv = {} @@ -108,22 +78,16 @@ describe('ConfigManager', () => { expect(cm.getFlag(flags.devMode)).not.to.equal(argv[flags.devMode.name]) expect(cm.getFlag(flags.devMode)).to.equal(true) }) - - after(() => { - fs.rmdirSync(tmpDir, { recursive: true }) - }) }) describe('should apply precedence', () => { - const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'config-')) - const tmpFile = path.join(tmpDir, 'test.yaml') const aliases = {} aliases[flags.devMode.name] = [flags.devMode.name, flags.devMode.definition.alias] // mock it('should take user input as the first preference', () => { // Given: config has value, argv has a different value // Expected: argv should retain the value - const cm = new ConfigManager(testLogger, tmpFile) + const cm = new ConfigManager(testLogger) cm.setFlag(flags.devMode, false) expect(cm.getFlag(flags.devMode)).not.to.be.ok @@ -135,24 +99,10 @@ describe('ConfigManager', () => { expect(argv2[flags.devMode.name]).to.be.ok // retain the value }) - it('should take cached config as the second preference', () => { - // Given: config has value, argv doesn't have the flag value - // Expected: argv should inherit the flag value from cached config - const cm = new ConfigManager(testLogger, tmpFile) - - cm.setFlag(flags.devMode, false) - expect(cm.getFlag(flags.devMode)).to.not.be.ok - - const argv = {} // devMode flag is not set in argv - const argv2 = cm.applyPrecedence(argv as any, aliases) - expect(cm.getFlag(flags.devMode)).to.not.be.ok // shouldn't have changed - expect(argv2[flags.devMode.name]).to.equal(cm.getFlag(flags.devMode)) // should inherit from config - }) - it('should take default as the last preference', () => { // Given: neither config nor argv has the flag value set // Expected: argv should inherit the default flag value - const cm = new ConfigManager(testLogger, tmpFile) + const cm = new ConfigManager(testLogger) expect(cm.hasFlag(flags.devMode)).not.to.be.ok // shouldn't have set const argv = {} // devMode flag is not set in argv and cached config doesn't have it either @@ -160,111 +110,5 @@ describe('ConfigManager', () => { expect(cm.hasFlag(flags.devMode)).to.not.be.ok // shouldn't have set expect(argv2[flags.devMode.name]).to.not.be.ok // should have set from the default }) - - after(() => { - fs.rmdirSync(tmpDir, { recursive: true }) - }) - }) - - describe('load a cached config file', () => { - const configFilePath = process.cwd() + '/test/data/solo-test-1.config' - const cm = new ConfigManager(testLogger, configFilePath) - cm.load() - - it('config file match: dev=false', () => { - expect(cm.config.flags[flags.devMode.name]).to.not.be.ok - }) - - it('config file match: namespace=solo-user', () => { - expect(cm.config.flags[flags.namespace.name]).to.equal('solo-user') - }) - - it('config file match: chartDirectory is empty', () => { - expect(cm.config.flags[flags.chartDirectory.name]).to.equal('') - }) - - it('config file match: clusterName=kind-kind', () => { - expect(cm.config.flags[flags.clusterName.name]).to.equal('kind-kind') - }) - - it('config file match: deployPrometheusStack=false', () => { - expect(cm.config.flags[flags.deployPrometheusStack.name]).to.not.be.ok - }) - - it('config file match: deployMinio=false', () => { - expect(cm.config.flags[flags.deployMinio.name]).to.not.be.ok - }) - - it('config file match: deployCertManager=false', () => { - expect(cm.config.flags[flags.deployCertManager.name]).to.not.be.ok - }) - - it('config file match: deployCertManagerCrds=false', () => { - expect(cm.config.flags[flags.deployCertManagerCrds.name]).to.not.be.ok - }) - - it('not set, it should be undefined', () => { - expect(cm.config.flags[flags.enablePrometheusSvcMonitor.name]).to.be.undefined - }) - - it('not set, it should be undefined', () => { - expect(cm.config.flags[flags.enableHederaExplorerTls.name]).to.be.undefined - }) - - it('not set, it should be undefined', () => { - expect(cm.config.flags[flags.hederaExplorerTlsHostName.name]).to.be.undefined - }) - - it('not set, it should be undefined', () => { - expect(cm.config.flags[flags.deletePvcs.name]).to.be.undefined - }) - }) - - describe('handle argv overrides', () => { - const configFilePath = process.cwd() + '/test/data/solo-test-2.config' - const cm = new ConfigManager(testLogger, configFilePath) - const cachedConfig = yamlToObject(process.cwd() + '/test/data/solo-test-2.config') - - it('override config using argv', () => { - cm.load() - expect(cm.getFlag(flags.clusterName)).to.equal(cachedConfig.flags[flags.clusterName.name]) - expect(cm.getFlag(flags.namespace)).to.equal(cachedConfig.flags[flags.namespace.name]) - - const argv = {} - argv[flags.clusterName.name] = 'new-cluster' - argv[flags.namespace.name] = 'new-namespace' - cm.update(argv) - - expect(cm.getFlag(flags.clusterName)).to.equal(argv[flags.clusterName.name]) - expect(cm.getFlag(flags.namespace)).to.equal(argv[flags.namespace.name]) - }) - - it('config file takes precedence over empty namespace', () => { - cm.load() - expect(cm.getFlag(flags.clusterName)).to.equal(cachedConfig.flags[flags.clusterName.name]) - expect(cm.getFlag(flags.namespace)).to.equal(cachedConfig.flags[flags.namespace.name]) - - const argv = {} - argv[flags.clusterName.name] = 'new-cluster' - argv[flags.namespace.name] = '' - cm.update(argv) - expect(cm.getFlag(flags.clusterName)).to.equal(argv[flags.clusterName.name]) - expect(cm.getFlag(flags.namespace)).not.to.equal(argv[flags.namespace.name]) - expect(cm.getFlag(flags.namespace)).to.equal(cachedConfig.flags[flags.namespace.name]) - }) - - it('config file takes precedence over empty cluster name', () => { - cm.load() - expect(cm.getFlag(flags.clusterName)).to.equal(cachedConfig.flags[flags.clusterName.name]) - expect(cm.getFlag(flags.namespace)).to.equal(cachedConfig.flags[flags.namespace.name]) - - const argv = {} - argv[flags.clusterName.name] = '' - argv[flags.namespace.name] = 'new-namespace' - cm.update(argv) - expect(cm.getFlag(flags.clusterName)).not.to.equal(argv[flags.clusterName.name]) - expect(cm.getFlag(flags.clusterName)).to.equal(cachedConfig.flags[flags.clusterName.name]) - expect(cm.getFlag(flags.namespace)).to.equal(argv[flags.namespace.name]) - }) }) }) diff --git a/test/unit/core/k8.test.ts b/test/unit/core/k8.test.ts index 717ec2080..04528745f 100644 --- a/test/unit/core/k8.test.ts +++ b/test/unit/core/k8.test.ts @@ -18,8 +18,8 @@ import { expect } from 'chai' import { describe, it, after, before } from 'mocha' import jest from 'jest-mock' -import { constants, K8 } from '../../../src/core/index.ts' -import { getTestConfigManager, testLogger } from '../../test_util.ts' +import { ConfigManager, constants, K8 } from '../../../src/core/index.ts' +import { testLogger } from '../../test_util.ts' import { flags } from '../../../src/commands/index.ts' import { SECONDS } from '../../../src/core/constants.ts' @@ -43,7 +43,7 @@ const defaultTimeout = 20 * SECONDS describe('K8 Unit Tests', function () { this.timeout(defaultTimeout) - const argv = { } + const argv = {} const expectedResult = [ { metadata: { name: 'pod' }, @@ -57,14 +57,15 @@ describe('K8 Unit Tests', function () { } ] // @ts-ignore - const k8InitSpy = jest.spyOn(K8.prototype, 'init').mockImplementation(() => {}) + const k8InitSpy = jest.spyOn(K8.prototype, 'init').mockImplementation(() => { + }) const k8GetPodsByLabelSpy = jest.spyOn(K8.prototype, 'getPodsByLabel').mockResolvedValue(expectedResult) let k8: K8 before(() => { argv[flags.namespace.name] = 'namespace' - const configManager = getTestConfigManager('k8-solo.yaml') - configManager.update(argv, true) + const configManager = new ConfigManager(testLogger) + configManager.update(argv) k8 = new K8(configManager, testLogger) k8.kubeClient = { // @ts-ignore diff --git a/test/unit/core/profile_manager.test.ts b/test/unit/core/profile_manager.test.ts index 217b09f50..d44f10000 100644 --- a/test/unit/core/profile_manager.test.ts +++ b/test/unit/core/profile_manager.test.ts @@ -31,8 +31,7 @@ import * as version from '../../../version.ts' import type { NodeAlias } from '../../../src/types/aliases.ts' const tmpDir = getTmpDir() -const configFile = path.join(tmpDir, 'resource-manager.config') -const configManager = new ConfigManager(testLogger, configFile) +const configManager = new ConfigManager(testLogger) const profileManager = new ProfileManager(testLogger, configManager, tmpDir) configManager.setFlag(flags.nodeAliasesUnparsed, 'node1,node2,node4') const testProfileFile = path.join('test', 'data', 'test-profiles.yaml')