diff --git a/models/dns.go b/models/dns.go index 713b6285e..1c6766b24 100644 --- a/models/dns.go +++ b/models/dns.go @@ -213,7 +213,7 @@ type DomainConfig struct { Metadata map[string]string `json:"meta,omitempty"` Records []*RecordConfig `json:"records"` Nameservers []*Nameserver `json:"nameservers,omitempty"` - KeepUnknown bool `json:"keepunknown"` + KeepUnknown bool `json:"keepunknown,omitempty"` } func (dc *DomainConfig) Copy() (*DomainConfig, error) { diff --git a/pkg/js/js_test.go b/pkg/js/js_test.go index 2bf709eca..609c0c8c2 100644 --- a/pkg/js/js_test.go +++ b/pkg/js/js_test.go @@ -8,7 +8,8 @@ import ( "testing" "unicode" - "github.com/StackExchange/dnscontrol/models" + "github.com/tdewolff/minify" + minjson "github.com/tdewolff/minify/json" ) const ( @@ -30,6 +31,8 @@ func TestParsedFiles(t *testing.T) { if filepath.Ext(f.Name()) != ".js" || !unicode.IsNumber(rune(f.Name()[0])) { continue } + m := minify.New() + m.AddFunc("json", minjson.Minify) t.Run(f.Name(), func(t *testing.T) { content, err := ioutil.ReadFile(filepath.Join(testDir, f.Name())) if err != nil { @@ -43,25 +46,24 @@ func TestParsedFiles(t *testing.T) { if err != nil { t.Fatal(err) } + actualJSON, err = m.Bytes("json", actualJSON) + if err != nil { + t.Fatal(err) + } expectedFile := filepath.Join(testDir, f.Name()[:len(f.Name())-3]+".json") expectedData, err := ioutil.ReadFile(expectedFile) if err != nil { t.Fatal(err) } - conf = &models.DNSConfig{} - //unmarshal and remarshal to not require manual formatting - err = json.Unmarshal(expectedData, conf) - if err != nil { - t.Fatal(err) - } - expectedJSON, err := json.MarshalIndent(conf, "", " ") + + expectedJSON, err := m.String("json", string(expectedData)) if err != nil { t.Fatal(err) } if string(expectedJSON) != string(actualJSON) { t.Error("Expected and actual json don't match") t.Log("Expected:", string(expectedJSON)) - t.Log("Actual:", string(actualJSON)) + t.Log("Actual :", string(actualJSON)) } }) } diff --git a/pkg/js/parse_tests/006-transforms.json b/pkg/js/parse_tests/006-transforms.json index 134aa2f3e..aa3cd7aaa 100644 --- a/pkg/js/parse_tests/006-transforms.json +++ b/pkg/js/parse_tests/006-transforms.json @@ -27,8 +27,7 @@ "transform": "0.0.0.0 ~ 1.1.1.1 ~ 2.2.2.2 ~ ; 1.1.1.1 ~ 2.2.2.2 ~ 3.3.3.3,4.4.4.4,5.5.5.5 ~ ; 1.1.1.1 ~ 2.2.2.2 ~ ~ 3.3.3.3,4.4.4.4,5.5.5.5" } } - ], - "keepunknown": false + ] } ] } \ No newline at end of file diff --git a/pkg/js/parse_tests/007-importTransformTTL.json b/pkg/js/parse_tests/007-importTransformTTL.json index b42526558..b0edac718 100644 --- a/pkg/js/parse_tests/007-importTransformTTL.json +++ b/pkg/js/parse_tests/007-importTransformTTL.json @@ -16,8 +16,7 @@ "transform_table": "0.0.0.0 ~ 1.1.1.1 ~ 2.2.2.2 ~ " } } - ], - "keepunknown": false + ] } ] } \ No newline at end of file diff --git a/pkg/js/parse_tests/008-import.json b/pkg/js/parse_tests/008-import.json index 63e441356..04a91c1ac 100644 --- a/pkg/js/parse_tests/008-import.json +++ b/pkg/js/parse_tests/008-import.json @@ -12,8 +12,7 @@ "name": "@", "target": "1.2.3.4" } - ], - "keepunknown": false + ] } ] } \ No newline at end of file diff --git a/pkg/js/parse_tests/009-reverse.json b/pkg/js/parse_tests/009-reverse.json index d439329a3..f4bf5a87c 100644 --- a/pkg/js/parse_tests/009-reverse.json +++ b/pkg/js/parse_tests/009-reverse.json @@ -6,8 +6,7 @@ "name": "2.1.in-addr.arpa", "registrar": "none", "dnsProviders": {}, - "records": [], - "keepunknown": false + "records": [] } ] } \ No newline at end of file diff --git a/pkg/js/parse_tests/010-alias.json b/pkg/js/parse_tests/010-alias.json index 6b76fa297..fc59bed03 100644 --- a/pkg/js/parse_tests/010-alias.json +++ b/pkg/js/parse_tests/010-alias.json @@ -12,8 +12,7 @@ "name": "@", "target": "foo.com." } - ], - "keepunknown": false + ] } ] } \ No newline at end of file diff --git a/pkg/js/parse_tests/011-cfRedirect.json b/pkg/js/parse_tests/011-cfRedirect.json index 729e2a0e7..bf424d463 100644 --- a/pkg/js/parse_tests/011-cfRedirect.json +++ b/pkg/js/parse_tests/011-cfRedirect.json @@ -17,8 +17,7 @@ "name": "@", "target": "test.foo.com,https://goo.com/$1" } - ], - "keepunknown": false + ] } ] } \ No newline at end of file diff --git a/pkg/js/parse_tests/012-duration.json b/pkg/js/parse_tests/012-duration.json index 100b360b3..30bd54e33 100644 --- a/pkg/js/parse_tests/012-duration.json +++ b/pkg/js/parse_tests/012-duration.json @@ -37,9 +37,7 @@ "target": "1.2.3.4", "ttl":259200 } - ], - - "keepunknown": false + ] } ] } \ No newline at end of file diff --git a/pkg/js/parse_tests/013-mx.js b/pkg/js/parse_tests/013-mx.js new file mode 100644 index 000000000..c8bb48c54 --- /dev/null +++ b/pkg/js/parse_tests/013-mx.js @@ -0,0 +1,3 @@ +D("foo.com","none", + MX("@",15,"foo.com.") +); \ No newline at end of file diff --git a/pkg/js/parse_tests/013-mx.json b/pkg/js/parse_tests/013-mx.json new file mode 100644 index 000000000..e96d45b02 --- /dev/null +++ b/pkg/js/parse_tests/013-mx.json @@ -0,0 +1,19 @@ +{ + "registrars": [], + "dns_providers": [], + "domains": [ + { + "name": "foo.com", + "registrar": "none", + "dnsProviders": {}, + "records": [ + { + "type": "MX", + "name": "@", + "target": "foo.com.", + "mxpreference": 15 + } + ] + } + ] +} \ No newline at end of file