Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nagdahimanshu committed Oct 24, 2023
1 parent 3fd0955 commit 835a6f9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Binary file added test/unit/fixtures/data/snapshotDir/blockchain.db
Binary file not shown.
47 changes: 46 additions & 1 deletion test/unit/utils/path.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import { homedir } from 'os';
import { join } from 'path';

import { DEFAULT_LISK_CORE_PATH } from '../../../src/constants';
import { resolveAbsolutePath, verifyOutputPath } from '../../../src/utils/path';
import {
resolveAbsolutePath,
verifyOutputPath,
resolveSnapshotPath,
} from '../../../src/utils/path';

describe('Test resolveAbsolutePath method', () => {
it('should resolve absolute path when called with valid path which contains ~', async () => {
Expand Down Expand Up @@ -73,3 +77,44 @@ describe('Test verifyOutputPath method', () => {
expect(() => verifyOutputPath(outputPath)).not.toThrow();
});
});

describe('Test resolveSnapshotPath method', () => {
const dataDir = join(__dirname, '../../..', 'test/unit/fixtures/data');
const liskCoreV3DataPath = '~/.lisk/lisk-core/config/data';
const inputSnapshotPath = join(__dirname, '../../..', 'test/unit/fixtures/data/snapshotDir');

it('should return valid snapshot path when useSnapshot is false', async () => {
const useSnapshot = false;
const snapshotPath = await resolveSnapshotPath(
useSnapshot,
inputSnapshotPath,
dataDir,
liskCoreV3DataPath,
);
const expectedResult = '~/.lisk/lisk-core/config/data/data/backup';
expect(snapshotPath).toBe(expectedResult);
});

it('should return valid snapshot path when useSnapshot is true and snapshotPath is available', async () => {
const useSnapshot = true;
const snapshotPath = await resolveSnapshotPath(
useSnapshot,
inputSnapshotPath,
dataDir,
liskCoreV3DataPath,
);
expect(snapshotPath).toBe(inputSnapshotPath);
});

it('should return valid snapshot path when useSnapshot is true and snapshotPath ends with .tar,gz', async () => {
const useSnapshot = true;
const snapshotPath = await resolveSnapshotPath(
useSnapshot,
(undefined as unknown) as string,
dataDir,
liskCoreV3DataPath,
);
const expectedResult = join(dataDir, 'snapshotDir');
expect(snapshotPath).toBe(expectedResult);
});
});

0 comments on commit 835a6f9

Please sign in to comment.