@hashgraph/solo
Version:
An opinionated CLI tool to deploy and manage private Hedera Networks.
62 lines • 2.88 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 { FileSystemCacheCatalogStore } from '../../../../src/integration/cache/impl/file-system-cache-catalog-store.js';
import { PathEx } from '../../../../src/business/utils/path-ex.js';
import { CacheArtifactEnum } from '../../../../src/integration/cache/enums/cache-artifact-enum.js';
describe('FileSystemCacheCatalogStore', () => {
let store;
let mkdirStub;
let writeFileStub;
let readFileStub;
let accessStub;
let rmStub;
const homePath = '/home/test';
const baseDirectory = PathEx.join(homePath, 'cache');
const catalogPath = PathEx.join(baseDirectory, 'cache-catalog.json');
beforeEach(() => {
store = new FileSystemCacheCatalogStore(homePath);
mkdirStub = sinon.stub(fs, 'mkdir');
writeFileStub = sinon.stub(fs, 'writeFile');
readFileStub = sinon.stub(fs, 'readFile');
accessStub = sinon.stub(fs, 'access');
rmStub = sinon.stub(fs, 'rm');
});
afterEach(() => sinon.restore());
it('should save catalog to cache-catalog.json', async () => {
const catalog = { items: [{ id: '1' }] };
await store.save(catalog);
expect(mkdirStub).to.have.been.calledOnceWith(baseDirectory, { recursive: true });
expect(writeFileStub).to.have.been.calledOnceWith(catalogPath, JSON.stringify(catalog, undefined, 2));
});
it('should load catalog from cache-catalog.json', async () => {
readFileStub.resolves('{"items":[{"id":"1"}]}');
const result = await store.load();
expect(readFileStub).to.have.been.calledOnceWith(catalogPath, 'utf8');
expect(result).to.deep.equal({ items: [{ id: '1' }] });
});
it('should return true from exists when file is accessible', async () => {
accessStub.resolves();
expect(await store.exists()).to.be.true;
});
it('should return false from exists when file is not accessible', async () => {
accessStub.rejects(new Error('missing'));
expect(await store.exists()).to.be.false;
});
it('should clear cache directory', async () => {
await store.clear();
expect(rmStub).to.have.been.calledOnceWith(baseDirectory, { recursive: true, force: true });
});
it('should resolve safe artifact path', () => {
const target = {
name: 'ghcr.io/hashgraph/solo:test',
version: '1.2.3',
};
const result = store.resolvePath(target, CacheArtifactEnum.IMAGE);
expect(result).to.equal(PathEx.join(baseDirectory, CacheArtifactEnum.IMAGE, 'ghcr.io__hashgraph__solo__test__1.2.3.tar'));
});
});
//# sourceMappingURL=file-system-cache-catalog-store.test.js.map