- Old tests fixed
- Added a static Fixuture class for test mockups
This commit is contained in:
@@ -1,48 +1,10 @@
|
||||
import type { CommandIO } from "@core/command_io";
|
||||
import { descriptor as echo } from "@core/commands/echo";
|
||||
import type { ResultSuccess } from "@core/result";
|
||||
import type { UserInfo } from "@core/session_manager";
|
||||
import { createInitialShellState, type ShellState } from "@core/shell_state";
|
||||
import { buildTestFS, type FixtureNode } from "@tests/helpers/filesystems_fixture";
|
||||
import { type ShellState } from "@core/shell_state";
|
||||
import { Fixture } from "@tests/helpers/state_fixture";
|
||||
import { expect, test } from "vitest";
|
||||
|
||||
const testTree: FixtureNode = {
|
||||
inode: 0,
|
||||
name: "root",
|
||||
type: "Dir",
|
||||
children: [
|
||||
{
|
||||
inode: 1,
|
||||
name: "hello.txt",
|
||||
type: "File",
|
||||
content: "Goodbye World!",
|
||||
children: [],
|
||||
},
|
||||
{
|
||||
inode: 2,
|
||||
name: "sub",
|
||||
type: "Dir",
|
||||
children: [
|
||||
{
|
||||
inode: 3,
|
||||
name: "world.txt",
|
||||
type: "File",
|
||||
content: "Goodbye!",
|
||||
children: [],
|
||||
},
|
||||
{
|
||||
inode: 4,
|
||||
name: "bye",
|
||||
type: "Dir",
|
||||
children: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const fs = buildTestFS(testTree);
|
||||
|
||||
const stdout: Uint8Array[] = [];
|
||||
const stderr: Uint8Array[] = [];
|
||||
|
||||
@@ -58,17 +20,7 @@ const io: CommandIO = {
|
||||
},
|
||||
};
|
||||
|
||||
const users: Map<number, UserInfo> = new Map();
|
||||
const user: UserInfo = {
|
||||
username: "root",
|
||||
uid: 0,
|
||||
gid: 0,
|
||||
group: [0],
|
||||
home: 0,
|
||||
};
|
||||
users.set(0, user);
|
||||
|
||||
const state: ShellState = createInitialShellState(fs, users, user);
|
||||
const state: ShellState = Fixture.State;
|
||||
|
||||
test("returns a Result of type success", async () => {
|
||||
const output = await echo.fn(io, state, [], ["hello", "world"]);
|
||||
@@ -76,5 +28,6 @@ test("returns a Result of type success", async () => {
|
||||
|
||||
expect(output.result.type).toBe("success");
|
||||
expect((output.result as ResultSuccess).exitCode).toBe(0);
|
||||
expect(string).toBe("hello world");
|
||||
// Fix: added a newline character
|
||||
expect(string).toEqual("hello world\n");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user