diff --git a/src/core/filesystem/filesystem.ts b/src/core/filesystem/filesystem.ts index c660dc3..c5b1772 100644 --- a/src/core/filesystem/filesystem.ts +++ b/src/core/filesystem/filesystem.ts @@ -272,7 +272,6 @@ export class FileSystem { } const time: number = Date.now(); - // Later initialize descendants with tree traversal algo const descendants: number[] = traverseTree(this, inode); const map: Map = new Map(this._OverlayFS); diff --git a/test/core/filesystem/filesystem.test.ts b/test/core/filesystem/filesystem.test.ts index 3ea6f0b..ee2edf6 100644 --- a/test/core/filesystem/filesystem.test.ts +++ b/test/core/filesystem/filesystem.test.ts @@ -13,7 +13,7 @@ const testTree: FixtureNode = { inode: 1, name: "hello.txt", type: "File", - content: "Hello, world!", + content: "Goodbye World!", children: [], }, { @@ -193,3 +193,67 @@ describe("deleteNode", () => { expect(fs.Overlay.size).toBe(0); }); }); + +describe("modifyNode", () => { + it("modifies content", () => { + const changes = { + content: createImmutableBuffer(new TextEncoder().encode("Hello, World!")), + }; + + const newFS = fs.modifyNode(1, changes); + const node = newFS.getNode(1) as FileNode; + + expect(new TextDecoder().decode(node.content.toArray())).toBe("Hello, World!"); + expect(newFS.Overlay.size).toBe(1); + }); + + it("modifies mode", () => { + const changes = { + mode: 0o222, + }; + + const newFS = fs.modifyNode(1, changes); + const node = newFS.getNode(1) as FileNode; + + expect(node.mode).toEqual(0o222); + expect(newFS.Overlay.size).toBe(1); + }); + + it("modifies owner and group", () => { + const changes = { + owner: 1, + group: 2, + }; + + const newFS = fs.modifyNode(1, changes); + const node = newFS.getNode(1) as FileNode; + + expect(node.owner).toBe(1); + expect(node.group).toBe(2); + expect(newFS.Overlay.size).toBe(1); + }); + + it("calls modify node with empty changes", () => { + const changes = {}; + + const newFS = fs.modifyNode(1, changes); + const node = newFS.getNode(1) as FileNode; + const oldNode = fs.getNode(1) as FileNode; + + expect(node.content).toEqual(oldNode.content); + expect(node.mode).toEqual(oldNode.mode); + expect(node.owner).toEqual(oldNode.owner); + expect(node.group).toEqual(oldNode.group); + expect(node.content).toEqual(oldNode.content); + expect(node.mtime).toEqual(oldNode.mtime); + }); + + it("fails", () => { + const changes = { + owner: 1, + group: 2, + }; + + expect(() => fs.modifyNode(999, changes)).toThrow(); + }); +});