Files
termos/test/core/commands/echo.test.ts
T

64 lines
1.7 KiB
TypeScript

import { descriptor as echo } from "@core/commands/echo";
import { createInitialShellState, type ShellState } from "@core/shell_state";
import type { UserInfo } from "@core/user_info";
import { buildTestFS, type FixtureNode } from "@tests/helpers/filesystems_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 users: Map<number, UserInfo> = new Map();
const user: UserInfo = {
name: "root",
uid: 0,
gid: 0,
group: [0],
home: 0,
};
users.set(0, user);
const state: ShellState = createInitialShellState(fs, users, user);
test("returns a Result of type success", () => {
const output = echo.fn(state, [], ["hello", "world"]);
const string = new TextDecoder().decode(output.result.stdout.toArray());
expect(output.result.type).toBe("success");
expect(output.result.exitCode).toBe(0);
expect(string).toBe("hello world");
});