feat(btrfs): add CLI and mock drivers with test utilities and interfaces #1

Merged
maxp merged 3 commits from feature/btrfs-driver into main 2025-10-12 15:02:46 +02:00
3 changed files with 18 additions and 0 deletions
Showing only changes of commit 369dfbe5db - Show all commits

View File

@@ -23,6 +23,7 @@ import {
createBtrfsTestVolume,
destroyBtrfsTestVolume,
disableQuota,
hasLoopDevices,
resetBtrfsTestVolume,
} from '../utils/test_volume.ts';
@@ -44,6 +45,11 @@ await configure({
],
});
if (!(await hasLoopDevices())) {
console.warn('Skipping BtrfsCliDriver tests: No loop devices available');
Deno.exit(0);
}
describe('BtrfsCliDriver', () => {
beforeAll(async () => {
vol = await createBtrfsTestVolume(512);

View File

@@ -4,6 +4,7 @@ export {
createBtrfsTestVolume,
destroyBtrfsTestVolume,
disableQuota,
hasLoopDevices,
resetBtrfsTestVolume,
} from './test_volume.ts';
export type { BtrfsTestVolume } from './test_volume.ts';

View File

@@ -113,3 +113,14 @@ export async function disableQuota(mountPoint: string): Promise<void> {
await run('sudo', ['btrfs', 'quota', 'disable', mountPoint]);
log.info(`[BTRFS] Quota disabled`);
}
/**
* Checks if the current system has loop devices available.
* Used to skip tests when running in environments without /dev/loop-control.
*/
export async function hasLoopDevices(): Promise<boolean> {
const { code } = await new Deno.Command('sh', {
args: ['-c', 'test -e /dev/loop-control && exit 0 || exit 1'],
}).output();
return code === 0;
}