mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
tests that would have caught tag renaming bug. js tests now don't marahsl expected through the go object. Instead minify both sides to compare
This commit is contained in:
@ -213,7 +213,7 @@ type DomainConfig struct {
|
|||||||
Metadata map[string]string `json:"meta,omitempty"`
|
Metadata map[string]string `json:"meta,omitempty"`
|
||||||
Records []*RecordConfig `json:"records"`
|
Records []*RecordConfig `json:"records"`
|
||||||
Nameservers []*Nameserver `json:"nameservers,omitempty"`
|
Nameservers []*Nameserver `json:"nameservers,omitempty"`
|
||||||
KeepUnknown bool `json:"keepunknown"`
|
KeepUnknown bool `json:"keepunknown,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dc *DomainConfig) Copy() (*DomainConfig, error) {
|
func (dc *DomainConfig) Copy() (*DomainConfig, error) {
|
||||||
|
@ -8,7 +8,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
"github.com/StackExchange/dnscontrol/models"
|
"github.com/tdewolff/minify"
|
||||||
|
minjson "github.com/tdewolff/minify/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -30,6 +31,8 @@ func TestParsedFiles(t *testing.T) {
|
|||||||
if filepath.Ext(f.Name()) != ".js" || !unicode.IsNumber(rune(f.Name()[0])) {
|
if filepath.Ext(f.Name()) != ".js" || !unicode.IsNumber(rune(f.Name()[0])) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
m := minify.New()
|
||||||
|
m.AddFunc("json", minjson.Minify)
|
||||||
t.Run(f.Name(), func(t *testing.T) {
|
t.Run(f.Name(), func(t *testing.T) {
|
||||||
content, err := ioutil.ReadFile(filepath.Join(testDir, f.Name()))
|
content, err := ioutil.ReadFile(filepath.Join(testDir, f.Name()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -43,18 +46,17 @@ func TestParsedFiles(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
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")
|
expectedFile := filepath.Join(testDir, f.Name()[:len(f.Name())-3]+".json")
|
||||||
expectedData, err := ioutil.ReadFile(expectedFile)
|
expectedData, err := ioutil.ReadFile(expectedFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
conf = &models.DNSConfig{}
|
|
||||||
//unmarshal and remarshal to not require manual formatting
|
expectedJSON, err := m.String("json", string(expectedData))
|
||||||
err = json.Unmarshal(expectedData, conf)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
expectedJSON, err := json.MarshalIndent(conf, "", " ")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -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"
|
"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
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -16,8 +16,7 @@
|
|||||||
"transform_table": "0.0.0.0 ~ 1.1.1.1 ~ 2.2.2.2 ~ "
|
"transform_table": "0.0.0.0 ~ 1.1.1.1 ~ 2.2.2.2 ~ "
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
"keepunknown": false
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -12,8 +12,7 @@
|
|||||||
"name": "@",
|
"name": "@",
|
||||||
"target": "1.2.3.4"
|
"target": "1.2.3.4"
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
"keepunknown": false
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -6,8 +6,7 @@
|
|||||||
"name": "2.1.in-addr.arpa",
|
"name": "2.1.in-addr.arpa",
|
||||||
"registrar": "none",
|
"registrar": "none",
|
||||||
"dnsProviders": {},
|
"dnsProviders": {},
|
||||||
"records": [],
|
"records": []
|
||||||
"keepunknown": false
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -12,8 +12,7 @@
|
|||||||
"name": "@",
|
"name": "@",
|
||||||
"target": "foo.com."
|
"target": "foo.com."
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
"keepunknown": false
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -17,8 +17,7 @@
|
|||||||
"name": "@",
|
"name": "@",
|
||||||
"target": "test.foo.com,https://goo.com/$1"
|
"target": "test.foo.com,https://goo.com/$1"
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
"keepunknown": false
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -37,9 +37,7 @@
|
|||||||
"target": "1.2.3.4",
|
"target": "1.2.3.4",
|
||||||
"ttl":259200
|
"ttl":259200
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
|
|
||||||
"keepunknown": false
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
3
pkg/js/parse_tests/013-mx.js
Normal file
3
pkg/js/parse_tests/013-mx.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
D("foo.com","none",
|
||||||
|
MX("@",15,"foo.com.")
|
||||||
|
);
|
19
pkg/js/parse_tests/013-mx.json
Normal file
19
pkg/js/parse_tests/013-mx.json
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"registrars": [],
|
||||||
|
"dns_providers": [],
|
||||||
|
"domains": [
|
||||||
|
{
|
||||||
|
"name": "foo.com",
|
||||||
|
"registrar": "none",
|
||||||
|
"dnsProviders": {},
|
||||||
|
"records": [
|
||||||
|
{
|
||||||
|
"type": "MX",
|
||||||
|
"name": "@",
|
||||||
|
"target": "foo.com.",
|
||||||
|
"mxpreference": 15
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
Reference in New Issue
Block a user