Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mrgrain committed Sep 27, 2022
1 parent dbd579c commit 12ad5ba
Show file tree
Hide file tree
Showing 12 changed files with 1,380 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import * as cdk from '@aws-cdk/core';
import { IntegTest, ExpectedResult, Match } from '@aws-cdk/integ-tests';
import { Construct } from 'constructs';
import * as ssm from '../lib';
const paramName = 'integ-list-param';
const paramValue = ['value1', 'value2'];

class TestCaseBase extends cdk.Stack {
public readonly listParam: ssm.IStringListParameter;
constructor(scope: Construct, id: string) {
super(scope, id);

this.listParam = new ssm.StringListParameter(this, 'ListParam', {
parameterName: paramName,
stringListValue: paramValue,
});
}
}


const app = new cdk.App({
treeMetadata: false,
});
/**
* This test case is to verify the previous behavior of the @aws-cdk/aws-ssm:importParameterAsDynamicReference Feature Flag
*/
app.node.setContext('@aws-cdk/aws-ssm:importParameterAsDynamicReference', false);
app.node.setContext('@aws-cdk/core:newStyleStackSynthesis', true);
const base = new TestCaseBase(app, 'base');
const testCase = new cdk.Stack(app, 'list-param');

// creates the dependency between stacks
new cdk.CfnOutput(testCase, 'Output', {
value: cdk.Fn.join(',', base.listParam.stringListValue),
});


/**
* get the value from the `base` stack and then write it to a new parameter
* We will then assert that the value that is written is the correct value
* This validates that the `fromXXX` and `valueForXXX` imports the value correctly
*/

const fromAttrs = ssm.StringListParameter.fromListParameterAttributes(testCase, 'FromAttrs', {
parameterName: paramName,
elementType: ssm.ParameterValueType.STRING,
});
const ssmAttrsValue = new ssm.CfnParameter(testCase, 'attrs-test', {
type: 'StringList',
value: cdk.Fn.join(',', fromAttrs.stringListValue),
});

const value = ssm.StringListParameter.valueForTypedListParameter(testCase, paramName, ssm.ParameterValueType.STRING);
const ssmValue = new ssm.CfnParameter(testCase, 'value-test', {
type: 'StringList',
value: cdk.Fn.join(',', value),
});

const versionValue = ssm.StringListParameter.valueForTypedListParameter(testCase, paramName, ssm.ParameterValueType.STRING, 1);
const ssmVersionValue = new ssm.CfnParameter(testCase, 'version-value-test', {
type: 'StringList',
value: cdk.Fn.join(',', versionValue),
});


const integ = new IntegTest(app, 'ssm-string-param', {
testCases: [
testCase,
],
});

// list the parameters
const actualAttrs = integ.assertions.awsApiCall('SSM', 'getParameters', {
Names: [ssmVersionValue.ref, ssmValue.ref, ssmAttrsValue.ref],
});

actualAttrs.expect(ExpectedResult.objectLike({
Parameters: Match.arrayWith([
Match.objectLike({
Value: paramValue.join(','),
}),
Match.objectLike({
Value: paramValue.join(','),
}),
Match.objectLike({
Value: paramValue.join(','),
}),
]),
}));
4 changes: 4 additions & 0 deletions packages/@aws-cdk/aws-ssm/test/integ.list-parameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class TestCaseBase extends cdk.Stack {
const app = new cdk.App({
treeMetadata: false,
});
/**
* This test case is to verify the current behavior of the @aws-cdk/aws-ssm:importParameterAsDynamicReference Feature Flag
*/
app.node.setContext('@aws-cdk/aws-ssm:importParameterAsDynamicReference', true);
app.node.setContext('@aws-cdk/core:newStyleStackSynthesis', true);
const base = new TestCaseBase(app, 'base');
const testCase = new cdk.Stack(app, 'list-param');
Expand Down
Loading

0 comments on commit 12ad5ba

Please sign in to comment.