Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable windows testing #13

Merged
merged 6 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

strategy:
matrix:
os: [ ubuntu-latest, macos-latest ]
os: [ ubuntu-latest, macos-latest, windows-latest ]
node-version: [ 14, 16 ]
fail-fast: false

Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
#### 1.N.N - YYYY-MM-DD


- test: add windows CI testing
- test(bind): replace implicit \n with os.EOL
- test(index): add tests for removeChar, stripComment


#### 1.0.0 - 2022-04-25

- fix(dns-zone): update import syntax for ESM RR
Expand Down
4 changes: 3 additions & 1 deletion lib/bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export async function parseZoneFile (str, implicitOrigin) {
}

const match = line.match(re.zoneRR)
if (!match) throw new Error(`parse failure during line:\n\t${line}`)
if (!match) throw new Error(`parse failure during line:${os.EOL}\t${line}`)

const [ owner, ttl, c, type, rdata ] = match.slice(1)
const iterRR = {
Expand All @@ -68,6 +68,7 @@ export async function parseZoneFile (str, implicitOrigin) {
iterRR.rdata = dz.removeChar(iterRR.rdata, '"', '(').trim()

if (dz.hasUnquoted(iterRR.rdata, '"', ')')) {
// this is a single line continuation, see also resumeContinuation
iterRR.rdata = dz.removeChar(iterRR.rdata, '"', ')').trim()
res.push(parseRR(iterRR))
continue
Expand Down Expand Up @@ -98,6 +99,7 @@ function resumeContinuation (line, rrWIP, res) {
// opened, the closing paren will end the RR's rdata
if (dz.hasUnquoted(line, '"', ')')) { // last line of this RR
rrWIP.rdata += dz.removeChar(line, '"', ')')
rrWIP.rdata = rrWIP.rdata.replace(/[\s]+/g, ' ') // flatten whitespace
res.push(parseRR(rrWIP))
Object.keys(rrWIP).map(k => delete rrWIP[k])
}
Expand Down
8 changes: 1 addition & 7 deletions test/bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,7 @@ describe('bind', function () {
})

it(`parses SOA`, async () => {
const r = await bind.parseZoneFile(`example.com. 86400 IN SOA ns1.example.com. hostmaster.example.com. (
2021102100 ; serial
16384 ; refresh
2048 ; retry
604800 ; expiry
2560 ; minimum
)${os.EOL}`)
const r = await bind.parseZoneFile(`example.com. 86400 IN SOA ns1.example.com. hostmaster.example.com. (${os.EOL}\t\t2021102100 ; serial${os.EOL}\t\t16384 ; refresh${os.EOL}\t\t2048 ; retry${os.EOL}\t\t604800 ; expiry${os.EOL}\t\t2560 ; minimum${os.EOL}\t\t) ${os.EOL}`)

// console.dir(r, { depth: null })
assert.deepStrictEqual(r[0], new RR.SOA({
Expand Down
55 changes: 45 additions & 10 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import assert from 'assert'
import os from 'os'

import * as dz from '../index.js'

Expand All @@ -18,18 +19,52 @@ describe('dns-zone', function () {
})
})

const cases = {
'1w2d3h4m5s': 788645,
'1w1d' : 691200,
'1w' : 604800,
'1d' : 86400,
'2h' : 7200,
'1m' : 60,
'3600' : 3600,
'4500s' : 4500,
}
describe('removeChar', function () {
const removeCases = [
[ 'this ( has opening paran', '"', '(', 'this has opening paran' ],
[ 'this ) has closing paran', '"', ')', 'this has closing paran' ],
]

for (const c of removeCases) {
it(`removes unquoted chacter ${c[2]}`, function () {
assert.equal(dz.removeChar(c[0], c[1], c[2]), c[3])
})
}

const remainCases = [
[ 'this "(" quoted open remains', '"', '(', 'this "(" quoted open remains' ],
[ 'this ")" quoted open remains', '"', ')', 'this ")" quoted open remains' ],
]

for (const c of remainCases) {
it(`retains quoted char ${c[2]}`, function () {
assert.equal(dz.removeChar(c[0], c[1], c[2]), c[3])
})
}
})

describe('stripCommment', function () {
it('removes a trailing comment', async function () {
assert.equal(dz.stripComment('This line has a ; trailing comment', '"', ';'), 'This line has a ')
})

it('removes multiline comments', async function () {
assert.equal(dz.stripComment(`This line has a ; trailing comment${os.EOL}and so too does ;this one${os.EOL}`, '"', ';'), 'This line has a ')
})
})

describe('toSeconds', function () {
const cases = {
'1w2d3h4m5s': 788645,
'1w1d' : 691200,
'1w' : 604800,
'1d' : 86400,
'2h' : 7200,
'1m' : 60,
'3600' : 3600,
'4500s' : 4500,
}

for (const c in cases) {
it(`converts ${c} to ${cases[c]} seconds`, function () {
assert.equal(dz.toSeconds(c), cases[c])
Expand Down