|
1 | 1 | import * as DenoFileSystem from "@effect/platform-deno/DenoFileSystem" |
2 | | -import { describe } from "@effect/vitest" |
| 2 | +import { assert, describe, it } from "@effect/vitest" |
| 3 | +import * as Effect from "effect/Effect" |
| 4 | +import * as FileSystem from "effect/FileSystem" |
3 | 5 | import { testLayer } from "../../effect/test/FileSystem.test-utils.ts" |
4 | 6 |
|
5 | | -describe("FileSystem", () => |
| 7 | +describe("FileSystem", () => { |
6 | 8 | testLayer(DenoFileSystem.layer, { |
7 | 9 | accessOnDirectory: false, |
8 | 10 | tempFileScopedRemovesDirectory: false |
9 | | - })) |
| 11 | + }) |
| 12 | + |
| 13 | + it.effect("copyFile rejects unsupported copy file modes", () => |
| 14 | + Effect.gen(function*() { |
| 15 | + const fs = yield* FileSystem.FileSystem |
| 16 | + const root = yield* fs.makeTempDirectoryScoped() |
| 17 | + const source = `${root}/source.txt` |
| 18 | + const destination = `${root}/destination.txt` |
| 19 | + |
| 20 | + yield* fs.writeFileString(source, "source") |
| 21 | + |
| 22 | + const exclusiveError = yield* Effect.flip( |
| 23 | + fs.copyFile(source, destination, { mode: FileSystem.CopyFileFlag.COPYFILE_EXCL }) |
| 24 | + ) |
| 25 | + assert.strictEqual(exclusiveError.reason._tag, "BadArgument") |
| 26 | + |
| 27 | + yield* fs.copyFile(source, destination, { mode: FileSystem.CopyFileFlag.COPYFILE_FICLONE }) |
| 28 | + assert.strictEqual(yield* fs.readFileString(destination), "source") |
| 29 | + |
| 30 | + const forceError = yield* Effect.flip( |
| 31 | + fs.copyFile(source, destination, { mode: FileSystem.CopyFileFlag.COPYFILE_FICLONE_FORCE }) |
| 32 | + ) |
| 33 | + assert.strictEqual(forceError.reason._tag, "BadArgument") |
| 34 | + }).pipe( |
| 35 | + Effect.scoped, |
| 36 | + Effect.provide(DenoFileSystem.layer) |
| 37 | + )) |
| 38 | +}) |
0 commit comments