diff --git a/storage-s3/s3.test.ts b/storage-s3/s3.test.ts new file mode 100644 index 0000000..57920af --- /dev/null +++ b/storage-s3/s3.test.ts @@ -0,0 +1,25 @@ +// load packages +import process from 'node:process' +import { test } from '@cross/test' +import { assertInstanceOf } from '@std/assert' +// @deno-types="minio/dist/esm/minio.d.mts" +import { Client } from 'minio' +import sinon from 'sinon' + +test('s3 - exports a Minio.Client instance', async () => { + // Setup + const envStub = sinon.stub(process, 'env').value({ + S3_ENDPOINT: 'test-endpoint', + MY_SCW_ACCESS_KEY: 'test-access-key', + MY_SCW_SECRET_KEY: 'test-secret-key', + }) + + // load module with stubbed env + const { minioClient } = await import('./s3.ts') + + // Verify + assertInstanceOf(minioClient, Client, 'Should export a Minio.Client instance') + + // Cleanup + envStub.restore() +}) diff --git a/storage-s3/s3.ts b/storage-s3/s3.ts index 23d7805..3bf9dd6 100644 --- a/storage-s3/s3.ts +++ b/storage-s3/s3.ts @@ -1,16 +1,12 @@ // load packages -import process from 'node:process' -import { checkRequiredEnv } from '@frytg/check-required-env' -import * as Minio from 'minio' +import { getRequiredEnv } from '@frytg/check-required-env/get' +// @deno-types="minio/dist/esm/minio.d.mts" +import { Client } from 'minio' -// check for env -checkRequiredEnv('S3_ENDPOINT') -checkRequiredEnv('MY_SCW_ACCESS_KEY') -checkRequiredEnv('MY_SCW_SECRET_KEY') - -export const minioClient = new Minio.Client({ +// create a minio client +export const minioClient = new Client({ useSSL: true, - endPoint: process.env.S3_ENDPOINT, - accessKey: process.env.MY_SCW_ACCESS_KEY, - secretKey: process.env.MY_SCW_SECRET_KEY, + endPoint: getRequiredEnv('S3_ENDPOINT', false), + accessKey: getRequiredEnv('MY_SCW_ACCESS_KEY', false), + secretKey: getRequiredEnv('MY_SCW_SECRET_KEY', false), })