@hashgraph/solo
Version:
An opinionated CLI tool to deploy and manage private Hedera Networks.
49 lines • 2.04 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 fs from 'node:fs/promises';
import { DefaultCacheHealthInspector } from '../../../../src/integration/cache/impl/default-cache-health-inspector.js';
describe('DefaultCacheHealthInspector', () => {
let inspector;
let accessStub;
let statStub;
beforeEach(() => {
inspector = new DefaultCacheHealthInspector();
accessStub = sinon.stub(fs, 'access');
statStub = sinon.stub(fs, 'stat');
});
afterEach(() => sinon.restore());
describe('exists', () => {
it('should return true when access succeeds', async () => {
accessStub.resolves();
expect(await inspector.exists('/tmp/file')).to.be.true;
});
it('should return false when access fails', async () => {
accessStub.rejects(new Error('missing'));
expect(await inspector.exists('/tmp/file')).to.be.false;
});
});
describe('getSize', () => {
it('should return stat size', async () => {
statStub.resolves({ size: 1234 });
expect(await inspector.getSize('/tmp/file')).to.equal(1234);
});
});
describe('filterExisting', () => {
it('should return only existing paths', async () => {
accessStub.onFirstCall().resolves();
accessStub.onSecondCall().rejects(new Error('missing'));
accessStub.onThirdCall().resolves();
const result = await inspector.filterExisting(['/a', '/b', '/c']);
expect(result).to.deep.equal(['/a', '/c']);
});
it('should return empty array when none exist', async () => {
accessStub.rejects(new Error('missing'));
const result = await inspector.filterExisting(['/a', '/b']);
expect(result).to.deep.equal([]);
});
});
});
//# sourceMappingURL=default-cache-health-inspector.test.js.map