Skip to content

Commit

Permalink
added working service network tests
Browse files Browse the repository at this point in the history
  • Loading branch information
clopca committed Jun 28, 2024
1 parent 2886d77 commit d8bfd84
Showing 1 changed file with 44 additions and 19 deletions.
63 changes: 44 additions & 19 deletions test/core/unit/service-network.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { EOL } from 'os';
import * as cdk from 'aws-cdk-lib';
import { Template } from 'aws-cdk-lib/assertions';
import { Vpc } from 'aws-cdk-lib/aws-ec2';
import * as iam from 'aws-cdk-lib/aws-iam';
import { Stream } from 'aws-cdk-lib/aws-kinesis';
import { LogGroup } from 'aws-cdk-lib/aws-logs';
Expand Down Expand Up @@ -51,24 +52,6 @@ describe('Service network', () => {
});
});

test('Service network with service association', () => {
const stack = new cdk.Stack();
const mockService = Service.fromServiceArn(stack, 'MockService', 'arn:aws:vpc-lattice:us-west-2:123456789012:service/svc-12345');

const serviceNetwork = new ServiceNetwork(stack, 'ServiceNetwork', {
name: 'my-service-network',
});

serviceNetwork.associateService(mockService);

Template.fromStack(stack).hasResourceProperties('AWS::VpcLattice::ServiceNetworkServiceAssociation', {
ServiceIdentifier: 'svc-12345',
ServiceNetworkIdentifier: {
'Fn::GetAtt': ['ServiceNetworkEF29AF70', 'Id'],
},
});
});

test('Service network with resource sharing', () => {
const stack = new cdk.Stack();
const serviceNetwork = new ServiceNetwork(stack, 'ServiceNetwork', {
Expand Down Expand Up @@ -203,6 +186,48 @@ describe('Service network', () => {
serviceNetwork.grantAccess([new iam.FederatedPrincipal('cognito-identity.amazonaws.com', {})]);
}).toThrow(/Invalid principal type/);
});

test('Service network with service association', () => {
const stack = new cdk.Stack();
const mockService = Service.fromServiceArn(stack, 'MockService', 'arn:aws:vpc-lattice:us-west-2:123456789012:service/svc-12345');

const serviceNetwork = new ServiceNetwork(stack, 'ServiceNetwork', {
name: 'my-service-network',
});

serviceNetwork.associateService(mockService);

Template.fromStack(stack).hasResourceProperties('AWS::VpcLattice::ServiceNetworkServiceAssociation', {
ServiceIdentifier: 'svc-12345',
ServiceNetworkIdentifier: {
'Fn::GetAtt': ['ServiceNetworkEF29AF70', 'Id'],
},
});
});

test('Service network with VPC association', () => {
const stack = new cdk.Stack();
const vpc = new Vpc(stack, 'VPC', {
vpcName: 'my-vpc',
});

const serviceNetwork = new ServiceNetwork(stack, 'ServiceNetwork', {
name: 'my-service-network',
});

serviceNetwork.associateVPC({
vpc,
});

Template.fromStack(stack).hasResourceProperties('AWS::VpcLattice::ServiceNetworkVpcAssociation', {
ServiceNetworkIdentifier: {
'Fn::GetAtt': ['ServiceNetworkEF29AF70', 'Id'],
},
VpcIdentifier: {
Ref: 'VPCB9E5F0B4',
},
});
});
});

describe('Auth policy validation', () => {
Expand Down Expand Up @@ -377,7 +402,7 @@ describe('Service network', () => {
});
});

describe('Service logging destination validation', () => {
describe('Service network logging destination validation', () => {
test('Service network with logging destination to cloudwatch', () => {
// GIVEN
const stack = new cdk.Stack();
Expand Down

0 comments on commit d8bfd84

Please sign in to comment.