Skip to content

Commit

Permalink
refactor(cli): reorganizing tests/ directory
Browse files Browse the repository at this point in the history
  • Loading branch information
endersonmaia committed Oct 23, 2024
1 parent 29ba930 commit 486380e
Show file tree
Hide file tree
Showing 29 changed files with 75 additions and 30 deletions.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 486380e

Please sign in to comment.