@hashgraph/solo
Version:
An opinionated CLI tool to deploy and manage private Hedera Networks.
72 lines • 3.63 kB
JavaScript
// SPDX-License-Identifier: Apache-2.0
import { expect } from 'chai';
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 { ExportLogsResponse } from '../../../../../src/integration/kind/model/export-logs/export-logs-response.js';
describe('DefaultKindClient - exportLogs', () => {
let client;
let executionBuilderStub;
let executionStub;
beforeEach(() => {
client = new DefaultKindClient('/usr/local/bin/kind');
executionBuilderStub = sinon.createStubInstance(KindExecutionBuilder);
executionStub = sinon.createStubInstance(KindExecution);
// Set up the builder stub
executionBuilderStub.build.returns(executionStub);
sinon.stub(KindExecutionBuilder.prototype, 'build').returns(executionStub);
});
afterEach(() => {
sinon.restore();
});
it('should export logs and parse the response correctly', async () => {
const clusterName = 'test-cluster';
const exportPath = '/tmp/kind-logs-test-cluster-2025-07-10T12-34-56';
executionStub.responseAs.callsFake((responseClass) => {
const output = exportPath;
return Promise.resolve(new responseClass(output));
});
const result = await client.exportLogs(clusterName);
expect(result).to.be.instanceOf(ExportLogsResponse);
expect(result.exportPath).to.equal(exportPath);
});
it('should throw if responseAs throws', async () => {
executionStub.responseAs.rejects(new Error('export logs failed'));
try {
await client.exportLogs('test-cluster');
expect.fail('Expected error');
}
catch (error) {
expect(error.message).to.equal('export logs failed');
}
});
it('should pass cluster name to execution builder correctly', async () => {
const clusterName = 'options-test-cluster';
// Create spies to track method calls
const subcommandsSpy = sinon.spy(KindExecutionBuilder.prototype, 'subcommands');
const argumentSpy = sinon.spy(KindExecutionBuilder.prototype, 'argument');
await client.exportLogs(clusterName);
// Verify subcommands were called correctly
expect(subcommandsSpy.calledWith('export', 'logs')).to.be.true;
// Verify arguments were set correctly
expect(argumentSpy.calledWith('name', clusterName)).to.be.true;
});
it('should handle undefined cluster name', async () => {
// Create a spy for subcommands and argument methods
const subcommandsSpy = sinon.spy(KindExecutionBuilder.prototype, 'subcommands');
const argumentSpy = sinon.spy(KindExecutionBuilder.prototype, 'argument');
// Output with default 'kind' cluster name
const output = '/tmp/kind-logs-kind-2025-07-10T12-34-56';
executionStub.responseAs.callsFake((responseClass) => {
return Promise.resolve(new responseClass(output));
});
const result = await client.exportLogs();
// Verify subcommands were called correctly
expect(subcommandsSpy.calledWith('export', 'logs')).to.be.true;
// Should not set name argument when undefined
expect(argumentSpy.callCount).to.equal(0);
expect(result.exportPath).to.be.equal(output);
});
});
//# sourceMappingURL=export-logs.test.js.map