Skip to content

Commit

Permalink
test-helper adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
biffgaut committed Dec 27, 2022
1 parent c27ff37 commit 982b68c
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import * as cdk from "aws-cdk-lib";
import { FargateToKinesisFirehose } from "../lib";
import * as ecs from 'aws-cdk-lib/aws-ecs';
import { Match, Template } from "aws-cdk-lib/assertions";
import { GetTestDestination } from './test-helper';
import { GetTestFirehoseDestination } from './test-helper';

test('New service/new bucket, public API, new VPC', () => {
const stack = new cdk.Stack();
Expand All @@ -26,7 +26,7 @@ test('New service/new bucket, public API, new VPC', () => {
const containerName = "custom-container-name";
const serviceName = "custom-service-name";
const familyName = "family-name";
const destination = GetTestDestination(stack, 'test-destination');
const destination = GetTestFirehoseDestination(stack, 'test-destination');

const construct = new FargateToKinesisFirehose(stack, 'test-construct', {
publicApi,
Expand Down Expand Up @@ -137,7 +137,7 @@ test('New service/new bucket, private API, new VPC', () => {
const stack = new cdk.Stack();
const publicApi = false;

const destination = GetTestDestination(stack, 'test-destination');
const destination = GetTestFirehoseDestination(stack, 'test-destination');

new FargateToKinesisFirehose(stack, 'test-construct', {
publicApi,
Expand Down Expand Up @@ -199,7 +199,7 @@ test('New service/new bucket, private API, new VPC', () => {
test('Default construct has all expected properties', () => {
const stack = new cdk.Stack();

const destination = GetTestDestination(stack, 'test-destination');
const destination = GetTestFirehoseDestination(stack, 'test-destination');
const construct = new FargateToKinesisFirehose(stack, 'test-fargate-kinesisfirehose', {
publicApi: false,
ecrRepositoryArn: defaults.fakeEcrRepoArn,
Expand All @@ -215,7 +215,7 @@ test('Default construct has all expected properties', () => {
test('Construct deploys Fargate Service in isolated subnets when publicApi is set to false', () => {
const stack = new cdk.Stack();

const destination = GetTestDestination(stack, 'test-destination');
const destination = GetTestFirehoseDestination(stack, 'test-destination');
new FargateToKinesisFirehose(stack, 'test-fargate-kinesisfirehose', {
publicApi: false,
ecrRepositoryArn: defaults.fakeEcrRepoArn,
Expand Down Expand Up @@ -280,7 +280,7 @@ test('Construct deploys Fargate Service in isolated subnets when publicApi is se

test('Construct deploys Fargate Service in private subnets when publicApi is set to true', () => {
const stack = new cdk.Stack();
const destination = GetTestDestination(stack, 'test-destination');
const destination = GetTestFirehoseDestination(stack, 'test-destination');

new FargateToKinesisFirehose(stack, 'test-fargate-kinesisfirehose', {
publicApi: true,
Expand Down Expand Up @@ -347,7 +347,7 @@ test('Construct deploys Fargate Service in private subnets when publicApi is set

test('Construct uses vpcProps when provided', () => {
const stack = new cdk.Stack();
const destination = GetTestDestination(stack, 'test-destination');
const destination = GetTestFirehoseDestination(stack, 'test-destination');

new FargateToKinesisFirehose(stack, 'test-fargate-kinesisfirehose', {
publicApi: false,
Expand All @@ -371,7 +371,7 @@ test('Construct uses vpcProps when provided', () => {

test('Construct uses existingVpc when provided', () => {
const stack = new cdk.Stack();
const destination = GetTestDestination(stack, 'test-destination');
const destination = GetTestFirehoseDestination(stack, 'test-destination');

const existingVpc = defaults.getTestVpc(stack, false, {
vpcName: 'my-vpc'
Expand All @@ -397,7 +397,7 @@ test('Construct uses existingVpc when provided', () => {

test('Construct creates VPC Interface Endpoints for ECR and Kinesis Streams', () => {
const stack = new cdk.Stack();
const destination = GetTestDestination(stack, 'test-destination');
const destination = GetTestFirehoseDestination(stack, 'test-destination');

new FargateToKinesisFirehose(stack, 'test-fargate-kinesisfirehose', {
publicApi: false,
Expand Down Expand Up @@ -438,7 +438,7 @@ test('Construct creates VPC Interface Endpoints for ECR and Kinesis Streams', ()

test('Container has default stream name environment variable', () => {
const stack = new cdk.Stack();
const destination = GetTestDestination(stack, 'test-destination');
const destination = GetTestFirehoseDestination(stack, 'test-destination');

new FargateToKinesisFirehose(stack, 'test-fargate-kinesisfirehose', {
publicApi: false,
Expand All @@ -462,7 +462,7 @@ test('Container has default stream name environment variable', () => {

test('Container stream name environment variable can be overridden', () => {
const stack = new cdk.Stack();
const destination = GetTestDestination(stack, 'test-destination');
const destination = GetTestFirehoseDestination(stack, 'test-destination');

new FargateToKinesisFirehose(stack, 'test-fargate-kinesisfirehose', {
publicApi: false,
Expand All @@ -487,7 +487,7 @@ test('Container stream name environment variable can be overridden', () => {

test('Construct grants PutRecord permission for the Fargate Service to write to the Kinesis Stream', () => {
const stack = new cdk.Stack();
const destination = GetTestDestination(stack, 'test-destination');
const destination = GetTestFirehoseDestination(stack, 'test-destination');

new FargateToKinesisFirehose(stack, 'test-fargate-kinesisfirehose', {
publicApi: false,
Expand Down Expand Up @@ -520,7 +520,7 @@ test('Construct grants PutRecord permission for the Fargate Service to write to

test('Construct defaults to the latest version of the ECR image', () => {
const stack = new cdk.Stack();
const destination = GetTestDestination(stack, 'test-destination');
const destination = GetTestFirehoseDestination(stack, 'test-destination');

new FargateToKinesisFirehose(stack, 'test-fargate-kinesisfirehose', {
publicApi: false,
Expand Down Expand Up @@ -550,7 +550,7 @@ test('Construct defaults to the latest version of the ECR image', () => {

test('Construct uses ecrImageVersion when provided', () => {
const stack = new cdk.Stack();
const destination = GetTestDestination(stack, 'test-destination');
const destination = GetTestFirehoseDestination(stack, 'test-destination');

new FargateToKinesisFirehose(stack, 'test-fargate-kinesisfirehose', {
publicApi: false,
Expand Down Expand Up @@ -581,7 +581,7 @@ test('Construct uses ecrImageVersion when provided', () => {

test('Construct uses clusterProps when provided', () => {
const stack = new cdk.Stack();
const destination = GetTestDestination(stack, 'test-destination');
const destination = GetTestFirehoseDestination(stack, 'test-destination');

new FargateToKinesisFirehose(stack, 'test-fargate-kinesisfirehose', {
publicApi: false,
Expand All @@ -600,7 +600,7 @@ test('Construct uses clusterProps when provided', () => {

test('Construct uses containerDefinitionProps when provided', () => {
const stack = new cdk.Stack();
const destination = GetTestDestination(stack, 'test-destination');
const destination = GetTestFirehoseDestination(stack, 'test-destination');

new FargateToKinesisFirehose(stack, 'test-fargate-kinesisfirehose', {
publicApi: false,
Expand All @@ -623,7 +623,7 @@ test('Construct uses containerDefinitionProps when provided', () => {

test('Construct uses fargateTaskDefinitionProps when provided', () => {
const stack = new cdk.Stack();
const destination = GetTestDestination(stack, 'test-destination');
const destination = GetTestFirehoseDestination(stack, 'test-destination');

new FargateToKinesisFirehose(stack, 'test-fargate-kinesisfirehose', {
publicApi: false,
Expand All @@ -642,7 +642,7 @@ test('Construct uses fargateTaskDefinitionProps when provided', () => {

test('Construct uses fargateServiceProps when provided', () => {
const stack = new cdk.Stack();
const destination = GetTestDestination(stack, 'test-destination');
const destination = GetTestFirehoseDestination(stack, 'test-destination');

new FargateToKinesisFirehose(stack, 'test-fargate-kinesisfirehose', {
publicApi: false,
Expand All @@ -663,7 +663,7 @@ test('Construct uses fargateServiceProps when provided', () => {

test('Construct uses existingFargateServiceObject when provided', () => {
const stack = new cdk.Stack();
const destination = GetTestDestination(stack, 'test-destination');
const destination = GetTestFirehoseDestination(stack, 'test-destination');

const existingVpc = defaults.getTestVpc(stack);

Expand Down Expand Up @@ -709,7 +709,7 @@ test('Construct uses existingFargateServiceObject when provided', () => {
test('Test fail if existingFirehose does not have a stream name', () => {
// Stack
const stack = new cdk.Stack();
const destination = GetTestDestination(stack, 'test-destination');
const destination = GetTestFirehoseDestination(stack, 'test-destination');

const mutatedFirehose = defaults.overrideProps(destination.kinesisFirehose, {});
mutatedFirehose.deliveryStreamName = undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { App, Stack } from "aws-cdk-lib";
import { FargateToKinesisFirehose } from "../lib";
import { CreateFargateService, generateIntegStackName, getTestVpc, suppressAutoDeleteHandlerWarnings } from '@aws-solutions-constructs/core';
import * as ecs from 'aws-cdk-lib/aws-ecs';
import { GetTestDestination } from './test-helper';
import { GetTestFirehoseDestination } from './test-helper';

const app = new App();
const stack = new Stack(app, generateIntegStackName(__filename));
Expand All @@ -25,7 +25,7 @@ const existingVpc = getTestVpc(stack);

const image = ecs.ContainerImage.fromRegistry('nginx');

const destination = GetTestDestination(stack, 'test-destination');
const destination = GetTestFirehoseDestination(stack, 'destination-firehose');

const [existingFargateServiceObject, existingContainerDefinitionObject] = CreateFargateService(stack,
'test',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { App, Stack } from "aws-cdk-lib";
import { FargateToKinesisFirehose } from "../lib";
import { buildVpc, DefaultPublicPrivateVpcProps, generateIntegStackName, suppressAutoDeleteHandlerWarnings } from '@aws-solutions-constructs/core';
import * as ecs from 'aws-cdk-lib/aws-ecs';
import { GetTestDestination } from './test-helper';
import { GetTestFirehoseDestination } from './test-helper';

const app = new App();
const stack = new Stack(app, generateIntegStackName(__filename));
Expand All @@ -25,7 +25,7 @@ const existingVpc = buildVpc(stack, {
defaultVpcProps: DefaultPublicPrivateVpcProps()
});

const destination = GetTestDestination(stack, 'test-destination');
const destination = GetTestFirehoseDestination(stack, 'destination-firehose');

new FargateToKinesisFirehose(stack, 'test-fargate-kinesisstreams', {
publicApi: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import { App, Stack } from "aws-cdk-lib";
import { FargateToKinesisFirehose } from "../lib";
import { generateIntegStackName, suppressAutoDeleteHandlerWarnings } from '@aws-solutions-constructs/core';
import * as ecs from "aws-cdk-lib/aws-ecs";
import { GetTestDestination } from './test-helper';
import { GetTestFirehoseDestination } from './test-helper';

const app = new App();
const stack = new Stack(app, generateIntegStackName(__filename));

const destination = GetTestDestination(stack, 'test-destination');
const destination = GetTestFirehoseDestination(stack, 'destination-firehose');

new FargateToKinesisFirehose(stack, 'test-fargate-kinesisstreams', {
publicApi: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { Aws, App, Stack } from "aws-cdk-lib";
import { FargateToKinesisFirehose, FargateToKinesisFirehoseProps } from "../lib";
import { generateIntegStackName, suppressAutoDeleteHandlerWarnings } from '@aws-solutions-constructs/core';
import * as ecs from 'aws-cdk-lib/aws-ecs';
import { GetTestDestination } from './test-helper';
import { GetTestFirehoseDestination } from './test-helper';

// Setup
const app = new App();
Expand All @@ -26,7 +26,7 @@ const stack = new Stack(app, generateIntegStackName(__filename), {

const image = ecs.ContainerImage.fromRegistry('nginx');

const destination = GetTestDestination(stack, 'test-destination');
const destination = GetTestFirehoseDestination(stack, 'destination-firehose');

const testProps: FargateToKinesisFirehoseProps = {
publicApi: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import { App, Stack } from "aws-cdk-lib";
import { FargateToKinesisFirehose } from "../lib";
import { generateIntegStackName, suppressAutoDeleteHandlerWarnings } from '@aws-solutions-constructs/core';
import * as ecs from "aws-cdk-lib/aws-ecs";
import { GetTestDestination } from './test-helper';
import { GetTestFirehoseDestination } from './test-helper';

const app = new App();
const stack = new Stack(app, generateIntegStackName(__filename));

const destination = GetTestDestination(stack, 'test-destination');
const destination = GetTestFirehoseDestination(stack, 'destination-firehose');

new FargateToKinesisFirehose(stack, 'test-fargate-kinesisstreams', {
publicApi: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
* and limitations under the License.
*/

import '@aws-cdk/assert/jest';
import * as cdk from "aws-cdk-lib";
import { Construct } from "constructs";
import { KinesisFirehoseToS3 } from '@aws-solutions-constructs/aws-kinesisfirehose-s3';

export function GetTestDestination(scope: Construct, id: string): KinesisFirehoseToS3 {
// We can't move this to core, because the dependence upon KinesisFirehoseToS3
// would cause a circular dependency
export function GetTestFirehoseDestination(scope: Construct, id: string): KinesisFirehoseToS3 {
return new KinesisFirehoseToS3(scope, id, {
bucketProps: {
autoDeleteObjects: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@

// Imports
import '@aws-cdk/assert/jest';
import { Construct } from 'constructs';
import * as cdk from 'aws-cdk-lib';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import { KinesisFirehoseToS3 } from '@aws-solutions-constructs/aws-kinesisfirehose-s3';
import { LambdaToKinesisFirehose } from '../lib';
import * as defaults from '@aws-solutions-constructs/core';
import { GetTestFirehoseDestination } from './test-helper';

test('Test that properties are set correctly', () => {
// Stack
const stack = new cdk.Stack();
const destination = GetTestDestination(stack, 'test-destination');
const destination = GetTestFirehoseDestination(stack, 'test-destination');

const construct = new LambdaToKinesisFirehose(stack, 'test-target', {
existingKinesisFirehose: destination.kinesisFirehose,
Expand All @@ -42,7 +41,7 @@ test('Test that properties are set correctly', () => {
test('Test existing function is utilized correctly', () => {
// Stack
const stack = new cdk.Stack();
const destination = GetTestDestination(stack, 'test-destination');
const destination = GetTestFirehoseDestination(stack, 'test-destination');
const testName = 'test-name';
const existingFunction = new lambda.Function(stack, 'test-function', {
runtime: lambda.Runtime.NODEJS_18_X,
Expand All @@ -68,7 +67,7 @@ test('Test existing function is utilized correctly', () => {
test('Test that lambda function props are incorporated', () => {
// Stack
const stack = new cdk.Stack();
const destination = GetTestDestination(stack, 'test-destination');
const destination = GetTestFirehoseDestination(stack, 'test-destination');
const testName = 'test-name';

new LambdaToKinesisFirehose(stack, 'test-target', {
Expand All @@ -91,7 +90,7 @@ test('Test that new VPC is created', () => {
const stack = new cdk.Stack();
const cidrRange = '172.0.0.0/16';

const destination = GetTestDestination(stack, 'test-destination');
const destination = GetTestFirehoseDestination(stack, 'test-destination');

const construct = new LambdaToKinesisFirehose(stack, 'test-target', {
existingKinesisFirehose: destination.kinesisFirehose,
Expand Down Expand Up @@ -133,7 +132,7 @@ test('Test that existing VPC is used', () => {
const stack = new cdk.Stack();
const cidrInGetTestVpc = '172.168.0.0/16';

const destination = GetTestDestination(stack, 'test-destination');
const destination = GetTestFirehoseDestination(stack, 'test-destination');
const myVpc = defaults.getTestVpc(stack, false);
const construct = new LambdaToKinesisFirehose(stack, 'test-target', {
existingKinesisFirehose: destination.kinesisFirehose,
Expand Down Expand Up @@ -173,7 +172,7 @@ test('Test that existing VPC is used', () => {
test('Test fail if existingFirehose does not have a stream name', () => {
// Stack
const stack = new cdk.Stack();
const destination = GetTestDestination(stack, 'test-destination');
const destination = GetTestFirehoseDestination(stack, 'test-destination');
const testName = 'test-name';

const mutatedFirehose = defaults.overrideProps(destination.kinesisFirehose, {});
Expand All @@ -194,22 +193,9 @@ test('Test fail if existingFirehose does not have a stream name', () => {
expect(app).toThrowError(/existingKinesisFirehose must have a defined deliveryStreamName/);
});

function GetTestDestination(scope: Construct, id: string): KinesisFirehoseToS3 {
return new KinesisFirehoseToS3(scope, id, {
bucketProps: {
autoDeleteObjects: true,
removalPolicy: cdk.RemovalPolicy.DESTROY,
},
loggingBucketProps: {
autoDeleteObjects: true,
removalPolicy: cdk.RemovalPolicy.DESTROY
}
});
}

test('Test fail Vpc check with vpcProps yet deployVpc is false', () => {
const stack = new cdk.Stack();
const destination = GetTestDestination(stack, 'test-destination');
const destination = GetTestFirehoseDestination(stack, 'test-destination');

const app = () => {
new LambdaToKinesisFirehose(stack, 'test-target', {
Expand All @@ -232,7 +218,7 @@ test('Test fail Vpc check with vpcProps yet deployVpc is false', () => {

test('Test fail Vpc check with vpcProps yet deployVpc is undefined', () => {
const stack = new cdk.Stack();
const destination = GetTestDestination(stack, 'test-destination');
const destination = GetTestFirehoseDestination(stack, 'test-destination');

const app = () => {
new LambdaToKinesisFirehose(stack, 'test-target', {
Expand Down
Loading

0 comments on commit 982b68c

Please sign in to comment.