Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(cli): reorganizing tests/ directory #115

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from "fs-extra";
import path from "path";
import { describe, expect } from "vitest";
import { build } from "../../src/builder/directory";
import { DEFAULT_SDK, DirectoryDriveConfig } from "../../src/config";
import { build } from "../../../src/builder/directory";
import { DEFAULT_SDK, DirectoryDriveConfig } from "../../../src/config";
import { tmpdirTest } from "./tmpdirTest";

describe("when building with the directory builder", () => {
Expand Down Expand Up @@ -67,7 +67,7 @@ describe("when building with the directory builder", () => {
const destination = tmpdir;
const drive: DirectoryDriveConfig = {
builder: "directory",
directory: path.join(__dirname, "data", "sample1"),
directory: path.join(__dirname, "fixtures", "sample1"),
extraSize: 0,
format: "ext2",
};
Expand All @@ -84,7 +84,7 @@ describe("when building with the directory builder", () => {
const destination = tmpdir;
const drive: DirectoryDriveConfig = {
builder: "directory",
directory: path.join(__dirname, "data", "sample1"),
directory: path.join(__dirname, "fixtures", "sample1"),
extraSize: 0,
format: "sqfs",
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import fs from "fs-extra";
import { beforeEach } from "node:test";
import path from "path";
import { describe, expect } from "vitest";
import { build } from "../../src/builder/docker";
import { DEFAULT_SDK, DockerDriveConfig } from "../../src/config";
import { build } from "../../../src/builder/docker";
import { DEFAULT_SDK, DockerDriveConfig } from "../../../src/config";
import { tmpdirTest } from "./tmpdirTest";

describe("when building with the docker builder", () => {
Expand Down Expand Up @@ -52,8 +52,8 @@ describe("when building with the docker builder", () => {
const destination = tmpdir;
const drive: DockerDriveConfig = {
builder: "docker",
context: path.join(__dirname, "data"),
dockerfile: path.join(__dirname, "data", "Dockerfile"),
context: path.join(__dirname, "fixtures"),
dockerfile: path.join(__dirname, "fixtures", "Dockerfile"),
extraSize: 0,
format: "ext2",
tags: [],
Expand All @@ -71,8 +71,8 @@ describe("when building with the docker builder", () => {
const destination = tmpdir;
const drive: DockerDriveConfig = {
builder: "docker",
context: path.join(__dirname, "data"),
dockerfile: path.join(__dirname, "data", "Dockerfile"),
context: path.join(__dirname, "fixtures"),
dockerfile: path.join(__dirname, "fixtures", "Dockerfile"),
extraSize: 0,
format: "ext2",
tags: [],
Expand All @@ -89,8 +89,8 @@ describe("when building with the docker builder", () => {
const destination = tmpdir;
const drive: DockerDriveConfig = {
builder: "docker",
context: path.join(__dirname, "data"),
dockerfile: path.join(__dirname, "data", "Dockerfile"),
context: path.join(__dirname, "fixtures"),
dockerfile: path.join(__dirname, "fixtures", "Dockerfile"),
extraSize: 0,
format: "sqfs",
tags: [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from "fs-extra";
import path from "path";
import { describe, expect } from "vitest";
import { build } from "../../src/builder/empty";
import { DEFAULT_SDK, EmptyDriveConfig } from "../../src/config";
import { build } from "../../../src/builder/empty";
import { DEFAULT_SDK, EmptyDriveConfig } from "../../../src/config";
import { tmpdirTest } from "./tmpdirTest";

describe("when building with the empty builder", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from "fs-extra";
import path from "path";
import { describe, expect } from "vitest";
import { build } from "../../src/builder/none";
import { ExistingDriveConfig } from "../../src/config";
import { build } from "../../../src/builder/none";
import { ExistingDriveConfig } from "../../../src/config";
import { tmpdirTest } from "./tmpdirTest";

describe("when building with the none builder", () => {
Expand All @@ -20,7 +20,7 @@ describe("when building with the none builder", () => {

tmpdirTest("should just copy an existing drive", async ({ tmpdir }) => {
const destination = tmpdir;
const filename = path.join(__dirname, "data", "data.ext2");
const filename = path.join(__dirname, "fixtures", "data.ext2");
const drive: ExistingDriveConfig = {
builder: "none",
filename,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from "fs-extra";
import path from "path";
import { describe, expect } from "vitest";
import { build } from "../../src/builder/tar";
import { DEFAULT_SDK, TarDriveConfig } from "../../src/config";
import { build } from "../../../src/builder/tar";
import { DEFAULT_SDK, TarDriveConfig } from "../../../src/config";
import { tmpdirTest } from "./tmpdirTest";

describe("when building with the tar builder", () => {
Expand All @@ -25,7 +25,7 @@ describe("when building with the tar builder", () => {
const destination = tmpdir;
const drive: TarDriveConfig = {
builder: "tar",
filename: path.join(__dirname, "data", "data.tar"),
filename: path.join(__dirname, "fixtures", "data.tar"),
extraSize: 0,
format: "ext2",
};
Expand All @@ -39,7 +39,7 @@ describe("when building with the tar builder", () => {
const destination = tmpdir;
const drive: TarDriveConfig = {
builder: "tar",
filename: path.join(__dirname, "data", "data.tar"),
filename: path.join(__dirname, "fixtures", "data.tar"),
extraSize: 0,
format: "sqfs",
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { satisfies } from "semver";
import { describe, expect, it } from "vitest";
import { DEFAULT_SDK } from "../../src/config.js";
import { cartesiMachine } from "../../src/exec/index.js";
import { DEFAULT_SDK } from "../../../src/config.js";
import { cartesiMachine } from "../../../src/exec/index.js";

describe("cartesi-machine", () => {
it("should report version", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { satisfies } from "semver";
import { describe, expect, it } from "vitest";
import { DEFAULT_SDK } from "../../src/config.js";
import { crane } from "../../src/exec/index.js";
import { DEFAULT_SDK } from "../../../src/config.js";
import { crane } from "../../../src/exec/index.js";

describe("crane", () => {
it("should report version", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { satisfies } from "semver";
import { describe, expect, it } from "vitest";
import { DEFAULT_SDK } from "../../src/config.js";
import { genext2fs } from "../../src/exec/index.js";
import { DEFAULT_SDK } from "../../../src/config.js";
import { genext2fs } from "../../../src/exec/index.js";

describe("genext2fs", () => {
it("should report version", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { satisfies } from "semver";
import { describe, expect, it } from "vitest";
import { DEFAULT_SDK } from "../../src/config.js";
import { mksquashfs } from "../../src/exec/index.js";
import { DEFAULT_SDK } from "../../../src/config.js";
import { mksquashfs } from "../../../src/exec/index.js";

describe("mksquashfs", () => {
it("should report version", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as fs from "fs";
import * as path from "path";
import { describe, expect, it } from "vitest";
import {
defaultConfig,
Expand All @@ -11,7 +13,50 @@ import {
InvalidStringValueError,
parse,
RequiredFieldError,
} from "../src/config.js";
} from "../../src/config.js";

const loadDriveConfig = (driveName: string) => {
const filePath = path.join(
__dirname,
"config",
"fixtures",
"drives",
`${driveName}.toml`,
);
return fs.readFileSync(filePath, "utf-8");
};

describe("when parsing only drive config files", () => {
it("should pass with a basic drive config", () => {
const basic = loadDriveConfig("basic");
expect(() => parse(basic)).not.toThrow();
});

it("should pass with a data drive config", () => {
const basic = loadDriveConfig("data");
expect(() => parse(basic)).not.toThrow();
});

it("should pass with an empty drive config", () => {
const basic = loadDriveConfig("empty");
expect(() => parse(basic)).not.toThrow();
});

it("should pass with a none drive config", () => {
const basic = loadDriveConfig("none");
expect(() => parse(basic)).not.toThrow();
});

it("should pass with a rives config", () => {
const basic = loadDriveConfig("rives");
expect(() => parse(basic)).not.toThrow();
});

it("should pass with a tar drive config", () => {
const basic = loadDriveConfig("rives");
expect(() => parse(basic)).not.toThrow();
});
});

describe("when parsing a cartesi.toml config", () => {
it("should load the default config when file is empty", () => {
Expand Down
Loading