mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-01-11 18:08:57 +08:00
2f83aa9302
* Switched to v2 go.mod Also set GO111MODULE=on in build stuff to always use Go modules even when in GOPATH. * Ensure go.mod, go.sum, and vendor are up to date * Attempt to fix Azure pipelines * Add set -e to properly fail on exit (it didn't seem to be propagating properly before). * Set workingDirectory for GoFmt and GoGen (this might be why it fails unlike compile and unitests). * Another attempt to fix Azure Pipelines * Use the Go env template for all go-related jobs. * Completely fixed Azure Pipelines * Added a display name to GoFmt for consistency. * Fixed diffs for GoFmt and GoGen. * Show git status for checks. * Drop GOPATH for tests TODO: Do the same for integration tests. * Drop GOPATH for integration tests * Show more diffs * Regenerate provider support matrix This wasn't done in #590...
49 lines
1.4 KiB
Go
49 lines
1.4 KiB
Go
package normalize
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/StackExchange/dnscontrol/v2/models"
|
|
)
|
|
|
|
func makeRC(label, domain, target string, rc models.RecordConfig) *models.RecordConfig {
|
|
rc.SetLabel(label, domain)
|
|
rc.SetTarget(target)
|
|
return &rc
|
|
}
|
|
|
|
func TestImportTransform(t *testing.T) {
|
|
|
|
const transformDouble = "0.0.0.0~1.1.1.1~~9.0.0.0,10.0.0.0"
|
|
const transformSingle = "0.0.0.0~1.1.1.1~~8.0.0.0"
|
|
src := &models.DomainConfig{
|
|
Name: "stackexchange.com",
|
|
Records: []*models.RecordConfig{
|
|
makeRC("*", "stackexchange.com", "0.0.2.2", models.RecordConfig{Type: "A"}),
|
|
makeRC("www", "stackexchange.com", "0.0.1.1", models.RecordConfig{Type: "A"}),
|
|
},
|
|
}
|
|
dst := &models.DomainConfig{
|
|
Name: "internal",
|
|
Records: []*models.RecordConfig{
|
|
makeRC("*.stackexchange.com", "*.stackexchange.com.internal", "0.0.3.3", models.RecordConfig{Type: "A", Metadata: map[string]string{"transform_table": transformSingle}}),
|
|
makeRC("@", "internal", "stackexchange.com", models.RecordConfig{Type: "IMPORT_TRANSFORM", Metadata: map[string]string{"transform_table": transformDouble}}),
|
|
},
|
|
}
|
|
cfg := &models.DNSConfig{
|
|
Domains: []*models.DomainConfig{src, dst},
|
|
}
|
|
if errs := NormalizeAndValidateConfig(cfg); len(errs) != 0 {
|
|
for _, err := range errs {
|
|
t.Error(err)
|
|
}
|
|
t.FailNow()
|
|
}
|
|
d := cfg.FindDomain("internal")
|
|
if len(d.Records) != 3 {
|
|
for _, r := range d.Records {
|
|
t.Error(r)
|
|
}
|
|
t.Fatalf("Expected 3 records in internal, but got %d", len(d.Records))
|
|
}
|
|
}
|