|
| 1 | +import { describe, test } from "node:test"; |
| 2 | +import assert from "node:assert"; |
| 3 | + |
| 4 | +describe("S3 Client Configuration", () => { |
| 5 | + test("should include endpoint and forcePathStyle when cloudEndpoint is set", () => { |
| 6 | + // Set cloudEndpoint in environment |
| 7 | + const originalEnv = process.env.CLOUD_ENDPOINT; |
| 8 | + process.env.CLOUD_ENDPOINT = "http://localhost:9000"; |
| 9 | + process.env.CLOUD_REGION = "us-east-1"; |
| 10 | + process.env.CLOUD_KEY = "test-key"; |
| 11 | + process.env.CLOUD_SECRET = "test-secret"; |
| 12 | + |
| 13 | + // Clear module cache to force re-evaluation with new env |
| 14 | + const modulePath = require.resolve("../../src/services/s3"); |
| 15 | + const constantsPath = require.resolve("../../src/config/constants"); |
| 16 | + delete require.cache[modulePath]; |
| 17 | + delete require.cache[constantsPath]; |
| 18 | + |
| 19 | + // Re-import to get fresh config |
| 20 | + const { s3ClientConfig } = require("../../src/services/s3"); |
| 21 | + |
| 22 | + // Verify config structure |
| 23 | + assert.ok( |
| 24 | + s3ClientConfig !== undefined, |
| 25 | + "s3ClientConfig should be defined", |
| 26 | + ); |
| 27 | + assert.strictEqual( |
| 28 | + s3ClientConfig.endpoint, |
| 29 | + "http://localhost:9000", |
| 30 | + "endpoint should be set when cloudEndpoint is provided", |
| 31 | + ); |
| 32 | + assert.strictEqual( |
| 33 | + s3ClientConfig.forcePathStyle, |
| 34 | + true, |
| 35 | + "forcePathStyle should be true when cloudEndpoint is provided", |
| 36 | + ); |
| 37 | + |
| 38 | + // Restore original env |
| 39 | + if (originalEnv !== undefined) { |
| 40 | + process.env.CLOUD_ENDPOINT = originalEnv; |
| 41 | + } else { |
| 42 | + delete process.env.CLOUD_ENDPOINT; |
| 43 | + } |
| 44 | + }); |
| 45 | + |
| 46 | + test("should not include endpoint or forcePathStyle when cloudEndpoint is not set", () => { |
| 47 | + // Unset cloudEndpoint |
| 48 | + const originalEnv = process.env.CLOUD_ENDPOINT; |
| 49 | + delete process.env.CLOUD_ENDPOINT; |
| 50 | + process.env.CLOUD_REGION = "us-east-1"; |
| 51 | + process.env.CLOUD_KEY = "test-key"; |
| 52 | + process.env.CLOUD_SECRET = "test-secret"; |
| 53 | + |
| 54 | + // Clear module cache |
| 55 | + const modulePath = require.resolve("../../src/services/s3"); |
| 56 | + const constantsPath = require.resolve("../../src/config/constants"); |
| 57 | + delete require.cache[modulePath]; |
| 58 | + delete require.cache[constantsPath]; |
| 59 | + |
| 60 | + // Re-import to get fresh config |
| 61 | + const { s3ClientConfig } = require("../../src/services/s3"); |
| 62 | + |
| 63 | + // Verify config structure |
| 64 | + assert.ok( |
| 65 | + s3ClientConfig !== undefined, |
| 66 | + "s3ClientConfig should be defined", |
| 67 | + ); |
| 68 | + assert.strictEqual( |
| 69 | + s3ClientConfig.endpoint, |
| 70 | + undefined, |
| 71 | + "endpoint should not be set when cloudEndpoint is not provided", |
| 72 | + ); |
| 73 | + assert.strictEqual( |
| 74 | + s3ClientConfig.forcePathStyle, |
| 75 | + undefined, |
| 76 | + "forcePathStyle should not be set when cloudEndpoint is not provided", |
| 77 | + ); |
| 78 | + |
| 79 | + // Restore original env |
| 80 | + if (originalEnv !== undefined) { |
| 81 | + process.env.CLOUD_ENDPOINT = originalEnv; |
| 82 | + } |
| 83 | + }); |
| 84 | +}); |
0 commit comments