Skip to content

Commit

Permalink
Merge branch 'master' into qmg-rbass/comparison-operators
Browse files Browse the repository at this point in the history
  • Loading branch information
NetaNir authored Jun 30, 2020
2 parents 96f0974 + 719cd16 commit af607bf
Show file tree
Hide file tree
Showing 26 changed files with 392 additions and 190 deletions.
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-ec2/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ nyc.config.js
.LAST_PACKAGE
*.snk
!.eslintrc.js

!jest.config.js
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-ec2/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ tsconfig.json
.eslintrc.js

# exclude cdk artifacts
**/cdk.out
**/cdk.out
jest.config.js
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-ec2/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const baseConfig = require('../../../tools/cdk-build-tools/config/jest.config');
module.exports = baseConfig;
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-ec2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"compat": "cdk-compat"
},
"cdk-build": {
"cloudformation": "AWS::EC2"
"cloudformation": "AWS::EC2",
"jest": true
},
"keywords": [
"aws",
Expand All @@ -63,11 +64,10 @@
"license": "Apache-2.0",
"devDependencies": {
"@aws-cdk/assert": "0.0.0",
"@types/nodeunit": "^0.0.31",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"cfn2ts": "0.0.0",
"nodeunit": "^0.11.3",
"nodeunit-shim": "0.0.0",
"pkglint": "0.0.0",
"@aws-cdk/cloud-assembly-schema": "0.0.0"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { expect, haveResource } from '@aws-cdk/assert';
import { Stack } from '@aws-cdk/core';
import { Test } from 'nodeunit';
import { nodeunitShim, Test } from 'nodeunit-shim';
import { BastionHostLinux, BlockDeviceVolume, SubnetType, Vpc } from '../lib';

export = {
nodeunitShim({
'default instance is created in basic'(test: Test) {
// GIVEN
const stack = new Stack();
Expand Down Expand Up @@ -85,4 +85,4 @@ export = {

test.done();
},
};
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, haveResource } from '@aws-cdk/assert';
import { App, ConstructNode, Stack } from '@aws-cdk/core';
import { Test } from 'nodeunit';
import { nodeunitShim, Test } from 'nodeunit-shim';

import {
Connections,
Expand All @@ -10,7 +10,7 @@ import {
Vpc,
} from '../lib';

export = {
nodeunitShim({
'peering between two security groups does not recursive infinitely'(test: Test) {
// GIVEN
const stack = new Stack(undefined, 'TestStack', { env: { account: '12345678', region: 'dummy' }});
Expand Down Expand Up @@ -326,7 +326,7 @@ export = {

test.done();
},
};
});

class SomethingConnectable implements IConnectable {
constructor(public readonly connections: Connections) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { expect, haveResource } from '@aws-cdk/assert';
import { StringParameter } from '@aws-cdk/aws-ssm';
import * as cxschema from '@aws-cdk/cloud-assembly-schema';
import { Stack } from '@aws-cdk/core';
import { Test } from 'nodeunit';
import { nodeunitShim, Test } from 'nodeunit-shim';
import { AmazonLinuxImage, BlockDeviceVolume, EbsDeviceVolumeType, Instance, InstanceClass, InstanceSize, InstanceType, Vpc } from '../lib';

export = {
nodeunitShim({
'instance is created correctly'(test: Test) {
// GIVEN
const stack = new Stack();
Expand Down Expand Up @@ -292,4 +292,4 @@ export = {

test.done();
},
};
});
14 changes: 14 additions & 0 deletions packages/@aws-cdk/aws-ec2/test/l1.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as cdk from '@aws-cdk/core';
import * as ec2 from '../lib';

test('NetworkAclEntry CidrBlock should be optional', () => {
const stack = new cdk.Stack();

new ec2.CfnNetworkAclEntry(stack, 'ACL', {
// Note the conspicuous absence of cidrBlock
networkAclId: 'asdf',
protocol: 5,
ruleAction: 'action',
ruleNumber: 1,
});
});
94 changes: 94 additions & 0 deletions packages/@aws-cdk/aws-ec2/test/machine-image.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { App, Stack } from '@aws-cdk/core';
import * as ec2 from '../lib';

let app: App;
let stack: Stack;

beforeEach(() => {
app = new App();
stack = new Stack(app, 'Stack', {
env: { account: '1234', region: 'testregion' },
});
});

test('can make and use a Windows image', () => {
// WHEN
const image = new ec2.GenericWindowsImage({
testregion: 'ami-1234',
});

// THEN
const details = image.getImage(stack);
expect(details.imageId).toEqual('ami-1234');
expect(details.osType).toEqual(ec2.OperatingSystemType.WINDOWS);
});

test('WindowsImage retains userdata if given', () => {
// WHEN
const ud = ec2.UserData.forWindows();

const image = new ec2.GenericWindowsImage({
testregion: 'ami-1234',
}, {
userData: ud,
});

// THEN
const details = image.getImage(stack);
expect(details.userData).toEqual(ud);
});

test('WindowsImage creates UserData if not given', () => {
// WHEN
const image = new ec2.GenericWindowsImage({
testregion: 'ami-1234',
});

// THEN
const details = image.getImage(stack);
expect(isWindowsUserData(details.userData)).toBeTruthy();
});

test('LookupMachineImage default search', () => {
// GIVEN

// WHEN
new ec2.LookupMachineImage({ name: 'bla*', owners: ['amazon'] }).getImage(stack);

// THEN
const missing = app.synth().manifest.missing || [];
expect(missing).toEqual([
{
key: 'ami:account=1234:filters.image-type.0=machine:filters.name.0=bla*:filters.state.0=available:owners.0=amazon:region=testregion',
props: {
account: '1234',
region: 'testregion',
owners: [ 'amazon' ],
filters: {
'name': [ 'bla*' ],
'state': [ 'available' ],
'image-type': [ 'machine' ],
},
},
provider: 'ami',
},
]);
});

test('LookupMachineImage creates correct type of UserData', () => {
// WHEN
const linuxDetails = new ec2.LookupMachineImage({ name: 'bla*', owners: ['amazon'] }).getImage(stack);
const windowsDetails = new ec2.LookupMachineImage({ name: 'bla*', owners: ['amazon'], windows: true }).getImage(stack);

// THEN
expect(isWindowsUserData(windowsDetails.userData)).toBeTruthy();
expect(isLinuxUserData(linuxDetails.userData)).toBeTruthy();
});

function isWindowsUserData(ud: ec2.UserData) {
return ud.render().indexOf('powershell') > -1;
}

function isLinuxUserData(ud: ec2.UserData) {
return ud.render().indexOf('bash') > -1;
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { Test } from 'nodeunit';
import { nodeunitShim, Test } from 'nodeunit-shim';
import {
CidrBlock,
InvalidCidrRangeError,
NetworkBuilder,
NetworkUtils,
} from '../lib/network-util';

export = {

nodeunitShim({
IP: {
'should convert a valid IP Address to an integer'(test: Test) {
test.strictEqual(NetworkUtils.ipToNum('174.66.173.168'), 2923605416);
Expand All @@ -16,7 +15,7 @@ export = {
'should throw on invalid IP Address'(test: Test) {
test.throws(() => {
NetworkUtils.ipToNum('174.266.173.168');
}, Error, 'is not valid');
}, 'is not valid');
test.done();
},
'should convert a valid IP integer to a staring'(test: Test) {
Expand Down Expand Up @@ -188,4 +187,4 @@ export = {
test.strictEqual(18, builder5.maskForRemainingSubnets(3)); test.done();
},
},
};
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { expect, haveResource, not } from '@aws-cdk/assert';
import { Intrinsic, Lazy, Stack, Token } from '@aws-cdk/core';
import { Test } from 'nodeunit';
import { nodeunitShim, Test } from 'nodeunit-shim';
import { Peer, Port, SecurityGroup, Vpc } from '../lib';

export = {
nodeunitShim({
'security group can allows all outbound traffic by default'(test: Test) {
// GIVEN
const stack = new Stack();
Expand Down Expand Up @@ -293,4 +293,4 @@ export = {
test.done();
},
},
};
});
19 changes: 0 additions & 19 deletions packages/@aws-cdk/aws-ec2/test/test.l1.ts

This file was deleted.

107 changes: 0 additions & 107 deletions packages/@aws-cdk/aws-ec2/test/test.machine-image.ts

This file was deleted.

Loading

0 comments on commit af607bf

Please sign in to comment.