@hashgraph/solo
Version:
An opinionated CLI tool to deploy and manage private Hedera Networks.
123 lines • 6.47 kB
JavaScript
// SPDX-License-Identifier: Apache-2.0
import 'sinon-chai';
import { expect } from 'chai';
import { describe, it, beforeEach, afterEach } from 'mocha';
import sinon from 'sinon';
import { DefaultKindClient } from '../../../../../src/integration/kind/impl/default-kind-client.js';
import { KindExecutionBuilder } from '../../../../../src/integration/kind/execution/kind-execution-builder.js';
import { KindExecution } from '../../../../../src/integration/kind/execution/kind-execution.js';
import { LoadImageArchiveResponse } from '../../../../../src/integration/kind/model/load-image-archive/load-image-archive-response.js';
import { LoadImageArchiveOptions } from '../../../../../src/integration/kind/model/load-image-archive/load-image-archive-options.js';
describe('DefaultKindClient.loadImageArchive', () => {
let client;
let executionStub;
let builderArguments;
let builderSubcommands;
let builderPositionals;
let buildStub;
let callStub;
beforeEach(() => {
client = new DefaultKindClient('/usr/local/bin/kind');
executionStub = sinon.createStubInstance(KindExecution);
builderArguments = new Map();
builderSubcommands = [];
builderPositionals = [];
callStub = executionStub.call;
buildStub = sinon.stub(KindExecutionBuilder.prototype, 'build').returns(executionStub);
sinon.stub(KindExecutionBuilder.prototype, 'subcommands').callsFake(function (...commands) {
builderSubcommands.push(...commands);
return this;
});
sinon.stub(KindExecutionBuilder.prototype, 'argument').callsFake(function (name, value) {
builderArguments.set(name, value);
return this;
});
sinon.stub(KindExecutionBuilder.prototype, 'positional').callsFake(function (value) {
builderPositionals.push(value);
return this;
});
});
afterEach(() => {
sinon.restore();
});
it('should call the correct subcommands when loading an image archive', async () => {
const archivePath = 'test-archive.tar';
callStub.resolves(new LoadImageArchiveResponse());
const result = await client.loadImageArchive(archivePath);
expect(result).to.be.instanceOf(LoadImageArchiveResponse);
expect(builderSubcommands).to.include('load');
expect(builderSubcommands).to.include('image-archive');
expect(builderPositionals).to.include(archivePath);
expect(buildStub).to.have.been.calledOnce;
expect(callStub).to.have.been.calledOnce;
});
it('should handle empty image name gracefully', async () => {
callStub.resolves(new LoadImageArchiveResponse());
const result = await client.loadImageArchive('');
expect(result).to.be.instanceOf(LoadImageArchiveResponse);
expect(builderArguments.get('name')).to.equal(undefined);
});
it('should throw if call rejects', async () => {
callStub.rejects(new Error('Failed to load image archive'));
await expect(client.loadImageArchive('test-archive-fail.tar')).to.be.rejectedWith('Failed to load image archive');
});
it('should pass cluster name from options parameter', async () => {
const archivePath = 'test-archive.tar';
const clusterName = 'custom-cluster';
const options = new LoadImageArchiveOptions(archivePath, clusterName);
callStub.resolves(new LoadImageArchiveResponse());
await client.loadImageArchive(archivePath, options);
expect(builderPositionals).to.include(archivePath);
expect(builderArguments.get('name')).to.equal(clusterName);
});
it('should pass nodes parameter when provided in options', async () => {
const archivePath = 'test-archive.tar';
const nodes = 'control-plane,worker1,worker2';
const options = new LoadImageArchiveOptions(archivePath, undefined, nodes);
callStub.resolves(new LoadImageArchiveResponse());
await client.loadImageArchive(archivePath, options);
expect(builderPositionals).to.include(archivePath);
expect(builderArguments.get('nodes')).to.equal(nodes);
});
it('should handle both cluster name and nodes parameters', async () => {
const archivePath = 'test-archive.tar';
const clusterName = 'custom-cluster';
const nodes = 'worker1,worker2';
const options = new LoadImageArchiveOptions(archivePath, clusterName, nodes);
callStub.resolves(new LoadImageArchiveResponse());
await client.loadImageArchive(archivePath, options);
expect(builderPositionals).to.include(archivePath);
expect(builderArguments.get('name')).to.equal(clusterName);
expect(builderArguments.get('nodes')).to.equal(nodes);
});
it('should handle archive paths with special characters', async () => {
const archivePath = '/path/to/archive with spaces.tar';
callStub.resolves(new LoadImageArchiveResponse());
const result = await client.loadImageArchive(archivePath);
expect(result).to.be.instanceOf(LoadImageArchiveResponse);
expect(builderPositionals).to.include(archivePath);
expect(callStub).to.have.been.calledOnce;
});
it('should handle malformed output format gracefully', async () => {
callStub.resolves(new LoadImageArchiveResponse());
const result = await client.loadImageArchive('test-archive.tar');
expect(result).to.be.instanceOf(LoadImageArchiveResponse);
});
it('should handle relative paths for archive files', async () => {
const archivePath = './relative/path/archive.tar';
callStub.resolves(new LoadImageArchiveResponse());
const result = await client.loadImageArchive(archivePath);
expect(result).to.be.instanceOf(LoadImageArchiveResponse);
expect(builderPositionals).to.include(archivePath);
expect(callStub).to.have.been.calledOnce;
});
it('should handle absolute paths for archive files', async () => {
const archivePath = '/absolute/path/archive.tar';
callStub.resolves(new LoadImageArchiveResponse());
const result = await client.loadImageArchive(archivePath);
expect(result).to.be.instanceOf(LoadImageArchiveResponse);
expect(builderPositionals).to.include(archivePath);
expect(callStub).to.have.been.calledOnce;
});
});
//# sourceMappingURL=load-image-archive.test.js.map