@hashgraph/solo
Version:
An opinionated CLI tool to deploy and manage private Hedera Networks.
115 lines • 5.95 kB
JavaScript
// SPDX-License-Identifier: Apache-2.0
import { BaseCommandTest } from './base-command-test.js';
import { main } from '../../../../src/index.js';
import { Duration } from '../../../../src/core/time/duration.js';
import { it } from 'mocha';
import { expect } from 'chai';
import fs from 'node:fs';
import { PathEx } from '../../../../src/business/utils/path-ex.js';
import { CacheCommandDefinition } from '../../../../src/commands/command-definitions/cache-command-definition.js';
/**
* Adjust these if your command-definition constants use different names,
* for example if the CLI path is `cache image pull`.
*/
export class CacheTest extends BaseCommandTest {
static soloCachePullArgv(testName) {
const { newArgv, argvPushGlobalFlags } = CacheTest;
const argv = newArgv();
argv.push(CacheCommandDefinition.COMMAND_NAME, CacheCommandDefinition.IMAGE_SUBCOMMAND_NAME, CacheCommandDefinition.IMAGE_PULL);
argvPushGlobalFlags(argv, testName, true, false);
return argv;
}
static soloCacheListArgv(testName) {
const { newArgv, argvPushGlobalFlags } = CacheTest;
const argv = newArgv();
argv.push(CacheCommandDefinition.COMMAND_NAME, CacheCommandDefinition.IMAGE_SUBCOMMAND_NAME, CacheCommandDefinition.IMAGE_LIST);
argvPushGlobalFlags(argv, testName, true, false);
return argv;
}
static soloCacheStatusArgv(testName) {
const { newArgv, argvPushGlobalFlags } = CacheTest;
const argv = newArgv();
argv.push(CacheCommandDefinition.COMMAND_NAME, CacheCommandDefinition.IMAGE_SUBCOMMAND_NAME, CacheCommandDefinition.IMAGE_STATUS);
argvPushGlobalFlags(argv, testName, true, false);
return argv;
}
static soloCacheClearArgv(testName) {
const { newArgv, argvPushGlobalFlags } = CacheTest;
const argv = newArgv();
argv.push(CacheCommandDefinition.COMMAND_NAME, CacheCommandDefinition.IMAGE_SUBCOMMAND_NAME, CacheCommandDefinition.IMAGE_CLEAR);
argvPushGlobalFlags(argv, testName, true, false);
return argv;
}
static soloCacheLoadArgv(testName) {
const { newArgv, argvPushGlobalFlags } = CacheTest;
const argv = newArgv();
argv.push(CacheCommandDefinition.COMMAND_NAME, CacheCommandDefinition.IMAGE_SUBCOMMAND_NAME, CacheCommandDefinition.IMAGE_LOAD);
argvPushGlobalFlags(argv, testName, true, false);
return argv;
}
static pull(options) {
const { testName } = options;
it(`${testName}: cache pull`, async () => {
await main(CacheTest.soloCachePullArgv(testName));
}).timeout(Duration.ofMinutes(10).toMillis());
}
static list(options) {
const { testName } = options;
it(`${testName}: cache list`, async () => {
await main(CacheTest.soloCacheListArgv(testName));
}).timeout(Duration.ofMinutes(5).toMillis());
}
static status(options) {
const { testName } = options;
it(`${testName}: cache status`, async () => {
await main(CacheTest.soloCacheStatusArgv(testName));
}).timeout(Duration.ofMinutes(5).toMillis());
}
static load(options) {
const { testName } = options;
it(`${testName}: cache load`, async () => {
await main(CacheTest.soloCacheLoadArgv(testName));
}).timeout(Duration.ofMinutes(10).toMillis());
}
static clear(options) {
const { testName } = options;
it(`${testName}: cache clear`, async () => {
await main(CacheTest.soloCacheClearArgv(testName));
}).timeout(Duration.ofMinutes(5).toMillis());
}
static pullListStatusClear(options) {
const { testName, testCacheDirectory } = options;
const cacheRoot = PathEx.join(testCacheDirectory, 'cache');
it(`${testName}: cache pull/list/status/clear workflow`, async () => {
await main(CacheTest.soloCachePullArgv(testName));
expect(fs.existsSync(cacheRoot), `expected cache directory to exist at ${cacheRoot}`).to.be.true;
await main(CacheTest.soloCacheListArgv(testName));
await main(CacheTest.soloCacheStatusArgv(testName));
await main(CacheTest.soloCacheClearArgv(testName));
expect(fs.existsSync(cacheRoot), `expected cache directory to be removed at ${cacheRoot}`).to.be.false;
}).timeout(Duration.ofMinutes(15).toMillis());
}
static pullAndVerifyArtifactsExist(options) {
const { testName, testCacheDirectory } = options;
it(`${testName}: cache pull creates archive artifacts`, async () => {
await main(CacheTest.soloCachePullArgv(testName));
const cacheRoot = PathEx.join(testCacheDirectory, 'cache');
expect(fs.existsSync(cacheRoot), `expected cache directory to exist at ${cacheRoot}`).to.be.true;
const imageDirectory = PathEx.join(cacheRoot, 'IMAGE');
const fallbackImageDirectory = PathEx.join(cacheRoot, 'image');
const artifactDirectory = [imageDirectory, fallbackImageDirectory].find((directory) => fs.existsSync(directory));
expect(artifactDirectory, 'expected image cache artifact directory to exist').to.not.equal(undefined);
const files = fs.readdirSync(artifactDirectory);
expect(files.length, 'expected at least one cached image artifact').to.be.greaterThan(0);
expect(files.some((fileName) => fileName.endsWith('.tar'))).to.be.true;
}).timeout(Duration.ofMinutes(15).toMillis());
}
static loadAfterNetworkDeploy(options) {
const { testName } = options;
it(`${testName}: cache load into cluster`, async () => {
await main(CacheTest.soloCachePullArgv(testName));
await main(CacheTest.soloCacheLoadArgv(testName));
}).timeout(Duration.ofMinutes(15).toMillis());
}
}
//# sourceMappingURL=cache-test.js.map