Skip to content

Commit

Permalink
fix: enhance filesystem metadata tests to validate system volume mark…
Browse files Browse the repository at this point in the history
…ings
  • Loading branch information
mceachen committed Jan 1, 2025
1 parent 5790967 commit 85d23a8
Showing 1 changed file with 39 additions and 9 deletions.
48 changes: 39 additions & 9 deletions src/mount_point.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { jest } from "@jest/globals";
import { getVolumeMountPoints } from "..";
import { times, uniq } from "./array.js";
import { MountPoint } from "./mount_point.js";
import { isLinux, isWindows } from "./platform.js";
import { isWindows } from "./platform.js";
import { sortByLocale } from "./string.js";

describe("Filesystem Metadata", () => {
Expand Down Expand Up @@ -48,15 +48,45 @@ describe("Filesystem Metadata", () => {
});

if (!isWindows) {
it("should exclude pseudo filesystems", async () => {
const mountPoints = await getVolumeMountPoints();
const pseudoFS = isLinux
? ["/proc", "/sys", "/dev/pts"]
: ["/dev", "/dev/fd"];

pseudoFS.forEach((fs) => {
expect(mountPoints).not.toContain(fs);
it("should mark filesystems properly as a system volume", async () => {
const allMountPoints = await getVolumeMountPoints({
includeSystemVolumes: true,
});
const nonSystemMountPoints = await getVolumeMountPoints();
console.log({ allMountPoints, nonSystemMountPoints });
const foundSystemVolumes = [];
const mismarkedSystemVolumes = [];
const systemVolumesInDefaultList = nonSystemMountPoints.filter(
(ea) => ea.isSystemVolume,
);
// this is a non-exhaustive list of filesystems to validate that at
// least one of these both exists and is marked as a system volume:
for (const mountPoint of [
"/boot",
"/proc",
"/sys",
"/dev/shm",
"/snap",
"/run/lock",
"/System/Volumes/VM",
]) {
const fs = allMountPoints.find((ea) => ea.mountPoint === mountPoint);
if (fs != null) {
if (fs.isSystemVolume) {
foundSystemVolumes.push(fs);
} else {
mismarkedSystemVolumes.push(fs);
}
}
systemVolumesInDefaultList.push(
...systemVolumesInDefaultList.filter(
(ea) => ea.mountPoint === mountPoint,
),
);
}
expect(foundSystemVolumes).not.toEqual([]);
expect(mismarkedSystemVolumes).toEqual([]);
expect(systemVolumesInDefaultList).toEqual([]);
});
}

Expand Down

0 comments on commit 85d23a8

Please sign in to comment.