Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/file-server/btrfs/test/filesystem.test.ts
1543 views
1
import { before, after, fs } from "./setup";
2
import { isValidUUID } from "@cocalc/util/misc";
3
4
beforeAll(before);
5
6
describe("some basic tests", () => {
7
it("gets basic info", async () => {
8
const info = await fs.info();
9
expect(info).not.toEqual(null);
10
expect(info.Name).toBe("<FS_TREE>");
11
expect(isValidUUID(info.UUID)).toBe(true);
12
const creation = new Date(info["Creation time"]);
13
expect(Math.abs(creation.valueOf() - Date.now())).toBeLessThan(15000);
14
expect(info["Snapshot(s)"]).toBe("");
15
});
16
17
it("lists the subvolumes (there are none)", async () => {
18
expect(await fs.subvolumes.list()).toEqual([]);
19
});
20
});
21
22
describe("operations with subvolumes", () => {
23
it("can't use a reserved subvolume name", async () => {
24
expect(async () => {
25
await fs.subvolumes.get("bup");
26
}).rejects.toThrow("is reserved");
27
});
28
29
it("creates a subvolume", async () => {
30
const vol = await fs.subvolumes.get("cocalc");
31
expect(vol.name).toBe("cocalc");
32
// it has no snapshots
33
expect(await vol.snapshots.ls()).toEqual([]);
34
});
35
36
it("our subvolume is in the list", async () => {
37
expect(await fs.subvolumes.list()).toEqual(["cocalc"]);
38
});
39
40
it("create another two subvolumes", async () => {
41
await fs.subvolumes.get("sagemath");
42
await fs.subvolumes.get("a-math");
43
// list is sorted:
44
expect(await fs.subvolumes.list()).toEqual([
45
"a-math",
46
"cocalc",
47
"sagemath",
48
]);
49
});
50
51
it("delete a subvolume", async () => {
52
await fs.subvolumes.delete("a-math");
53
expect(await fs.subvolumes.list()).toEqual(["cocalc", "sagemath"]);
54
});
55
56
it("clone a subvolume", async () => {
57
await fs.subvolumes.clone("sagemath", "cython");
58
expect(await fs.subvolumes.list()).toEqual([
59
"cocalc",
60
"cython",
61
"sagemath",
62
]);
63
});
64
65
it("rsync from one volume to another", async () => {
66
await fs.subvolumes.rsync({ src: "sagemath", target: "cython" });
67
});
68
69
it("rsync an actual file", async () => {
70
const sagemath = await fs.subvolumes.get("sagemath");
71
const cython = await fs.subvolumes.get("cython");
72
await sagemath.fs.writeFile("README.md", "hi");
73
await fs.subvolumes.rsync({ src: "sagemath", target: "cython" });
74
const copy = await cython.fs.readFile("README.md", "utf8");
75
expect(copy).toEqual("hi");
76
});
77
78
it("clone a subvolume with contents", async () => {
79
await fs.subvolumes.clone("cython", "pyrex");
80
const pyrex = await fs.subvolumes.get("pyrex");
81
const clone = await pyrex.fs.readFile("README.md", "utf8");
82
expect(clone).toEqual("hi");
83
});
84
});
85
86
describe("clone of a subvolume with snapshots should have no snapshots", () => {
87
it("creates a subvolume, a file, and a snapshot", async () => {
88
const x = await fs.subvolumes.get("my-volume");
89
await x.fs.writeFile("abc.txt", "hi");
90
await x.snapshots.create("my-snap");
91
});
92
93
it("clones my-volume", async () => {
94
await fs.subvolumes.clone("my-volume", "my-clone");
95
});
96
97
it("clone has no snapshots", async () => {
98
const clone = await fs.subvolumes.get("my-clone");
99
expect(await clone.fs.readFile("abc.txt", "utf8")).toEqual("hi");
100
expect(await clone.snapshots.ls()).toEqual([]);
101
await clone.snapshots.create("my-clone-snap");
102
});
103
});
104
105
afterAll(after);
106
107