Skip to content

Commit 790be7c

Browse files
honor a default $TTL (#27)
1 parent 30f12f8 commit 790be7c

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

packages/google-cloud-dns/src/zone.js

+4
Original file line numberDiff line numberDiff line change
@@ -1003,13 +1003,17 @@ Zone.prototype.import = function(localPath, callback) {
10031003
}
10041004

10051005
var parsedZonefile = zonefile.parse(file);
1006+
var defaultTTL = parsedZonefile.$ttl;
1007+
delete parsedZonefile.$ttl;
1008+
10061009
var recordTypes = Object.keys(parsedZonefile);
10071010
var recordsToCreate = [];
10081011

10091012
recordTypes.forEach(function(recordType) {
10101013
var recordTypeSet = arrify(parsedZonefile[recordType]);
10111014

10121015
recordTypeSet.forEach(function(record) {
1016+
record.ttl = record.ttl || defaultTTL;
10131017
recordsToCreate.push(Record.fromZoneRecord_(self, recordType, record));
10141018
});
10151019
});
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
$TTL 3600
12
{DNS_DOMAIN} 21600 IN SPF "v=spf1" "mx:{DNS_DOMAIN}" "-all"
2-
{DNS_DOMAIN} 21600 IN TXT "google-site-verification=xxxxxxxxxxxxYYYYYYXXX"
3+
{DNS_DOMAIN} IN TXT "google-site-verification=xxxxxxxxxxxxYYYYYYXXX"

packages/google-cloud-dns/test/zone.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -804,9 +804,12 @@ describe('Zone', function() {
804804
describe('success', function() {
805805
var recordType = 'ns';
806806
var parsedZonefile = {};
807-
parsedZonefile[recordType] = {a: 'b', c: 'd'};
808807

809808
beforeEach(function() {
809+
parsedZonefile = {
810+
[recordType]: {a: 'b', c: 'd'},
811+
};
812+
810813
parseOverride = function() {
811814
return parsedZonefile;
812815
};
@@ -834,6 +837,26 @@ describe('Zone', function() {
834837

835838
zone.import(path, done);
836839
});
840+
841+
it('should use the default ttl', function(done) {
842+
var defaultTTL = '90';
843+
844+
parsedZonefile.$ttl = defaultTTL;
845+
parsedZonefile[recordType] = {};
846+
parsedZonefile.mx = {ttl: '180'};
847+
848+
zone.addRecords = function(recordsToCreate) {
849+
var record1 = recordsToCreate[0].calledWith_[2];
850+
assert.strictEqual(record1.ttl, defaultTTL);
851+
852+
var record2 = recordsToCreate[1].calledWith_[2];
853+
assert.strictEqual(record2.ttl, '180');
854+
855+
done();
856+
};
857+
858+
zone.import(path, done);
859+
});
837860
});
838861
});
839862

0 commit comments

Comments
 (0)