mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-10-29 07:26:22 +08:00
TESTING: parse_tests: Generate post-processed json files
This commit is contained in:
parent
e664daea53
commit
e2325014de
3 changed files with 60 additions and 5 deletions
42
pkg/js/README-parse_tests.md
Normal file
42
pkg/js/README-parse_tests.md
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
|
||||
# Parse Tests
|
||||
|
||||
The `parse_tests` directory contains test cases for `js_test.go`. `js_test.go`
|
||||
scans for files named `DDD-*.js` where `DDD` is a three-digit number.
|
||||
|
||||
* `parse_tests/001-basic.js` -- The dnsconfig.js file.
|
||||
* `parse_tests/001-basic.json` -- The EXPECTED output of "print-ir" for the `.js` file.
|
||||
* `parse_tests/001-basic.json.ACTUAL` -- The ACTUAL output of "print-ir" for the `.js` file (not saved in git)
|
||||
* `parse_tests/001-basic/foo.com.zone` -- Zonefiles from the domains mentioned in dnsconfig.js
|
||||
|
||||
NOTE: The zonefiles are only tested if a matching `DDD-name/DOMAINNAME.zone` file exists.
|
||||
|
||||
Any files committed to Git should be in standard format.
|
||||
|
||||
# Fix formatting
|
||||
|
||||
Fix the `.js` formatting:
|
||||
|
||||
```
|
||||
cd parse_tests
|
||||
for i in *.js ; do echo ========== $i ; dnscontrol fmt -i $i -o $i ; done
|
||||
```
|
||||
|
||||
Fix the `.json` formatting:
|
||||
|
||||
```
|
||||
cd parse_tests
|
||||
fmtjson *.json *.json.ACTUAL
|
||||
```
|
||||
|
||||
# Copy actuals to expected.
|
||||
|
||||
Back-port the ACTUAL results to the expected results:
|
||||
|
||||
(This is dangerous. You may be committing buggy results to the "expected" files. Carefully inspect the resulting PR.)
|
||||
|
||||
```
|
||||
cd parse_tests
|
||||
fmtjson *.json *.json.ACTUAL
|
||||
for i in *.ACTUAL ; do f=$(basename $i .ACTUAL) ; cp $i $f ; done
|
||||
```
|
||||
|
|
@ -9,6 +9,7 @@ import (
|
|||
"testing"
|
||||
"unicode"
|
||||
|
||||
"github.com/StackExchange/dnscontrol/v4/models"
|
||||
"github.com/StackExchange/dnscontrol/v4/pkg/normalize"
|
||||
"github.com/StackExchange/dnscontrol/v4/pkg/prettyzone"
|
||||
"github.com/StackExchange/dnscontrol/v4/providers"
|
||||
|
|
@ -49,6 +50,21 @@ func TestParsedFiles(t *testing.T) {
|
|||
// normalize.UpdateNameSplitHorizon(dc)
|
||||
// }
|
||||
|
||||
errs := normalize.ValidateAndNormalizeConfig(conf)
|
||||
if len(errs) != 0 {
|
||||
t.Fatal(errs[0])
|
||||
}
|
||||
|
||||
for _, dc := range conf.Domains {
|
||||
//fmt.Printf("DEBUG: PrettySort: domain=%q #rec=%d\n", dc.Name, len(dc.Records))
|
||||
//fmt.Printf("DEBUG: records = %d %v\n", len(dc.Records), dc.Records)
|
||||
ps := prettyzone.PrettySort(dc.Records, dc.Name, 0, nil)
|
||||
dc.Records = ps.Records
|
||||
if len(dc.Records) == 0 {
|
||||
dc.Records = models.Records{}
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize any DNS providers mentioned.
|
||||
for _, dProv := range conf.DNSProviders {
|
||||
var pcfg = map[string]string{}
|
||||
|
|
@ -91,11 +107,6 @@ func TestParsedFiles(t *testing.T) {
|
|||
|
||||
// For each domain, if there is a zone file, test against it:
|
||||
|
||||
errs := normalize.ValidateAndNormalizeConfig(conf)
|
||||
if len(errs) != 0 {
|
||||
t.Fatal(errs[0])
|
||||
}
|
||||
|
||||
var dCount int
|
||||
for _, dc := range conf.Domains {
|
||||
zoneFile := filepath.Join(testDir, testName, dc.Name+".zone")
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ func (z *ZoneGenData) Less(i, j int) bool {
|
|||
|
||||
// If we are at the apex, use "@" in the sorting.
|
||||
compA, compB := a.NameFQDN, b.NameFQDN
|
||||
//fmt.Printf("DEBUG: LabelLess(%q, %q) = %v %q %q\n", compA, compB, LabelLess(compA, compB), a.Name, b.Name)
|
||||
if compA != compB {
|
||||
if a.Name == "@" {
|
||||
compA = "@"
|
||||
|
|
@ -122,6 +123,7 @@ func (z *ZoneGenData) Less(i, j int) bool {
|
|||
default:
|
||||
// pass through. String comparison is sufficient.
|
||||
}
|
||||
//fmt.Printf("DEBUG: Less %q < %q == %v\n", a.String(), b.String(), a.String() < b.String())
|
||||
return a.String() < b.String()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue