| 1 | import { tarGzipDirectory } from "@/Util/tarGzip.ts"; |
| 2 | import * as NodeServices from "@effect/platform-node/NodeServices"; |
| 3 | import { describe, expect, it } from "alchemy-test"; |
| 4 | import * as Effect from "effect/Effect"; |
| 5 | import * as FileSystem from "effect/FileSystem"; |
| 6 | import * as Path from "effect/Path"; |
| 7 | import * as zlib from "node:zlib"; |
| 8 | |
| 9 | describe("tarGzipDirectory", { tags: ["unit", "local"] }, () => { |
| 10 | it.effect("packs a Dockerfile and nested files into a gzipped ustar", () => |
| 11 | Effect.gen(function* () { |
| 12 | const fs = yield* FileSystem.FileSystem; |
| 13 | const path = yield* Path.Path; |
| 14 | const dir = yield* fs.makeTempDirectory({ prefix: "alchemy-tar-" }); |
| 15 | yield* fs.writeFileString( |
| 16 | path.join(dir, "Dockerfile"), |
| 17 | "FROM oven/bun:1\n", |
| 18 | ); |
| 19 | yield* fs.makeDirectory(path.join(dir, "dist"), { recursive: true }); |
| 20 | yield* fs.writeFileString( |
| 21 | path.join(dir, "dist", "index.html"), |
| 22 | "<h1>ok</h1>\n", |
| 23 | ); |
| 24 | const gz = yield* tarGzipDirectory(dir); |
| 25 | expect(gz.byteLength).toBeGreaterThan(80); |
| 26 | const tar = yield* Effect.sync(() => zlib.gunzipSync(gz)); |
| 27 | const latin1 = new TextDecoder("latin1").decode(tar); |
| 28 | expect(latin1).toContain("Dockerfile"); |
| 29 | expect(latin1).toContain("index.html"); |
| 30 | }).pipe(Effect.provide(NodeServices.layer)), |
| 31 | ); |
| 32 | }); |