-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! feat(cli): build based on configuration
integration tests
- Loading branch information
Showing
16 changed files
with
7,695 additions
and
6,023 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ node_modules | |
oclif.manifest.json | ||
src/contracts.ts | ||
src/graphql/ | ||
test/builder/output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,7 @@ export const build = async ( | |
cwd: destination, | ||
image: sdkImage, | ||
}); | ||
break; | ||
} | ||
} | ||
} finally { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FROM --platform=linux/riscv64 ubuntu:22.04 | ||
ADD ./file1 . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FROM scratch | ||
ADD ./file1 . |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lorem ipsum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lorem ipsum lorem ipsum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import fs from "fs-extra"; | ||
import path from "path"; | ||
import { afterAll, describe, expect, it } from "vitest"; | ||
import { build } from "../../src/builder/directory"; | ||
import { DirectoryDriveConfig } from "../../src/config"; | ||
|
||
describe("directory_builder", () => { | ||
const image = "cartesi/sdk:0.11.0"; | ||
|
||
it("non-existent directory", async ({ task }) => { | ||
const destination = path.join(__dirname, "output", task.suite!.name); | ||
const drive: DirectoryDriveConfig = { | ||
builder: "directory", | ||
directory: path.join(__dirname, "data", "invalid"), | ||
extraSize: 0, | ||
format: "ext2", | ||
}; | ||
await expect(build(task.id, drive, image, destination)).rejects.toThrow( | ||
"no such file or directory", | ||
); | ||
}); | ||
|
||
it("empty directory", async ({ task }) => { | ||
const destination = path.join(__dirname, "output", task.suite!.name); | ||
const drive: DirectoryDriveConfig = { | ||
builder: "directory", | ||
directory: path.join(__dirname, "data", "empty"), | ||
extraSize: 0, | ||
format: "ext2", | ||
}; | ||
await expect(build(task.id, drive, image, destination)).rejects.toThrow( | ||
Check failure on line 31 in apps/cli/test/builder/diretory.test.ts GitHub Actions / buildtest/builder/diretory.test.ts > directory_builder > empty directory
|
||
"too few blocks", | ||
); | ||
}); | ||
|
||
it("empty directory with extra size", async ({ task }) => { | ||
const destination = path.join(__dirname, "output", task.suite!.name); | ||
const drive: DirectoryDriveConfig = { | ||
builder: "directory", | ||
directory: path.join(__dirname, "data", "empty"), | ||
extraSize: 1024 * 1024, // 1Mb | ||
format: "ext2", | ||
}; | ||
await build(task.id, drive, image, destination); | ||
const filename = path.join(destination, `${task.id}.ext2`); | ||
const stat = fs.statSync(filename); | ||
expect(stat.size).toEqual(1069056); | ||
}); | ||
|
||
it("success", async ({ task }) => { | ||
const destination = path.join(__dirname, "output", task.suite!.name); | ||
const drive: DirectoryDriveConfig = { | ||
builder: "directory", | ||
directory: path.join(__dirname, "data", "sample1"), | ||
extraSize: 0, | ||
format: "ext2", | ||
}; | ||
await build(task.id, drive, image, destination); | ||
const filename = path.join(destination, `${task.id}.ext2`); | ||
const stat = fs.statSync(filename); | ||
expect(stat.size).toEqual(32768); | ||
}); | ||
|
||
afterAll(({ name }) => { | ||
const destination = path.join(__dirname, "output", name); | ||
fs.rmSync(destination, { recursive: true, force: true }); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import fs from "fs-extra"; | ||
import path from "path"; | ||
import { afterAll, beforeAll, describe, expect, it } from "vitest"; | ||
import { build } from "../../src/builder/docker"; | ||
import { DockerDriveConfig } from "../../src/config"; | ||
|
||
describe("docker_builder", () => { | ||
const image = "cartesi/sdk:0.11.0"; | ||
|
||
beforeAll(({ name }) => { | ||
const destination = path.join(__dirname, "output", name); | ||
fs.mkdirpSync(destination); | ||
}); | ||
|
||
it("should not build withoua correct context", async ({ task }) => { | ||
const destination = path.join(__dirname, "output", task.suite!.name); | ||
const drive: DockerDriveConfig = { | ||
builder: "docker", | ||
context: ".", | ||
dockerfile: "Dockerfile", | ||
extraSize: 0, | ||
format: "ext2", | ||
tags: [], | ||
image: undefined, | ||
target: undefined, | ||
}; | ||
await expect(build(task.id, drive, image, destination)).rejects.toThrow( | ||
"exit code 1", | ||
); | ||
}); | ||
|
||
it("should not build a non-riscv image", async ({ task }) => { | ||
const destination = path.join(__dirname, "output", task.suite!.name); | ||
const drive: DockerDriveConfig = { | ||
builder: "docker", | ||
context: path.join(__dirname, "data"), | ||
dockerfile: path.join(__dirname, "data", "Dockerfile.nonriscv"), | ||
extraSize: 0, | ||
format: "ext2", | ||
tags: [], | ||
image: undefined, | ||
target: undefined, | ||
}; | ||
await expect(build(task.id, drive, image, destination)).rejects.toThrow( | ||
Check failure on line 44 in apps/cli/test/builder/docker.test.ts GitHub Actions / buildtest/builder/docker.test.ts > docker_builder > should not build a non-riscv image
|
||
"Invalid image Architecture: arm64. Expected riscv64", | ||
); | ||
}); | ||
|
||
it("should build a docker drive", { timeout: 60000 }, async ({ task }) => { | ||
const destination = path.join(__dirname, "output", task.suite!.name); | ||
const drive: DockerDriveConfig = { | ||
builder: "docker", | ||
context: path.join(__dirname, "data"), | ||
dockerfile: path.join(__dirname, "data", "Dockerfile"), | ||
extraSize: 0, | ||
format: "ext2", | ||
tags: [], | ||
image: undefined, | ||
target: undefined, | ||
}; | ||
await build(task.id, drive, image, destination); | ||
}); | ||
|
||
afterAll(({ name }) => { | ||
const destination = path.join(__dirname, "output", name); | ||
fs.rmSync(destination, { recursive: true, force: true }); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import fs from "fs-extra"; | ||
import path from "path"; | ||
import { afterAll, beforeAll, describe, expect, it } from "vitest"; | ||
import { build } from "../../src/builder/empty"; | ||
import { EmptyDriveConfig } from "../../src/config"; | ||
|
||
describe("empty_builder", () => { | ||
const image = "cartesi/sdk:0.11.0"; | ||
|
||
beforeAll(({ name }) => { | ||
const destination = path.join(__dirname, "output", name); | ||
fs.mkdirpSync(destination); | ||
}); | ||
|
||
it("invalid size", async ({ task }) => { | ||
const destination = path.join(__dirname, "output", task.suite!.name); | ||
const drive: EmptyDriveConfig = { | ||
builder: "empty", | ||
format: "ext2", | ||
size: 0, | ||
}; | ||
await expect(build(task.id, drive, image, destination)).rejects.toThrow( | ||
Check failure on line 22 in apps/cli/test/builder/empty.test.ts GitHub Actions / buildtest/builder/empty.test.ts > empty_builder > invalid size
|
||
"too few blocks", | ||
); | ||
}); | ||
|
||
it("success", async ({ task }) => { | ||
const destination = path.join(__dirname, "output", task.suite!.name); | ||
const driveName = `${task.id}.ext2`; | ||
const drive: EmptyDriveConfig = { | ||
builder: "empty", | ||
format: "ext2", | ||
size: 1024 * 1024 * 1, // 1Mb | ||
}; | ||
await build(task.id, drive, image, destination); | ||
|
||
const filename = path.join(destination, driveName); | ||
expect(fs.existsSync(filename)).toBeTruthy(); | ||
const stat = await fs.stat(filename); | ||
expect(stat.isFile()).toBeTruthy(); | ||
expect(stat.size).toEqual(1 * 1024 * 1024); | ||
}); | ||
|
||
afterAll(({ name }) => { | ||
const destination = path.join(__dirname, "output", name); | ||
fs.emptyDirSync(destination); | ||
fs.rmSync(destination, { recursive: true, force: true }); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import fs from "fs-extra"; | ||
import path from "path"; | ||
import { afterAll, beforeAll, describe, expect, it } from "vitest"; | ||
import { build } from "../../src/builder/none"; | ||
import { ExistingDriveConfig } from "../../src/config"; | ||
|
||
describe("none_build", () => { | ||
beforeAll(({ name }) => { | ||
const destination = path.join(__dirname, "output", name); | ||
fs.mkdirpSync(destination); | ||
}); | ||
|
||
it("should not build a missing file", async ({ task }) => { | ||
const destination = path.join(__dirname, "output", task.suite!.name); | ||
const drive: ExistingDriveConfig = { | ||
builder: "none", | ||
filename: path.join(__dirname, "data", "missing.ext2"), | ||
format: "ext2", | ||
}; | ||
await expect(build(task.id, drive, destination)).rejects.toThrow( | ||
"no such file or directory", | ||
); | ||
}); | ||
|
||
it("should just copy an existing drive", async ({ task }) => { | ||
const destination = path.join(__dirname, "output", task.suite!.name); | ||
const filename = path.join(__dirname, "data", "data.ext2"); | ||
const drive: ExistingDriveConfig = { | ||
builder: "none", | ||
filename, | ||
format: "ext2", | ||
}; | ||
await build(task.id, drive, destination); | ||
const src = fs.statSync(filename); | ||
const dest = fs.statSync(path.join(destination, `${task.id}.ext2`)); | ||
expect(dest.size).toEqual(src.size); | ||
}); | ||
|
||
afterAll(({ name }) => { | ||
const destination = path.join(__dirname, "output", name); | ||
fs.rmSync(destination, { recursive: true, force: true }); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import fs from "fs-extra"; | ||
import path from "path"; | ||
import { afterAll, describe, expect, it } from "vitest"; | ||
import { build } from "../../src/builder/tar"; | ||
import { TarDriveConfig } from "../../src/config"; | ||
|
||
describe("tar_builder", () => { | ||
const image = "cartesi/sdk:0.11.0"; | ||
|
||
it("should not build a missing file", async ({ task }) => { | ||
const destination = path.join(__dirname, "output", task.suite!.name); | ||
const drive: TarDriveConfig = { | ||
builder: "tar", | ||
filename: path.join(__dirname, "data", "unexisting.tar"), | ||
extraSize: 0, | ||
format: "ext2", | ||
}; | ||
await expect(build(task.id, drive, image, destination)).rejects.toThrow( | ||
"no such file or directory", | ||
); | ||
}); | ||
|
||
it("should build a tar drive", async ({ task }) => { | ||
const destination = path.join(__dirname, "output", task.suite!.name); | ||
const drive: TarDriveConfig = { | ||
builder: "tar", | ||
filename: path.join(__dirname, "data", "data.tar"), | ||
extraSize: 0, | ||
format: "ext2", | ||
}; | ||
await build(task.id, drive, image, destination); | ||
}); | ||
|
||
afterAll(({ name }) => { | ||
const destination = path.join(__dirname, "output", name); | ||
fs.rmSync(destination, { recursive: true, force: true }); | ||
}); | ||
}); |
Oops, something went wrong.