-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(certificatemanager): convert tests to Jest (#9290)
Converted all tests in the module to use Jest instead of nodeunit. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
10 changed files
with
516 additions
and
553 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,5 +14,6 @@ nyc.config.js | |
.LAST_PACKAGE | ||
*.snk | ||
!.eslintrc.js | ||
!jest.config.js | ||
|
||
junit.xml | ||
junit.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,4 +25,5 @@ tsconfig.json | |
|
||
# exclude cdk artifacts | ||
**/cdk.out | ||
junit.xml | ||
junit.xml | ||
jest.config.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
211 changes: 211 additions & 0 deletions
211
packages/@aws-cdk/aws-certificatemanager/test/certificate.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
import '@aws-cdk/assert/jest'; | ||
import * as route53 from '@aws-cdk/aws-route53'; | ||
import { Lazy, Stack } from '@aws-cdk/core'; | ||
import { Certificate, CertificateValidation, ValidationMethod } from '../lib'; | ||
|
||
test('apex domain selection by default', () => { | ||
const stack = new Stack(); | ||
|
||
new Certificate(stack, 'Certificate', { | ||
domainName: 'test.example.com', | ||
}); | ||
|
||
expect(stack).toHaveResource('AWS::CertificateManager::Certificate', { | ||
DomainName: 'test.example.com', | ||
DomainValidationOptions: [{ | ||
DomainName: 'test.example.com', | ||
ValidationDomain: 'example.com', | ||
}], | ||
}); | ||
}); | ||
|
||
test('validation domain can be overridden', () => { | ||
const stack = new Stack(); | ||
|
||
new Certificate(stack, 'Certificate', { | ||
domainName: 'test.example.com', | ||
validationDomains: { | ||
'test.example.com': 'test.example.com', | ||
}, | ||
}); | ||
|
||
expect(stack).toHaveResource('AWS::CertificateManager::Certificate', { | ||
DomainValidationOptions: [{ | ||
DomainName: 'test.example.com', | ||
ValidationDomain: 'test.example.com', | ||
}], | ||
}); | ||
}); | ||
|
||
test('export and import', () => { | ||
// GIVEN | ||
const stack = new Stack(); | ||
|
||
// WHEN | ||
const c = Certificate.fromCertificateArn(stack, 'Imported', 'cert-arn'); | ||
|
||
// THEN | ||
expect(c.certificateArn).toBe('cert-arn'); | ||
}); | ||
|
||
test('can configure validation method', () => { | ||
const stack = new Stack(); | ||
|
||
new Certificate(stack, 'Certificate', { | ||
domainName: 'test.example.com', | ||
validationMethod: ValidationMethod.DNS, | ||
}); | ||
|
||
expect(stack).toHaveResource('AWS::CertificateManager::Certificate', { | ||
DomainName: 'test.example.com', | ||
ValidationMethod: 'DNS', | ||
}); | ||
}); | ||
|
||
test('needs validation domain supplied if domain contains a token', () => { | ||
const stack = new Stack(); | ||
|
||
expect(() => { | ||
const domainName = Lazy.stringValue({ produce: () => 'example.com' }); | ||
new Certificate(stack, 'Certificate', { | ||
domainName, | ||
}); | ||
}).toThrow(/'validationDomains' needs to be supplied/); | ||
}); | ||
|
||
test('validationdomains can be given for a Token', () => { | ||
const stack = new Stack(); | ||
|
||
const domainName = Lazy.stringValue({ produce: () => 'my.example.com' }); | ||
new Certificate(stack, 'Certificate', { | ||
domainName, | ||
validationDomains: { | ||
[domainName]: 'example.com', | ||
}, | ||
}); | ||
|
||
expect(stack).toHaveResource('AWS::CertificateManager::Certificate', { | ||
DomainName: 'my.example.com', | ||
DomainValidationOptions: [{ | ||
DomainName: 'my.example.com', | ||
ValidationDomain: 'example.com', | ||
}], | ||
}); | ||
}); | ||
|
||
test('CertificateValidation.fromEmail', () => { | ||
const stack = new Stack(); | ||
|
||
new Certificate(stack, 'Certificate', { | ||
domainName: 'test.example.com', | ||
subjectAlternativeNames: ['extra.example.com'], | ||
validation: CertificateValidation.fromEmail({ | ||
'test.example.com': 'example.com', | ||
}), | ||
}); | ||
|
||
expect(stack).toHaveResource('AWS::CertificateManager::Certificate', { | ||
DomainName: 'test.example.com', | ||
SubjectAlternativeNames: ['extra.example.com'], | ||
DomainValidationOptions: [ | ||
{ | ||
DomainName: 'test.example.com', | ||
ValidationDomain: 'example.com', | ||
}, | ||
{ | ||
DomainName: 'extra.example.com', | ||
ValidationDomain: 'example.com', | ||
}, | ||
], | ||
ValidationMethod: 'EMAIL', | ||
}); | ||
}); | ||
|
||
test('CertificateValidation.fromDns', () => { | ||
const stack = new Stack(); | ||
|
||
new Certificate(stack, 'Certificate', { | ||
domainName: 'test.example.com', | ||
subjectAlternativeNames: ['extra.example.com'], | ||
validation: CertificateValidation.fromDns(), | ||
}); | ||
|
||
expect(stack).toHaveResource('AWS::CertificateManager::Certificate', { | ||
DomainName: 'test.example.com', | ||
SubjectAlternativeNames: ['extra.example.com'], | ||
ValidationMethod: 'DNS', | ||
}); | ||
}); | ||
|
||
test('CertificateValidation.fromDns with hosted zone', () => { | ||
const stack = new Stack(); | ||
|
||
const exampleCom = new route53.HostedZone(stack, 'ExampleCom', { | ||
zoneName: 'example.com', | ||
}); | ||
|
||
new Certificate(stack, 'Certificate', { | ||
domainName: 'test.example.com', | ||
validation: CertificateValidation.fromDns(exampleCom), | ||
}); | ||
|
||
expect(stack).toHaveResource('AWS::CertificateManager::Certificate', { | ||
DomainName: 'test.example.com', | ||
DomainValidationOptions: [ | ||
{ | ||
DomainName: 'test.example.com', | ||
HostedZoneId: { | ||
Ref: 'ExampleCom20E1324B', | ||
}, | ||
}, | ||
], | ||
ValidationMethod: 'DNS', | ||
}); | ||
}); | ||
|
||
test('CertificateValidation.fromDnsMultiZone', () => { | ||
const stack = new Stack(); | ||
|
||
const exampleCom = new route53.HostedZone(stack, 'ExampleCom', { | ||
zoneName: 'example.com', | ||
}); | ||
|
||
const exampleNet = new route53.HostedZone(stack, 'ExampleNet', { | ||
zoneName: 'example.com', | ||
}); | ||
|
||
new Certificate(stack, 'Certificate', { | ||
domainName: 'test.example.com', | ||
subjectAlternativeNames: ['cool.example.com', 'test.example.net'], | ||
validation: CertificateValidation.fromDnsMultiZone({ | ||
'test.example.com': exampleCom, | ||
'cool.example.com': exampleCom, | ||
'test.example.net': exampleNet, | ||
}), | ||
}); | ||
|
||
expect(stack).toHaveResource('AWS::CertificateManager::Certificate', { | ||
DomainName: 'test.example.com', | ||
DomainValidationOptions: [ | ||
{ | ||
DomainName: 'test.example.com', | ||
HostedZoneId: { | ||
Ref: 'ExampleCom20E1324B', | ||
}, | ||
}, | ||
{ | ||
DomainName: 'cool.example.com', | ||
HostedZoneId: { | ||
Ref: 'ExampleCom20E1324B', | ||
}, | ||
}, | ||
{ | ||
DomainName: 'test.example.net', | ||
HostedZoneId: { | ||
Ref: 'ExampleNetF7CA40C9', | ||
}, | ||
}, | ||
], | ||
ValidationMethod: 'DNS', | ||
}); | ||
}); |
Oops, something went wrong.