Skip to content

Commit

Permalink
test: add e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zirkelc committed Jul 18, 2024
1 parent 1ceff10 commit 24de936
Show file tree
Hide file tree
Showing 39 changed files with 7,161 additions and 5,965 deletions.
6 changes: 5 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
{
"$schema": "https://biomejs.dev/schemas/1.5.3/schema.json",
"vcs": {
"clientKind": "git",
"enabled": true,
"useIgnoreFile": true
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"ignore": ["dist", "node_modules"],
"rules": {
"recommended": true,
"style": {
Expand Down
38 changes: 19 additions & 19 deletions examples/base64/package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"name": "middy-store-example-base64",
"private": true,
"type": "module",
"main": "handler.ts",
"scripts": {
"start": "tsx handler"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@middy/core": "^5.2.3",
"middy-store": "workspace:*",
"middy-store-base64": "workspace:*"
},
"devDependencies": {
"@types/aws-lambda": "^8.10.133"
}
}
"name": "middy-store-example-base64",
"private": true,
"type": "module",
"main": "handler.ts",
"scripts": {
"start": "tsx handler"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@middy/core": "^5.2.3",
"middy-store": "workspace:*",
"middy-store-base64": "workspace:*"
},
"devDependencies": {
"@types/aws-lambda": "^8.10.133"
}
}
6 changes: 3 additions & 3 deletions examples/base64/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "@tsconfig/node18/tsconfig.json",
"compilerOptions": {},
}
"extends": "@tsconfig/node18/tsconfig.json",
"compilerOptions": {}
}
2 changes: 1 addition & 1 deletion examples/s3/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { randomBytes, randomUUID } from "crypto";
import { randomBytes, randomUUID } from "node:crypto";
import middy from "@middy/core";
import { Handler } from "aws-lambda";
import { middyStore } from "middy-store";
Expand Down
36 changes: 18 additions & 18 deletions examples/s3/package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"name": "middy-store-example-s3",
"version": "1.0.0",
"description": "",
"private": true,
"type": "module",
"main": "index.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@middy/core": "^5.2.3",
"middy-store": "workspace:*",
"middy-store-s3": "workspace:*"
}
}
"name": "middy-store-example-s3",
"version": "1.0.0",
"description": "",
"private": true,
"type": "module",
"main": "index.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@middy/core": "^5.2.3",
"middy-store": "workspace:*",
"middy-store-s3": "workspace:*"
}
}
6 changes: 3 additions & 3 deletions examples/s3/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "@tsconfig/node18/tsconfig.json",
"compilerOptions": {},
}
"extends": "@tsconfig/node18/tsconfig.json",
"compilerOptions": {}
}
4 changes: 2 additions & 2 deletions examples/stepfunctions/functions/multiple.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { randomBytes, randomUUID } from "crypto";
import { randomBytes, randomUUID } from "node:crypto";
import middy from "@middy/core";
import { Handler } from "aws-lambda";
import type { Handler } from "aws-lambda";
import { loadInput, storeOutput } from "middy-store";
import { S3Store } from "middy-store-s3";

Expand Down
6 changes: 3 additions & 3 deletions examples/stepfunctions/functions/single.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { randomBytes, randomUUID } from "crypto";
import { randomBytes, randomUUID } from "node:crypto";
import middy from "@middy/core";
import { Handler } from "aws-lambda";
import { loadInput, storeOutput } from "middy-store-";
import type { Handler } from "aws-lambda";
import { loadInput, storeOutput } from "middy-store";
import { S3Store } from "middy-store-s3";

const MAX_OUTPUT_SIZE_KB = 256; // https://docs.aws.amazon.com/step-functions/latest/dg/limits.html
Expand Down
52 changes: 26 additions & 26 deletions examples/stepfunctions/package.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
{
"name": "middy-store-example-stepfunctions",
"version": "1.0.0",
"description": "",
"private": true,
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"deploy": "pnpm sls deploy"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@middy/core": "^5.2.3",
"middy-store": "workspace:*",
"middy-store-s3": "workspace:*"
},
"devDependencies": {
"esbuild": "^0.20.1",
"serverless": "^3.38.0",
"serverless-esbuild": "^1.51.0",
"serverless-step-functions": "^3.19.0",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
}
}
"name": "middy-store-example-stepfunctions",
"version": "1.0.0",
"description": "",
"private": true,
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"deploy": "pnpm sls deploy"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@middy/core": "^5.2.3",
"middy-store": "workspace:*",
"middy-store-s3": "workspace:*"
},
"devDependencies": {
"esbuild": "^0.20.1",
"serverless": "^3.38.0",
"serverless-esbuild": "^1.51.0",
"serverless-step-functions": "^3.19.0",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
}
}
6 changes: 3 additions & 3 deletions examples/stepfunctions/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "@tsconfig/node18/tsconfig.json",
"compilerOptions": {},
}
"extends": "@tsconfig/node18/tsconfig.json",
"compilerOptions": {}
}
Empty file.
116 changes: 116 additions & 0 deletions examples/stepfunctions_map/functions/single.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import { randomBytes, randomUUID } from "node:crypto";
import middy from "@middy/core";
import type { Handler } from "aws-lambda";
import { middyStore } from "middy-store";
import { S3Store } from "middy-store-s3";

const MAX_OUTPUT_SIZE_KB = 256; // https://docs.aws.amazon.com/step-functions/latest/dg/limits.html

const store = new S3Store({
bucket: process.env.PAYLOAD_BUCKET!,
key: randomUUID(),
});

type Payload = {
content: string;
};

type GeneratePayloadInput = any;

type GeneratePayloadOutput = {
sizeInKb: number;
payload: Payload;
iterator: Array<number>;
};

const SIZE = 100 * 1024 * 1024; // 100 MB
const ITERATIONS = 50;

const generatePayloads: Handler<
GeneratePayloadInput,
GeneratePayloadOutput
> = async (input, context, callback) => {
console.log("Generating payload", { input });

// Generate a large payload
const content = randomBytes(SIZE).toString("base64");

const output = {
...input,
sizeInKb: Buffer.byteLength(content, "utf8") / 1024,
payload: {
content,
},
iterator: Array.from({ length: ITERATIONS }, (_, i) => i),
};

console.log(`Generated payload: ${output.sizeInKb} KB`);

return output;
};

export const generatePayloadsHandler = middy()
.use(
middyStore({
// logger: console.log,
stores: [
new S3Store({
// logger: console.log,
region: "us-east-1",
bucket: process.env.PAYLOAD_BUCKET!,
// key: makeEtlKey(),
format: {
type: "url",
format: "s3-region-path",
},
}),
],
read: true,
write: {
selector: "payload",
},
}),
)
.handler(generatePayloads);

type MapPayloadIteratorInput = GeneratePayloadOutput & {
index: number;
};
const mapPayloadIterator: Handler<MapPayloadIteratorInput> = async (
input,
context,
): Promise<undefined> => {
console.log(`Iterator index${input.index}`);

const payload = input.payload;

console.log(
`Actual payload size: ${Buffer.byteLength(payload.content, "utf8")} KB`,
);

return undefined;
};

export const mapPayloadIteratorHandler = middy()
.use(
middyStore({
// logger: console.log,
stores: [
new S3Store({
// logger: console.log,
region: "us-east-1",
bucket: process.env.PAYLOAD_BUCKET!,
// key: makeEtlKey(),
format: {
type: "url",
format: "s3-region-path",
},
}),
],
read: true,
write: {
selector: "payload",
},
}),
)
.handler(mapPayloadIterator);
27 changes: 27 additions & 0 deletions examples/stepfunctions_map/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "middy-store-example-stepfunctions",
"version": "1.0.0",
"description": "",
"private": true,
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"deploy": "pnpm sls deploy"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@middy/core": "^5.2.3",
"middy-store": "workspace:*",
"middy-store-s3": "workspace:*"
},
"devDependencies": {
"esbuild": "^0.20.1",
"serverless": "^3.38.0",
"serverless-esbuild": "^1.51.0",
"serverless-step-functions": "^3.19.0",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
}
}
Loading

0 comments on commit 24de936

Please sign in to comment.