Skip to content

Commit

Permalink
fix: Create mock bueckts not on test
Browse files Browse the repository at this point in the history
  • Loading branch information
mateopresacastro committed Nov 7, 2024
1 parent 04ed1d4 commit 3f1b2fe
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
11 changes: 1 addition & 10 deletions lib/aws/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,18 @@ import {
GetObjectCommand,
DeleteObjectCommand,
CreateBucketCommand,
ListObjectsCommand,
} from "@aws-sdk/client-s3";
import "server-only";

(async () => {
if (!isDev) return;
await createLocalStackBuckets();
await listAllObjects();
})();

async function createLocalStackBuckets() {
const buckets = await listBuckets();
if (buckets && buckets.length > 0) return;
[AWS_PUBLIC_BUCKET_NAME, AWS_PRIVATE_BUCKET_NAME, "test-bucket"].forEach(
[AWS_PUBLIC_BUCKET_NAME, AWS_PRIVATE_BUCKET_NAME].forEach(
async (bucket) =>
await s3.send(
new CreateBucketCommand({
Expand All @@ -39,13 +37,6 @@ async function createLocalStackBuckets() {
console.log("Buckets created on localstack", await listBuckets());
}

async function listAllObjects() {
[AWS_PUBLIC_BUCKET_NAME, AWS_PRIVATE_BUCKET_NAME].forEach(async (bucket) => {
const objects = await s3.send(new ListObjectsCommand({ Bucket: bucket }));
console.log("Objects in bucket: ", bucket, objects);
});
}

export async function listBuckets() {
try {
const data = await s3.send(new ListBucketsCommand({}));
Expand Down
4 changes: 2 additions & 2 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}

export const isDev =
process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
export const isDev = process.env.NODE_ENV === "development";
export const isTest = process.env.NODE_ENV === "test";

export function createSamplePackName(str: string) {
return str
Expand Down

0 comments on commit 3f1b2fe

Please sign in to comment.