mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2026-01-16 05:04:56 +08:00
# Issue Fixes https://github.com/StackExchange/dnscontrol/issues/3912 # Resolution ``` #!/bin/sh # Reset git fetch origin main git reset --hard origin/main git checkout main git branch -D tlim_moveproviders git checkout -b tlim_moveproviders find . -name \*.bak -delete # Move the *.go files out of providers/ mkdir -p pkg/providers git mv providers/*.go pkg/providers # move the _all file out of providers/ git mv providers/_all pkg/providers/_all # Update the imports (in go.* and the affected files) sed -i.bak -e 's@"github.com/StackExchange/dnscontrol/v4/providers"@"github.com/StackExchange/dnscontrol/v4/pkg/providers"@g' go.* $(fgrep -lr --include '*.go' '"github.com/StackExchange/dnscontrol/v4/providers"' *) sed -i.bak -e 's@"../../providers"@"../../pkg/providers"@g' pkg/normalize/capabilities_test.go sed -i.bak -e 's@"github.com/StackExchange/dnscontrol/v4/providers/_all"@"github.com/StackExchange/dnscontrol/v4/pkg/providers/_all"@g' go.* $(fgrep -lr --include '*.go' '"github.com/StackExchange/dnscontrol/v4/providers/_all"' *) # Fix the docs sed -i.bak -e 's@StackExchange/dnscontrol/blob/main/providers/_all/all.go@StackExchange/dnscontrol/blob/main/pkg/providers/_all/all.go@g' documentation/advanced-features/writing-providers.md sed -i.bak -e 's@StackExchange/dnscontrol/providers@StackExchange/dnscontrol/pkg/providers@g' documentation/advanced-features/writing-providers.md sed -i.bak -e 's@StackExchange/dnscontrol/v4/providers@StackExchange/dnscontrol/v4/pkg/providers@g' documentation/advanced-features/writing-providers.md sed -i.bak -e 's@dnscontrol/providers/providers.go@dnscontrol/pkg/providers/providers.go@g' documentation/advanced-features/writing-providers.md sed -i.bak -e 's@providers/_all/all.go@pkg/providers/_all/all.go@g' documentation/advanced-features/writing-providers.md #sed -i.bak -e 's@@@g' documentation/advanced-features/writing-providers.md #sed -i.bak -e 's@@@g' documentation/advanced-features/writing-providers.md find . -name \*.bak -delete go fmt ./... git status echo git commit -a -m'CHORE: Move Non-provider files in providers to pkg/providers' ```
77 lines
2.2 KiB
Go
77 lines
2.2 KiB
Go
package commands
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"testing"
|
|
|
|
_ "github.com/StackExchange/dnscontrol/v4/pkg/providers/_all"
|
|
"github.com/andreyvit/diff"
|
|
)
|
|
|
|
func TestFormatTypes(t *testing.T) {
|
|
/*
|
|
Input: Converted to: Should match contents of:
|
|
test_data/$DOMAIN.zone js test_data/$DOMAIN.zone.js
|
|
test_data/$DOMAIN.zone tsv test_data/$DOMAIN.zone.tsv
|
|
test_data/$DOMAIN.zone zone test_data/$DOMAIN.zone.zone
|
|
*/
|
|
|
|
for _, domain := range []string{"simple.com", "example.org", "apex.com", "ds.com"} {
|
|
t.Run(domain+"/js", func(t *testing.T) { testFormat(t, domain, "js") })
|
|
t.Run(domain+"/djs", func(t *testing.T) { testFormat(t, domain, "djs") })
|
|
t.Run(domain+"/tsv", func(t *testing.T) { testFormat(t, domain, "tsv") })
|
|
t.Run(domain+"/zone", func(t *testing.T) { testFormat(t, domain, "zone") })
|
|
}
|
|
}
|
|
|
|
func testFormat(t *testing.T, domain, format string) {
|
|
t.Helper()
|
|
|
|
expectedFilename := fmt.Sprintf("test_data/%s.zone.%s", domain, format)
|
|
outputFiletmpl := fmt.Sprintf("%s.zone.%s.*.txt", domain, format)
|
|
|
|
outfile, err := os.CreateTemp(t.TempDir(), outputFiletmpl)
|
|
if err != nil {
|
|
log.Fatal(fmt.Errorf("gz can't TempFile %q: %w", outputFiletmpl, err))
|
|
}
|
|
defer os.Remove(outfile.Name())
|
|
|
|
// Convert test data to the experiment output.
|
|
gzargs := GetZoneArgs{
|
|
ZoneNames: []string{domain},
|
|
OutputFormat: format,
|
|
OutputFile: outfile.Name(),
|
|
CredName: "bind",
|
|
ProviderName: "BIND",
|
|
}
|
|
gzargs.CredsFile = "test_data/bind-creds.json"
|
|
|
|
// Read the zonefile and convert
|
|
err = GetZone(gzargs)
|
|
if err != nil {
|
|
log.Fatal(fmt.Errorf("can't GetZone: %w", err))
|
|
}
|
|
|
|
// Read the actual result:
|
|
got, err := os.ReadFile(outfile.Name())
|
|
if err != nil {
|
|
log.Fatal(fmt.Errorf("can't read actuals %q: %w", outfile.Name(), err))
|
|
}
|
|
|
|
// Read the expected result
|
|
want, err := os.ReadFile(expectedFilename)
|
|
if err != nil {
|
|
log.Fatal(fmt.Errorf("can't read expected %q: %w", expectedFilename, err))
|
|
}
|
|
|
|
if w, g := string(want), string(got); w != g {
|
|
// If the test fails, output a file showing "got"
|
|
err = os.WriteFile(expectedFilename+".ACTUAL", got, 0o644)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
t.Errorf("testFormat mismatch (-got +want):\n%s", diff.LineDiff(g, w))
|
|
}
|
|
}
|