Skip to content

Commit

Permalink
Update integ tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SoManyHs committed Mar 8, 2019
1 parent 472269f commit ca15e65
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 38 deletions.
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-servicediscovery/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"devDependencies": {
"@aws-cdk/assert": "^0.25.2",
"cdk-build-tools": "^0.25.2",
"cdk-integ-tools": "^0.25.2",
"cfn2ts": "^0.25.2",
"pkglint": "^0.25.2"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"Resources": {
"Namespace9B63B8C8": {
"Type": "AWS::ServiceDiscovery::PublicDnsNamespace",
"Properties": {
"Name": "foobar.com"
}
},
"NamespaceServiceCABDF534": {
"Type": "AWS::ServiceDiscovery::Service",
"Properties": {
"DnsConfig": {
"DnsRecords": [
{
"TTL": "30",
"Type": "CNAME"
}
],
"NamespaceId": {
"Fn::GetAtt": [
"Namespace9B63B8C8",
"Id"
]
},
"RoutingPolicy": "WEIGHTED"
},
"Name": "foo",
"NamespaceId": {
"Fn::GetAtt": [
"Namespace9B63B8C8",
"Id"
]
}
}
},
"NamespaceServicemyInstanceECEB093F": {
"Type": "AWS::ServiceDiscovery::Instance",
"Properties": {
"InstanceAttributes": {
"AWS_INSTANCE_CNAME": "service.pizza"
},
"ServiceId": {
"Fn::GetAtt": [
"NamespaceServiceCABDF534",
"Id"
]
},
"InstanceId": "myInstance"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import cdk = require('@aws-cdk/cdk');
import servicediscovery = require('../lib');

const app = new cdk.App();
const stack = new cdk.Stack(app, 'aws-servicediscovery-integ');

const namespace = new servicediscovery.PublicDnsNamespace(stack, 'Namespace', {
name: 'foobar.com',
});

const service = namespace.createService('Service', {
name: 'foo',
dnsRecordType: servicediscovery.DnsRecordType.Cname,
dnsTtlSec: 30
});

service.registerCnameInstance({
instanceId: 'myInstance',
instanceCname: 'service.pizza',
});

app.run();
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ const service = namespace.createService('Service', {
});

service.registerNonIpInstance({
instanceId: "api",
customAttributes: { "arn": "arn:aws:s3:::mybucket" }
instanceId: 'api',
customAttributes: { arn: 'arn:aws:s3:::mybucket' }
});

app.run();

Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ const stack = new cdk.Stack(app, 'aws-servicediscovery-integ');
const vpc = new ec2.VpcNetwork(stack, 'Vpc', { maxAZs: 2 });

const namespace = new servicediscovery.PrivateDnsNamespace(stack, 'Namespace', {
name: "boobar.com",
name: 'boobar.com',
vpc,
});

const service = namespace.createService('Service', {
name: "boo",
name: 'boo',
dnsRecordType: servicediscovery.DnsRecordType.A_AAAA,
dnsTtlSec: 30,
loadBalancer: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ const app = new cdk.App();
const stack = new cdk.Stack(app, 'aws-servicediscovery-integ');

const namespace = new servicediscovery.PublicDnsNamespace(stack, 'Namespace', {
name: "foobar.com",
name: 'foobar.com',
});

const service = namespace.createService('Service', {
name: "foo",
name: 'foo',
dnsRecordType: servicediscovery.DnsRecordType.A,
dnsTtlSec: 30,
healthCheckConfig: {
Expand All @@ -20,7 +20,7 @@ const service = namespace.createService('Service', {
});

service.registerIpInstance({
instanceId: "myInstance",
instanceId: 'myInstance',
ipv4: '54.239.25.192',
port: 443
});
Expand Down
60 changes: 30 additions & 30 deletions packages/@aws-cdk/aws-servicediscovery/test/test.instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export = {
});

service.registerIpInstance({
instanceId: "myInstance",
instanceId: 'myInstance',
ipv4: '10.0.0.0',
ipv6: '0:0:0:0:0:ffff:a00:0',
port: 443
Expand All @@ -28,17 +28,17 @@ export = {
// THEN
expect(stack).to(haveResource('AWS::ServiceDiscovery::Instance', {
InstanceAttributes: {
AWS_INSTANCE_IPV4: "10.0.0.0",
AWS_INSTANCE_IPV6: "0:0:0:0:0:ffff:a00:0",
AWS_INSTANCE_PORT: "443"
AWS_INSTANCE_IPV4: '10.0.0.0',
AWS_INSTANCE_IPV6: '0:0:0:0:0:ffff:a00:0',
AWS_INSTANCE_PORT: '443'
},
ServiceId: {
"Fn::GetAtt": [
"MyNamespaceMyService365E2470",
"Id"
'Fn::GetAtt': [
'MyNamespaceMyService365E2470',
'Id'
]
},
InstanceId: "myInstance"
InstanceId: 'myInstance'
}));

test.done();
Expand Down Expand Up @@ -99,7 +99,7 @@ export = {
});

service.registerIpInstance({
instanceId: "myInstance",
instanceId: 'myInstance',
ipv4: '10.0.0.0',
ipv6: '0:0:0:0:0:ffff:a00:0',
port: 443
Expand All @@ -108,17 +108,17 @@ export = {
// THEN
expect(stack).to(haveResource('AWS::ServiceDiscovery::Instance', {
InstanceAttributes: {
AWS_INSTANCE_IPV4: "10.0.0.0",
AWS_INSTANCE_IPV6: "0:0:0:0:0:ffff:a00:0",
AWS_INSTANCE_PORT: "443"
AWS_INSTANCE_IPV4: '10.0.0.0',
AWS_INSTANCE_IPV6: '0:0:0:0:0:ffff:a00:0',
AWS_INSTANCE_PORT: '443'
},
ServiceId: {
"Fn::GetAtt": [
"MyNamespaceMyService365E2470",
"Id"
'Fn::GetAtt': [
'MyNamespaceMyService365E2470',
'Id'
]
},
InstanceId: "myInstance"
InstanceId: 'myInstance'
}));

test.done();
Expand Down Expand Up @@ -243,20 +243,20 @@ export = {
expect(stack).to(haveResource('AWS::ServiceDiscovery::Instance', {
InstanceAttributes: {
AWS_ALIAS_DNS_NAME: {
"Fn::GetAtt": [
"MyALB911A8556",
"DNSName"
'Fn::GetAtt': [
'MyALB911A8556',
'DNSName'
]
},
foo: "bar"
foo: 'bar'
},
ServiceId: {
"Fn::GetAtt": [
"MyNamespaceMyService365E2470",
"Id"
'Fn::GetAtt': [
'MyNamespaceMyService365E2470',
'Id'
]
},
InstanceId: "MyLoadBalancer"
InstanceId: 'MyLoadBalancer'
}));

test.done();
Expand Down Expand Up @@ -324,14 +324,14 @@ export = {
service.registerCnameInstance({
instanceId: 'cnameInstance',
instanceCname: 'foo.com',
customAttributes: { 'dogs': 'good' }
customAttributes: { dogs: 'good' }
});

// THEN
expect(stack).to(haveResource('AWS::ServiceDiscovery::Instance', {
InstanceAttributes: {
'AWS_INSTANCE_CNAME': "foo.com",
'dogs': 'good'
AWS_INSTANCE_CNAME: 'foo.com',
dogs: 'good'
},
ServiceId: {
'Fn::GetAtt': [
Expand Down Expand Up @@ -380,13 +380,13 @@ export = {

service.registerNonIpInstance({
instanceId: 'nonIp',
customAttributes: { 'dogs': 'good' }
customAttributes: { dogs: 'good' }
});

// THEN
expect(stack).to(haveResource('AWS::ServiceDiscovery::Instance', {
InstanceAttributes: {
'dogs': 'good'
dogs: 'good'
},
ServiceId: {
'Fn::GetAtt': [
Expand All @@ -413,7 +413,7 @@ export = {
// THEN
test.throws(() => {
service.registerNonIpInstance({
instanceId: "nonIp",
instanceId: 'nonIp',
});
}, /This type of instance can only be registered for HTTP namespaces./);

Expand Down

0 comments on commit ca15e65

Please sign in to comment.