|
1 | 1 | import { fromNodeProviderChain } from "@aws-sdk/credential-providers"; |
2 | | -import { describe, expect, it } from "@effect/vitest"; |
3 | | -import { Console, Effect, Stream } from "effect"; |
4 | | -import { S3 } from "../../src/services/s3/index.ts"; |
5 | 2 | import { FileSystem } from "@effect/platform"; |
6 | 3 | import { NodeFileSystem } from "@effect/platform-node"; |
| 4 | +import { describe, expect, it } from "@effect/vitest"; |
| 5 | +import { Console, Effect, Stream } from "effect"; |
7 | 6 | import path from "pathe"; |
| 7 | +import { S3 } from "../../src/services/s3/index.ts"; |
8 | 8 |
|
9 | 9 | const credentials = await fromNodeProviderChain()(); |
10 | 10 |
|
@@ -55,4 +55,42 @@ describe("S3 Smoke Tests", () => { |
55 | 55 | yield* fs.remove(outputFilePath); |
56 | 56 | }).pipe(Effect.provide(NodeFileSystem.layer)), |
57 | 57 | ); |
| 58 | + |
| 59 | + it.live("headBucket and headObject", () => |
| 60 | + Effect.gen(function* () { |
| 61 | + const fs = yield* FileSystem.FileSystem; |
| 62 | + |
| 63 | + yield* Console.log("Step 1: Create bucket"); |
| 64 | + yield* client.createBucket({ Bucket: BUCKET_NAME }); |
| 65 | + |
| 66 | + yield* Console.log("Step 2: HeadBucket"); |
| 67 | + const bucketHead = yield* client.headBucket({ Bucket: BUCKET_NAME }); |
| 68 | + expect(bucketHead.BucketRegion).toBe("us-east-1"); |
| 69 | + |
| 70 | + yield* Console.log("Step 3: Upload a file"); |
| 71 | + const rawInput = yield* fs.readFile(inputFilePath); |
| 72 | + yield* client.putObject({ |
| 73 | + Bucket: BUCKET_NAME, |
| 74 | + Key: FILE_KEY, |
| 75 | + Body: rawInput, |
| 76 | + ContentType: "image/jpeg", |
| 77 | + }); |
| 78 | + |
| 79 | + yield* Console.log("Step 4: HeadObject"); |
| 80 | + const objectHead = yield* client.headObject({ |
| 81 | + Bucket: BUCKET_NAME, |
| 82 | + Key: FILE_KEY, |
| 83 | + }); |
| 84 | + expect(objectHead.ContentType).toBe("image/jpeg"); |
| 85 | + expect(objectHead.ContentLength).toBe(String(rawInput.byteLength)); |
| 86 | + |
| 87 | + yield* Console.log("Step 5: clean up"); |
| 88 | + yield* client.deleteObject({ |
| 89 | + Bucket: BUCKET_NAME, |
| 90 | + Key: FILE_KEY, |
| 91 | + }); |
| 92 | + yield* client.deleteBucket({ Bucket: BUCKET_NAME }); |
| 93 | + }).pipe(Effect.provide(NodeFileSystem.layer)), |
| 94 | + {timeout: 1000000} |
| 95 | + ); |
58 | 96 | }); |
0 commit comments