Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(eks-legacy): migrate tests to assertions #18596

Merged
merged 2 commits into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-eks-legacy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
},
"license": "Apache-2.0",
"devDependencies": {
"@aws-cdk/assert-internal": "0.0.0",
"@aws-cdk/assertions": "0.0.0",
"@aws-cdk/cdk-build-tools": "0.0.0",
"@aws-cdk/cdk-integ-tools": "0.0.0",
"@aws-cdk/cfn2ts": "0.0.0",
Expand Down
12 changes: 6 additions & 6 deletions packages/@aws-cdk/aws-eks-legacy/test/awsauth.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import '@aws-cdk/assert-internal/jest';
import { describeDeprecated } from '@aws-cdk/cdk-build-tools';
import { Template } from '@aws-cdk/assertions';
import * as iam from '@aws-cdk/aws-iam';
import { describeDeprecated } from '@aws-cdk/cdk-build-tools';
import { Cluster, KubernetesResource } from '../lib';
import { AwsAuth } from '../lib/aws-auth';
import { testFixtureNoVpc } from './util';
Expand All @@ -17,7 +17,7 @@ describeDeprecated('awsauth', () => {
new AwsAuth(stack, 'AwsAuth', { cluster });

// THEN
expect(stack).toHaveResource(KubernetesResource.RESOURCE_TYPE, {
Template.fromStack(stack).hasResourceProperties(KubernetesResource.RESOURCE_TYPE, {
Manifest: JSON.stringify([{
apiVersion: 'v1',
kind: 'ConfigMap',
Expand All @@ -44,8 +44,8 @@ describeDeprecated('awsauth', () => {
cluster.awsAuth.addAccount('5566776655');

// THEN
expect(stack).toCountResources(KubernetesResource.RESOURCE_TYPE, 1);
expect(stack).toHaveResource(KubernetesResource.RESOURCE_TYPE, {
Template.fromStack(stack).resourceCountIs(KubernetesResource.RESOURCE_TYPE, 1);
Template.fromStack(stack).hasResourceProperties(KubernetesResource.RESOURCE_TYPE, {
Manifest: {
'Fn::Join': [
'',
Expand Down Expand Up @@ -106,7 +106,7 @@ describeDeprecated('awsauth', () => {
cluster.awsAuth.addUserMapping(user, { groups: ['group2'] });

// THEN
expect(stack).toHaveResource(KubernetesResource.RESOURCE_TYPE, {
Template.fromStack(stack).hasResourceProperties(KubernetesResource.RESOURCE_TYPE, {
Manifest: {
'Fn::Join': [
'',
Expand Down
42 changes: 21 additions & 21 deletions packages/@aws-cdk/aws-eks-legacy/test/cluster.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '@aws-cdk/assert-internal/jest';
import { Template } from '@aws-cdk/assertions';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as iam from '@aws-cdk/aws-iam';
import { describeDeprecated } from '@aws-cdk/cdk-build-tools';
Expand All @@ -18,7 +18,7 @@ describeDeprecated('cluster', () => {
new eks.Cluster(stack, 'Cluster', { vpc, kubectlEnabled: false, defaultCapacity: 0 });

// THEN
expect(stack).toHaveResourceLike('AWS::EKS::Cluster', {
Template.fromStack(stack).hasResourceProperties('AWS::EKS::Cluster', {
ResourcesVpcConfig: {
SubnetIds: [
{ Ref: 'VPCPublicSubnet1SubnetB4246D30' },
Expand All @@ -40,7 +40,7 @@ describeDeprecated('cluster', () => {
new eks.Cluster(stack, 'cluster');

// THEN
expect(stack).toHaveResource('AWS::EC2::VPC');
Template.fromStack(stack).resourceCountIs('AWS::EC2::VPC', 1);

});

Expand All @@ -55,8 +55,8 @@ describeDeprecated('cluster', () => {

// THEN
expect(cluster.defaultCapacity).toBeDefined();
expect(stack).toHaveResource('AWS::AutoScaling::AutoScalingGroup', { DesiredCapacity: '2' });
expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { InstanceType: 'm5.large' });
Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::AutoScalingGroup', { DesiredCapacity: '2' });
Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::LaunchConfiguration', { InstanceType: 'm5.large' });

});

Expand All @@ -72,8 +72,8 @@ describeDeprecated('cluster', () => {

// THEN
expect(cluster.defaultCapacity).toBeDefined();
expect(stack).toHaveResource('AWS::AutoScaling::AutoScalingGroup', { DesiredCapacity: '10' });
expect(stack).toHaveResource('AWS::AutoScaling::LaunchConfiguration', { InstanceType: 'm2.xlarge' });
Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::AutoScalingGroup', { DesiredCapacity: '10' });
Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::LaunchConfiguration', { InstanceType: 'm2.xlarge' });

});

Expand All @@ -86,8 +86,8 @@ describeDeprecated('cluster', () => {

// THEN
expect(cluster.defaultCapacity).toBeUndefined();
expect(stack).not.toHaveResource('AWS::AutoScaling::AutoScalingGroup');
expect(stack).not.toHaveResource('AWS::AutoScaling::LaunchConfiguration');
Template.fromStack(stack).resourceCountIs('AWS::AutoScaling::AutoScalingGroup', 0);
Template.fromStack(stack).resourceCountIs('AWS::AutoScaling::LaunchConfiguration', 0);

});
});
Expand All @@ -100,7 +100,7 @@ describeDeprecated('cluster', () => {
new eks.Cluster(stack, 'Cluster', { vpc, kubectlEnabled: false, defaultCapacity: 0 });

// THEN
expect(stack).toHaveResource('AWS::EC2::Subnet', {
Template.fromStack(stack).hasResourceProperties('AWS::EC2::Subnet', {
Tags: [
{ Key: 'aws-cdk:subnet-name', Value: 'Private' },
{ Key: 'aws-cdk:subnet-type', Value: 'Private' },
Expand All @@ -120,7 +120,7 @@ describeDeprecated('cluster', () => {
new eks.Cluster(stack, 'Cluster', { vpc, kubectlEnabled: false, defaultCapacity: 0 });

// THEN
expect(stack).toHaveResource('AWS::EC2::Subnet', {
Template.fromStack(stack).hasResourceProperties('AWS::EC2::Subnet', {
MapPublicIpOnLaunch: true,
Tags: [
{ Key: 'aws-cdk:subnet-name', Value: 'Public' },
Expand All @@ -144,7 +144,7 @@ describeDeprecated('cluster', () => {
});

// THEN
expect(stack).toHaveResource('AWS::AutoScaling::AutoScalingGroup', {
Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::AutoScalingGroup', {
Tags: [
{
Key: { 'Fn::Join': ['', ['kubernetes.io/cluster/', { Ref: 'ClusterEB0386A7' }]] },
Expand Down Expand Up @@ -182,7 +182,7 @@ describeDeprecated('cluster', () => {
new cdk.CfnOutput(stack2, 'ClusterARN', { value: imported.clusterArn });

// THEN
expect(stack2).toMatchTemplate({
Template.fromStack(stack2).templateMatches({
Outputs: {
ClusterARN: {
Value: {
Expand Down Expand Up @@ -216,7 +216,7 @@ describeDeprecated('cluster', () => {
new eks.Cluster(stack, 'Cluster', { vpc, mastersRole: role, defaultCapacity: 0 });

// THEN
expect(stack).toHaveResource(eks.KubernetesResource.RESOURCE_TYPE, {
Template.fromStack(stack).hasResourceProperties(eks.KubernetesResource.RESOURCE_TYPE, {
Manifest: {
'Fn::Join': [
'',
Expand Down Expand Up @@ -247,11 +247,11 @@ describeDeprecated('cluster', () => {
cluster.addResource('manifest2', { bar: 123 }, { boor: [1, 2, 3] });

// THEN
expect(stack).toHaveResource(eks.KubernetesResource.RESOURCE_TYPE, {
Template.fromStack(stack).hasResourceProperties(eks.KubernetesResource.RESOURCE_TYPE, {
Manifest: '[{"foo":123}]',
});

expect(stack).toHaveResource(eks.KubernetesResource.RESOURCE_TYPE, {
Template.fromStack(stack).hasResourceProperties(eks.KubernetesResource.RESOURCE_TYPE, {
Manifest: '[{"bar":123},{"boor":[1,2,3]}]',
});

Expand All @@ -269,7 +269,7 @@ describeDeprecated('cluster', () => {
});

// THEN
expect(stack).toHaveResource(eks.KubernetesResource.RESOURCE_TYPE, {
Template.fromStack(stack).hasResourceProperties(eks.KubernetesResource.RESOURCE_TYPE, {
Manifest: {
'Fn::Join': [
'',
Expand Down Expand Up @@ -302,7 +302,7 @@ describeDeprecated('cluster', () => {
});

// THEN
expect(stack).not.toHaveResource(eks.KubernetesResource.RESOURCE_TYPE);
Template.fromStack(stack).resourceCountIs(eks.KubernetesResource.RESOURCE_TYPE, 0);

});

Expand All @@ -317,7 +317,7 @@ describeDeprecated('cluster', () => {
});

// THEN
expect(stack).not.toHaveResource(eks.KubernetesResource.RESOURCE_TYPE);
Template.fromStack(stack).resourceCountIs(eks.KubernetesResource.RESOURCE_TYPE, 0);

});

Expand Down Expand Up @@ -524,7 +524,7 @@ describeDeprecated('cluster', () => {
});

// THEN
expect(stack).toHaveResource(eks.KubernetesResource.RESOURCE_TYPE, { Manifest: JSON.stringify(spotInterruptHandler()) });
Template.fromStack(stack).hasResourceProperties(eks.KubernetesResource.RESOURCE_TYPE, { Manifest: JSON.stringify(spotInterruptHandler()) });

});

Expand All @@ -540,7 +540,7 @@ describeDeprecated('cluster', () => {
});

// THEN
expect(stack).not.toHaveResource(eks.KubernetesResource.RESOURCE_TYPE);
Template.fromStack(stack).resourceCountIs(eks.KubernetesResource.RESOURCE_TYPE, 0);

});

Expand Down
10 changes: 5 additions & 5 deletions packages/@aws-cdk/aws-eks-legacy/test/helm-chart.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '@aws-cdk/assert-internal/jest';
import { Template } from '@aws-cdk/assertions';
import { describeDeprecated } from '@aws-cdk/cdk-build-tools';
import * as eks from '../lib';
import { testFixtureCluster } from './util';
Expand All @@ -15,7 +15,7 @@ describeDeprecated('helm chart', () => {
new eks.HelmChart(stack, 'MyChart', { cluster, chart: 'chart' });

// THEN
expect(stack).toHaveResource(eks.HelmChart.RESOURCE_TYPE, { Namespace: 'default' });
Template.fromStack(stack).hasResourceProperties(eks.HelmChart.RESOURCE_TYPE, { Namespace: 'default' });

});
test('should have a lowercase default release name', () => {
Expand All @@ -26,7 +26,7 @@ describeDeprecated('helm chart', () => {
new eks.HelmChart(stack, 'MyChart', { cluster, chart: 'chart' });

// THEN
expect(stack).toHaveResource(eks.HelmChart.RESOURCE_TYPE, { Release: 'stackmychartff398361' });
Template.fromStack(stack).hasResourceProperties(eks.HelmChart.RESOURCE_TYPE, { Release: 'stackmychartff398361' });

});
test('should trim the last 63 of the default release name', () => {
Expand All @@ -37,7 +37,7 @@ describeDeprecated('helm chart', () => {
new eks.HelmChart(stack, 'MyChartNameWhichISMostProbablyLongerThenSixtyThreeCharacters', { cluster, chart: 'chart' });

// THEN
expect(stack).toHaveResource(eks.HelmChart.RESOURCE_TYPE, { Release: 'rtnamewhichismostprobablylongerthensixtythreecharactersb800614d' });
Template.fromStack(stack).hasResourceProperties(eks.HelmChart.RESOURCE_TYPE, { Release: 'rtnamewhichismostprobablylongerthensixtythreecharactersb800614d' });

});
test('with values', () => {
Expand All @@ -48,7 +48,7 @@ describeDeprecated('helm chart', () => {
new eks.HelmChart(stack, 'MyChart', { cluster, chart: 'chart', values: { foo: 123 } });

// THEN
expect(stack).toHaveResource(eks.HelmChart.RESOURCE_TYPE, { Values: '{\"foo\":123}' });
Template.fromStack(stack).hasResourceProperties(eks.HelmChart.RESOURCE_TYPE, { Values: '{\"foo\":123}' });

});
});
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-eks-legacy/test/manifest.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '@aws-cdk/assert-internal/jest';
import { Template } from '@aws-cdk/assertions';
import { describeDeprecated } from '@aws-cdk/cdk-build-tools';
import { Cluster, KubernetesResource } from '../lib';
import { testFixtureNoVpc } from './util';
Expand Down Expand Up @@ -69,7 +69,7 @@ describeDeprecated('manifest', () => {
manifest,
});

expect(stack).toHaveResource(KubernetesResource.RESOURCE_TYPE, {
Template.fromStack(stack).hasResourceProperties(KubernetesResource.RESOURCE_TYPE, {
Manifest: JSON.stringify(manifest),
});

Expand Down