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

TESTING: parse_tests files should be uniformly formatted and sorted #3272

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
19 changes: 10 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions pkg/js/README-parse_tests.md
Original file line number Diff line number Diff line change
@@ -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
```
21 changes: 16 additions & 5 deletions pkg/js/js_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{}
Expand Down Expand Up @@ -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")
Expand Down
9 changes: 4 additions & 5 deletions pkg/js/parse_tests/001-basic.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

var REG = NewRegistrar("Third-Party","NONE");
var REG = NewRegistrar("Third-Party", "NONE");
var CF = NewDnsProvider("Cloudflare", "CLOUDFLAREAPI");

D("foo.com",REG,DnsProvider(CF),
A("@","1.2.3.4")
);
D("foo.com", REG, DnsProvider(CF),
A("@", "1.2.3.4")
);
57 changes: 31 additions & 26 deletions pkg/js/parse_tests/001-basic.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
{
"registrars": [
"dns_providers": [
{
"name": "Cloudflare",
"type": "CLOUDFLAREAPI"
}
],
"domains": [
{
"dnsProviders": {
"Cloudflare": -1
},
"meta": {
"dnscontrol_tag": "",
"dnscontrol_uniquename": "foo.com"
},
"name": "foo.com",
"records": [
{
"name": "Third-Party",
"type": "NONE"
"name": "@",
"target": "1.2.3.4",
"ttl": 300,
"type": "A"
}
],
"dns_providers": [
{
"name": "Cloudflare",
"type": "CLOUDFLAREAPI"
}
],
"domains": [
{
"name": "foo.com",
"registrar": "Third-Party",
"dnsProviders": {
"Cloudflare": -1
},
"records": [
{
"type": "A",
"name": "@",
"target": "1.2.3.4"
}
]
}
]
],
"registrar": "Third-Party"
}
],
"registrars": [
{
"name": "Third-Party",
"type": "NONE"
}
]
}
11 changes: 6 additions & 5 deletions pkg/js/parse_tests/002-ttl.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var REG = NewRegistrar("Third-Party","NONE");
var CF = NewDnsProvider("Cloudflare", "CLOUDFLAREAPI")
D("foo.com",REG,DnsProvider(CF),
A("@","1.2.3.4",TTL(42))
);
var REG = NewRegistrar("Third-Party", "NONE");
var CF = NewDnsProvider("Cloudflare", "CLOUDFLAREAPI");

D("foo.com", REG, DnsProvider(CF),
A("@", "1.2.3.4", TTL(42)),
);
26 changes: 15 additions & 11 deletions pkg/js/parse_tests/002-ttl.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
{
"registrars": [
{
"name": "Third-Party",
"type": "NONE"
}
],
"dns_providers": [
{
"name": "Cloudflare",
Expand All @@ -13,19 +7,29 @@
],
"domains": [
{
"name": "foo.com",
"registrar": "Third-Party",
"dnsProviders": {
"Cloudflare": -1
},
"meta": {
"dnscontrol_tag": "",
"dnscontrol_uniquename": "foo.com"
},
"name": "foo.com",
"records": [
{
"type": "A",
"name": "@",
"target": "1.2.3.4",
"ttl": 42
"ttl": 42,
"type": "A"
}
]
],
"registrar": "Third-Party"
}
],
"registrars": [
{
"name": "Third-Party",
"type": "NONE"
}
]
}
10 changes: 6 additions & 4 deletions pkg/js/parse_tests/003-meta.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var CLOUDFLARE = NewRegistrar("Cloudflare", "CLOUDFLAREAPI");

var CLOUDFLARE = NewRegistrar("Cloudflare","CLOUDFLAREAPI");
D("foo.com",CLOUDFLARE,
A("@","1.2.3.4",{"cloudflare_proxy":"ON"})
);
D("foo.com", CLOUDFLARE,
A("@", "1.2.3.4", {
"cloudflare_proxy": "ON"
}),
);
31 changes: 18 additions & 13 deletions pkg/js/parse_tests/003-meta.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
{
"registrars": [
{
"name": "Cloudflare",
"type": "CLOUDFLAREAPI"
}
],
"dns_providers": [],
"domains": [
{
"name": "foo.com",
"registrar": "Cloudflare",
"dnsProviders": {},
"meta": {
"dnscontrol_tag": "",
"dnscontrol_uniquename": "foo.com"
},
"name": "foo.com",
"records": [
{
"type": "A",
"name": "@",
"target": "1.2.3.4",
"meta": {
"cloudflare_proxy": "ON"
}
},
"name": "@",
"target": "1.2.3.4",
"ttl": 300,
"type": "A"
}
]
],
"registrar": "Cloudflare"
}
],
"registrars": [
{
"name": "Cloudflare",
"type": "CLOUDFLAREAPI"
}
]
}
16 changes: 8 additions & 8 deletions pkg/js/parse_tests/004-ips.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var REG = NewRegistrar("Third-Party","NONE");
var CF = NewDnsProvider("Cloudflare", "CLOUDFLAREAPI")
var REG = NewRegistrar("Third-Party", "NONE");
var CF = NewDnsProvider("Cloudflare", "CLOUDFLAREAPI");

var BASE = IP("1.2.3.4")
var BASE = IP("1.2.3.4");

D("foo.com",REG,DnsProvider(CF,0),
A("@",BASE),
A("p1",BASE+1),
A("p255", BASE+255)
);
D("foo.com", REG, DnsProvider(CF, 0),
A("@", BASE),
A("p1", BASE + 1),
A("p255", BASE + 255),
);
37 changes: 22 additions & 15 deletions pkg/js/parse_tests/004-ips.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
{
"registrars": [
{
"name": "Third-Party",
"type": "NONE"
}
],
"dns_providers": [
{
"name": "Cloudflare",
Expand All @@ -13,28 +7,41 @@
],
"domains": [
{
"name": "foo.com",
"registrar": "Third-Party",
"dnsProviders": {
"Cloudflare": 0
},
"meta": {
"dnscontrol_tag": "",
"dnscontrol_uniquename": "foo.com"
},
"name": "foo.com",
"records": [
{
"type": "A",
"name": "@",
"target": "1.2.3.4"
"target": "1.2.3.4",
"ttl": 300,
"type": "A"
},
{
"type": "A",
"name": "p1",
"target": "1.2.3.5"
"target": "1.2.3.5",
"ttl": 300,
"type": "A"
},
{
"type": "A",
"name": "p255",
"target": "1.2.4.3"
"target": "1.2.4.3",
"ttl": 300,
"type": "A"
}
]
],
"registrar": "Third-Party"
}
],
"registrars": [
{
"name": "Third-Party",
"type": "NONE"
}
]
}
Loading
Loading