Skip to content

Commit

Permalink
test: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
theworkflow committed Sep 9, 2019
1 parent d41b0e3 commit 9b0e1ac
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 0 deletions.
107 changes: 107 additions & 0 deletions test/fixtures/route53records.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{
"A": [
{
"AliasTarget": {
"HostedZoneId": "Z2FDTNDATAQYW2",
"EvaluateTargetHealth": false,
"DNSName": "d1mylymyxdpqdy.cloudfront.net."
},
"Type": "A",
"Name": "olay.com."
},
{
"ResourceRecords": [
{
"Value": "208.70.143.2"
}
],
"Type": "A",
"Name": "canada.olay.com.",
"TTL": 300
}
],
"MX": [
{
"ResourceRecords": [
{
"Value": "10 bbhm.ex.exmaple.com."
}
],
"Type": "MX",
"Name": "example.com.",
"TTL": 300
}
],
"NS": [
{
"ResourceRecords": [
{
"Value": "ns-869.awsdns-44.net."
},
{
"Value": "ns-2018.awsdns-60.co.uk."
},
{
"Value": "ns-54.awsdns-06.com."
},
{
"Value": "ns-1140.awsdns-14.org."
}
],
"Type": "NS",
"Name": "olay.com.",
"TTL": 172800
}
],
"SOA": [
{
"ResourceRecords": [
{
"Value": "ns-869.awsdns-44.net. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400"
}
],
"Type": "SOA",
"Name": "olay.com.",
"TTL": 900
}
],
"TXT": [
{
"ResourceRecords": [
{
"Value": "\"google-site-verification=1tcMSeburb9qdWyNXEbWx17PPOa1JoADJOZ9-iaPlDg\""
},
{
"Value": "\"google-site-verification=B_NPUcdJ9Ncd8JlNXtFW-GfIUdcfGcM3KH5rhnq71RQ\""
},
{
"Value": "\"google-site-verification=pxYiqz1xdJx5anoPJCxBhXt80BPShiqzbeEhwhwCRWQ\""
}
],
"Type": "TXT",
"Name": "olay.com.",
"TTL": 300
}
],
"CNAME": [
{
"AliasTarget": {
"HostedZoneId": "Z2DTRSIKE5XMZF",
"EvaluateTargetHealth": false,
"DNSName": "futureyou.olay.com."
},
"Type": "CNAME",
"Name": "www.futureyou.olay.com."
},
{
"ResourceRecords": [
{
"Value": "_d3272163d1e7b5046236bb47a7f94131.tljzshvwok.acm-validations.aws."
}
],
"Type": "CNAME",
"Name": "_b891f66e4e09a70947ed968f5ae90ea4.olay.com.",
"TTL": 600
}
]
}
Empty file added test/lib/generateZoneFile.js
Empty file.
85 changes: 85 additions & 0 deletions test/lib/getRecordSets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
const { expect } = require('code')
const lab = require('lab')
const sinon = require('sinon')

const AWS = require('aws-sdk')

const client = require('../../lib/getRecordSets')

const { afterEach, before, describe, it } = exports.lab = lab.script()
const listStub = sinon.stub()
const getStub = sinon.stub()

describe('lib/getRecordSets', () => {
const options = {
zoneId: 'fakeZoneId',
ttl: 3600
}
const awsConfig = { test: true }

before(() => {
sinon.stub(AWS, 'Route53').returns({
listResourceRecordSets: listStub,
getHostedZone: getStub
})
})

afterEach(() => {
listStub.reset()
getStub.reset()
})

it('should fail if getting hosted zone data fails', async () => {
let error
getStub.yields(new Error('get hosted zone error'))

try {
await client(options, awsConfig)
} catch (err) {
error = err
}

expect(error.message).to.equal('get hosted zone error')
expect(listStub.called).to.equal(false)
})

it('should fail if listing resources fails', async () => {
let error
getStub.yields(null, { Name: 'example.com' })
listStub.yields(new Error('list resources error'))

try {
await client(options, awsConfig)
} catch (err) {
error = err
}

expect(getStub.callCount).to.equal(1)
expect(error.message).to.equal('list resources error')
})

it('should succeed', async () => {
let error, res
getStub.yields(null, { Name: 'example.com' })
listStub.yields(null, { ResourceRecordSets: [] })

try {
res = await client(options, awsConfig)
} catch (err) {
error = err
}

const listCall = listStub.getCall(0)
const getCall = getStub.getCall(0)

expect(error).to.not.exist()
expect(res).to.equal({
origin: 'example.com',
recordSets: []
})
expect(getStub.callCount).to.equal(1)
expect(listStub.callCount).to.equal(1)
expect(getCall.args[0]).to.equal({ Id: 'fakeZoneId' })
expect(listCall.args[0]).to.equal({ HostedZoneId: 'fakeZoneId' })
})
})

0 comments on commit 9b0e1ac

Please sign in to comment.