Skip to content

Commit

Permalink
wip: attempting to fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Ivo Yankov <[email protected]>
  • Loading branch information
Ivo-Yankov committed Dec 20, 2024
1 parent 7698f16 commit 24269fe
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 40 deletions.
3 changes: 2 additions & 1 deletion src/core/config_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import * as helpers from './helpers.js';
import type * as yargs from 'yargs';
import {type CommandFlag} from '../types/flag_types.js';
import {type ListrTaskWrapper} from 'listr2';
import {autoInjectable} from 'tsyringe-neo';
import {autoInjectable, container} from 'tsyringe-neo';

/**
* ConfigManager cache command flag values so that user doesn't need to enter the same values repeatedly.
Expand All @@ -35,6 +35,7 @@ export class ConfigManager {
config!: Record<string, any>;

constructor(private readonly logger?: SoloLogger) {
const logger2 = container.resolve(SoloLogger)
this.reset();
}

Expand Down
3 changes: 0 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import * as commands from './commands/index.js';
import {HelmDependencyManager, DependencyManager} from './core/dependency_managers/index.js';
import * as constants from './core/constants.js';
import {PackageDownloader} from './core/package_downloader.js';
import {Zippy} from './core/zippy.js';
import {Helm} from './core/helm.js';
import {ChartManager} from './core/chart_manager.js';
import {ConfigManager} from './core/config_manager.js';
Expand All @@ -44,8 +43,6 @@ import * as helpers from './core/helpers.js';
import {K8} from './core/k8.js';
import {CustomProcessOutput} from './core/process_output.js';
import {type Opts} from './types/command_types.js';
import {IntervalLeaseRenewalService} from './core/lease/interval_lease_renewal.js';
import {type LeaseRenewalService} from './core/lease/lease.js';
import {container} from 'tsyringe-neo';
import {SoloLogger} from './core/logging.js';

Expand Down
4 changes: 4 additions & 0 deletions test/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
import * as chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import sinonChai from 'sinon-chai';
import 'reflect-metadata';
import {resetTestContainer} from './test_container.js';

resetTestContainer();

chai.use(chaiAsPromised);
chai.use(sinonChai);
Expand Down
52 changes: 52 additions & 0 deletions test/test_container.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import {container} from "tsyringe-neo";
import {SoloLogger} from "../src/core/logging.js";
import {PackageDownloader} from "../src/core/package_downloader.js";
import {Zippy} from "../src/core/zippy.js";
import {DependencyManager, HelmDependencyManager} from "../src/core/dependency_managers/index.js";
import {Helm} from "../src/core/helm.js";
import {ChartManager} from "../src/core/chart_manager.js";
import {ConfigManager} from "../src/core/config_manager.js";
import {K8} from "../src/core/k8.js";
import {AccountManager} from "../src/core/account_manager.js";
import {PlatformInstaller} from "../src/core/platform_installer.js";
import {KeyManager} from "../src/core/key_manager.js";
import {ProfileManager} from "../src/core/profile_manager.js";
import {IntervalLeaseRenewalService} from "../src/core/lease/interval_lease_renewal.js";
import {LeaseManager} from "../src/core/lease/lease_manager.js";
import {CertificateManager} from "../src/core/certificate_manager.js";
import path from "path";
import * as constants from "../src/core/constants.js";
import {LocalConfig} from "../src/core/config/local_config.js";
import {RemoteConfigManager} from "../src/core/config/remote/remote_config_manager.js";


let cacheDir = path.join('test', 'data', 'tmp');
// if (!cacheDir) cacheDir = path.join('test', 'data', 'tmp');
// container.reset();
container.register<SoloLogger>(SoloLogger, {useValue: new SoloLogger('debug', true)});
container.register<PackageDownloader>(PackageDownloader, {useValue: new PackageDownloader()});
container.register<Zippy>(Zippy, {useValue: new Zippy()});
container.register<HelmDependencyManager>(HelmDependencyManager, {useValue: new HelmDependencyManager()});
container.register<DependencyManager>(DependencyManager, {useValue: new DependencyManager()});
container.register<Helm>(Helm, {useValue: new Helm()});
container.register<ChartManager>(ChartManager, {useValue: new ChartManager()});
container.register<ConfigManager>(ConfigManager, {useValue: new ConfigManager()});
container.register<K8>(K8, {useValue: new K8()});
container.register<AccountManager>(AccountManager, {useValue: new AccountManager()});
container.register<PlatformInstaller>(PlatformInstaller, {useValue: new PlatformInstaller()});
container.register<KeyManager>(KeyManager, {useValue: new KeyManager()});
container.register<ProfileManager>(ProfileManager, {useValue: new ProfileManager()});
container.register<IntervalLeaseRenewalService>(IntervalLeaseRenewalService, {
useValue: new IntervalLeaseRenewalService(),
});
container.register<LeaseManager>(LeaseManager, {
useValue: new LeaseManager(container.resolve(IntervalLeaseRenewalService)),
});
container.register<CertificateManager>(CertificateManager, {useValue: new CertificateManager()});
const localConfigPath = path.join(cacheDir, constants.DEFAULT_LOCAL_CONFIG_FILE);
container.register<LocalConfig>(LocalConfig, {useValue: new LocalConfig(localConfigPath)});
container.register<RemoteConfigManager>(RemoteConfigManager, {useValue: new RemoteConfigManager()});

export function resetTestContainer(cacheDir?: string) {

}
6 changes: 5 additions & 1 deletion test/test_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {AccountCommand} from '../src/commands/account.js';
import {SoloError} from '../src/core/errors.js';
import {execSync} from 'child_process';
import * as NodeCommandConfigs from '../src/commands/node/configs.js';
import type {SoloLogger} from '../src/core/logging.js';
import {SoloLogger} from '../src/core/logging.js';
import type {BaseCommand} from '../src/commands/base.js';
import type {NodeAlias} from '../src/types/aliases.js';
import type {NetworkNodeServices} from '../src/core/network_node_services.js';
Expand All @@ -61,6 +61,7 @@ import {HEDERA_PLATFORM_VERSION} from '../version.js';
import {IntervalLeaseRenewalService} from '../src/core/lease/interval_lease_renewal.js';
import {Duration} from '../src/core/time/duration.js';
import {container} from 'tsyringe-neo';
import {resetTestContainer} from "./test_container.js";

export const testLogger = logging.NewLogger('debug', true);
export const TEST_CLUSTER = 'solo-e2e';
Expand Down Expand Up @@ -138,6 +139,9 @@ export function bootstrapTestVariables(
): BootstrapResponse {
const namespace: string = argv[flags.namespace.name] || 'bootstrap-ns';
const cacheDir: string = argv[flags.cacheDir.name] || getTestCacheDir(testName);

// resetTestContainer(cacheDir)

const configManager = container.resolve(ConfigManager);
configManager.update(argv);

Expand Down
36 changes: 21 additions & 15 deletions test/unit/commands/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,34 @@ import * as logging from '../../../src/core/logging.js';
import {BaseCommand} from '../../../src/commands/base.js';
import {Flags as flags} from '../../../src/commands/flags.js';
import sinon from 'sinon';
import path from 'path';
import {BASE_TEST_DIR} from '../../test_util.js';
import {container} from 'tsyringe-neo';

const testLogger = logging.NewLogger('debug', true);

describe('BaseCommand', () => {
const helm = container.resolve(Helm);
const chartManager = container.resolve(ChartManager);
const configManager = container.resolve(ConfigManager);

const depManager = container.resolve(DependencyManager);
const localConfig = new LocalConfig(path.join(BASE_TEST_DIR, 'local-config.yaml'));
const remoteConfigManager = container.resolve(RemoteConfigManager);

import {SoloLogger} from "../../../src/core/logging.js";
import {resetTestContainer} from "../../test_container.js";

describe.only('BaseCommand', () => {
let helm: Helm;
let chartManager: ChartManager;
let configManager: ConfigManager;
let depManager: DependencyManager;
let localConfig: LocalConfig;
let remoteConfigManager: RemoteConfigManager;
let sandbox = sinon.createSandbox();
let testLogger: SoloLogger;

let baseCmd: BaseCommand;

describe('runShell', () => {
before(() => {
sandbox = sinon.createSandbox();
// resetTestContainer();
testLogger = container.resolve(SoloLogger);
helm = container.resolve(Helm);
chartManager = container.resolve(ChartManager);
configManager = container.resolve(ConfigManager);
depManager = container.resolve(DependencyManager);
localConfig = container.resolve(LocalConfig);
remoteConfigManager = container.resolve(RemoteConfigManager);

sandbox = sinon.createSandbox();
sandbox.stub(K8.prototype, 'init').callsFake(() => this);
const k8 = container.resolve(K8);

Expand Down
5 changes: 4 additions & 1 deletion test/unit/commands/network.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@ argv[flags.chartDirectory.name] = undefined;
describe('NetworkCommand unit tests', () => {
describe('Chart Install Function is called correctly', () => {
let opts: any;
let bootstrapResp: any;

const bootstrapResp = bootstrapTestVariables(testName, argv);
before(() => {
bootstrapResp = bootstrapTestVariables(testName, argv);
})

beforeEach(() => {
opts = getBaseCommandOpts();
Expand Down
15 changes: 9 additions & 6 deletions test/unit/core/platform_installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ import {IllegalArgumentError, MissingArgumentError} from '../../../src/core/erro
import {getK8Instance} from '../../test_util.js';
import type {PodName} from '../../../src/types/aliases.js';
import {container} from 'tsyringe-neo';
import {K8} from "../../../src/core/k8.js";
import {SoloLogger} from "../../../src/core/logging.js";

describe('PackageInstaller', () => {
const testLogger = logging.NewLogger('debug', true);
const configManager = container.resolve(ConfigManager);

const k8 = getK8Instance(configManager);

const installer = container.resolve(PlatformInstaller);
let testLogger: SoloLogger, configManager: ConfigManager, k8: K8, installer: PlatformInstaller;
before(() => {
testLogger = logging.NewLogger('debug', true);
configManager = container.resolve(ConfigManager);
k8 = getK8Instance(configManager);
installer = container.resolve(PlatformInstaller);
})

describe('validatePlatformReleaseDir', () => {
it('should fail for missing path', () => {
Expand Down
33 changes: 20 additions & 13 deletions test/unit/core/profile_manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,28 @@ import * as version from '../../../version.js';
import type {NodeAlias} from '../../../src/types/aliases.js';
import {container} from 'tsyringe-neo';

const tmpDir = getTmpDir();
const configManager = container.resolve(ConfigManager);
const profileManager = new ProfileManager(tmpDir);
configManager.setFlag(flags.nodeAliasesUnparsed, 'node1,node2,node4');
const testProfileFile = path.join('test', 'data', 'test-profiles.yaml');
configManager.setFlag(flags.cacheDir, getTestCacheDir('ProfileManager'));
configManager.setFlag(flags.releaseTag, version.HEDERA_PLATFORM_VERSION);
const cacheDir = configManager.getFlag<string>(flags.cacheDir) as string;
configManager.setFlag(flags.apiPermissionProperties, path.join(cacheDir, 'templates', 'api-permission.properties'));
configManager.setFlag(flags.applicationProperties, path.join(cacheDir, 'templates', 'application.properties'));
configManager.setFlag(flags.bootstrapProperties, path.join(cacheDir, 'templates', 'bootstrap.properties'));
configManager.setFlag(flags.log4j2Xml, path.join(cacheDir, 'templates', 'log4j2.xml'));
configManager.setFlag(flags.settingTxt, path.join(cacheDir, 'templates', 'settings.txt'));


describe('ProfileManager', () => {
let tmpDir: string, configManager: ConfigManager, profileManager: ProfileManager, testProfileFile: string,
cacheDir: string;

before(() => {
tmpDir = getTmpDir();
configManager = container.resolve(ConfigManager);
profileManager = new ProfileManager(tmpDir);
configManager.setFlag(flags.nodeAliasesUnparsed, 'node1,node2,node4');
testProfileFile = path.join('test', 'data', 'test-profiles.yaml');
configManager.setFlag(flags.cacheDir, getTestCacheDir('ProfileManager'));
configManager.setFlag(flags.releaseTag, version.HEDERA_PLATFORM_VERSION);
cacheDir = configManager.getFlag<string>(flags.cacheDir) as string;
configManager.setFlag(flags.apiPermissionProperties, path.join(cacheDir, 'templates', 'api-permission.properties'));
configManager.setFlag(flags.applicationProperties, path.join(cacheDir, 'templates', 'application.properties'));
configManager.setFlag(flags.bootstrapProperties, path.join(cacheDir, 'templates', 'bootstrap.properties'));
configManager.setFlag(flags.log4j2Xml, path.join(cacheDir, 'templates', 'log4j2.xml'));
configManager.setFlag(flags.settingTxt, path.join(cacheDir, 'templates', 'settings.txt'));
});

after(() => {
fs.rmSync(tmpDir, {recursive: true});
});
Expand Down

0 comments on commit 24269fe

Please sign in to comment.