Path: blob/master/src/packages/file-server/btrfs/test/filesystem.test.ts
1543 views
import { before, after, fs } from "./setup";1import { isValidUUID } from "@cocalc/util/misc";23beforeAll(before);45describe("some basic tests", () => {6it("gets basic info", async () => {7const info = await fs.info();8expect(info).not.toEqual(null);9expect(info.Name).toBe("<FS_TREE>");10expect(isValidUUID(info.UUID)).toBe(true);11const creation = new Date(info["Creation time"]);12expect(Math.abs(creation.valueOf() - Date.now())).toBeLessThan(15000);13expect(info["Snapshot(s)"]).toBe("");14});1516it("lists the subvolumes (there are none)", async () => {17expect(await fs.subvolumes.list()).toEqual([]);18});19});2021describe("operations with subvolumes", () => {22it("can't use a reserved subvolume name", async () => {23expect(async () => {24await fs.subvolumes.get("bup");25}).rejects.toThrow("is reserved");26});2728it("creates a subvolume", async () => {29const vol = await fs.subvolumes.get("cocalc");30expect(vol.name).toBe("cocalc");31// it has no snapshots32expect(await vol.snapshots.ls()).toEqual([]);33});3435it("our subvolume is in the list", async () => {36expect(await fs.subvolumes.list()).toEqual(["cocalc"]);37});3839it("create another two subvolumes", async () => {40await fs.subvolumes.get("sagemath");41await fs.subvolumes.get("a-math");42// list is sorted:43expect(await fs.subvolumes.list()).toEqual([44"a-math",45"cocalc",46"sagemath",47]);48});4950it("delete a subvolume", async () => {51await fs.subvolumes.delete("a-math");52expect(await fs.subvolumes.list()).toEqual(["cocalc", "sagemath"]);53});5455it("clone a subvolume", async () => {56await fs.subvolumes.clone("sagemath", "cython");57expect(await fs.subvolumes.list()).toEqual([58"cocalc",59"cython",60"sagemath",61]);62});6364it("rsync from one volume to another", async () => {65await fs.subvolumes.rsync({ src: "sagemath", target: "cython" });66});6768it("rsync an actual file", async () => {69const sagemath = await fs.subvolumes.get("sagemath");70const cython = await fs.subvolumes.get("cython");71await sagemath.fs.writeFile("README.md", "hi");72await fs.subvolumes.rsync({ src: "sagemath", target: "cython" });73const copy = await cython.fs.readFile("README.md", "utf8");74expect(copy).toEqual("hi");75});7677it("clone a subvolume with contents", async () => {78await fs.subvolumes.clone("cython", "pyrex");79const pyrex = await fs.subvolumes.get("pyrex");80const clone = await pyrex.fs.readFile("README.md", "utf8");81expect(clone).toEqual("hi");82});83});8485describe("clone of a subvolume with snapshots should have no snapshots", () => {86it("creates a subvolume, a file, and a snapshot", async () => {87const x = await fs.subvolumes.get("my-volume");88await x.fs.writeFile("abc.txt", "hi");89await x.snapshots.create("my-snap");90});9192it("clones my-volume", async () => {93await fs.subvolumes.clone("my-volume", "my-clone");94});9596it("clone has no snapshots", async () => {97const clone = await fs.subvolumes.get("my-clone");98expect(await clone.fs.readFile("abc.txt", "utf8")).toEqual("hi");99expect(await clone.snapshots.ls()).toEqual([]);100await clone.snapshots.create("my-clone-snap");101});102});103104afterAll(after);105106107