- Old tests fixed
- Added a static Fixuture class for test mockups
This commit is contained in:
@@ -1,59 +1,12 @@
|
||||
import type { UserInfo } from "@core/session_manager";
|
||||
import { createInitialShellState, type ShellState } from "@core/shell_state";
|
||||
import type { ResultError } from "@core/result";
|
||||
import { type ShellState } from "@core/shell_state";
|
||||
import { SIGNAL_MAP } from "@core/signal";
|
||||
import type { SignalTerminationError } from "@core/util/errors";
|
||||
import { Shell } from "@shell/shell";
|
||||
import { buildTestFS, type FixtureNode } from "@tests/helpers/filesystems_fixture";
|
||||
import { test } from "vitest";
|
||||
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 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 () => {
|
||||
await Shell.init(state);
|
||||
@@ -61,10 +14,14 @@ test("returns a Result of type success", async () => {
|
||||
let result;
|
||||
|
||||
Shell.Instance?.on("result", payload => {
|
||||
const decoder = new TextDecoder();
|
||||
console.log(decoder.decode(payload.result.stdout.toArray()));
|
||||
console.log(payload);
|
||||
//const decoder = new TextDecoder();
|
||||
//console.log(decoder.decode(payload.result.stdout.toArray()));
|
||||
//console.log(payload);
|
||||
result = payload.result;
|
||||
|
||||
expect(result.type).toBe("error");
|
||||
expect((result as ResultError<SignalTerminationError>).error.exitCode).toEqual(130);
|
||||
expect((result as ResultError<SignalTerminationError>).error.signalNumber).toEqual(SIGNAL_MAP.SIGINT);
|
||||
});
|
||||
|
||||
await Shell.Instance?.execute("async");
|
||||
|
||||
Reference in New Issue
Block a user