diff --git a/test/ds_file_test.go b/test/ds_file_test.go index 348692ada..7d4ae0cdc 100644 --- a/test/ds_file_test.go +++ b/test/ds_file_test.go @@ -28,7 +28,7 @@ var dsTestCases = []mtest.Case{ func TestLookupDS(t *testing.T) { t.Parallel() - name, rm, err := TempFile(".", miekNL) + name, rm, err := mtest.TempFile(".", miekNL) if err != nil { t.Fatalf("Failed to create zone: %s", err) } diff --git a/test/file.go b/test/file.go deleted file mode 100644 index 626224cac..000000000 --- a/test/file.go +++ /dev/null @@ -1,19 +0,0 @@ -package test - -import ( - "io/ioutil" - "os" -) - -// TempFile will create a temporary file on disk and returns the name and a cleanup function to remove it later. -func TempFile(dir, content string) (string, func(), error) { - f, err := ioutil.TempFile(dir, "go-test-tmpfile") - if err != nil { - return "", nil, err - } - if err := ioutil.WriteFile(f.Name(), []byte(content), 0644); err != nil { - return "", nil, err - } - rmFunc := func() { os.Remove(f.Name()) } - return f.Name(), rmFunc, nil -} diff --git a/test/file_cname_proxy_test.go b/test/file_cname_proxy_test.go index e6f41ee97..5fb13622b 100644 --- a/test/file_cname_proxy_test.go +++ b/test/file_cname_proxy_test.go @@ -3,13 +3,15 @@ package test import ( "testing" + "github.com/coredns/coredns/plugin/test" + "github.com/miekg/dns" ) func TestZoneExternalCNAMELookupWithoutProxy(t *testing.T) { t.Parallel() - name, rm, err := TempFile(".", exampleOrg) + name, rm, err := test.TempFile(".", exampleOrg) if err != nil { t.Fatalf("Failed to create zone: %s", err) } @@ -41,7 +43,7 @@ func TestZoneExternalCNAMELookupWithoutProxy(t *testing.T) { func TestZoneExternalCNAMELookupWithProxy(t *testing.T) { t.Parallel() - name, rm, err := TempFile(".", exampleOrg) + name, rm, err := test.TempFile(".", exampleOrg) if err != nil { t.Fatalf("Failed to create zone: %s", err) } diff --git a/test/file_reload_test.go b/test/file_reload_test.go index b0d6c6656..251c8c25c 100644 --- a/test/file_reload_test.go +++ b/test/file_reload_test.go @@ -5,6 +5,7 @@ import ( "testing" "time" + "github.com/coredns/coredns/plugin/test" "github.com/coredns/coredns/plugin/file" "github.com/miekg/dns" @@ -13,7 +14,7 @@ import ( func TestZoneReload(t *testing.T) { file.TickTime = 1 * time.Second - name, rm, err := TempFile(".", exampleOrg) + name, rm, err := test.TempFile(".", exampleOrg) if err != nil { t.Fatalf("Failed to create zone: %s", err) } diff --git a/test/file_serve_test.go b/test/file_serve_test.go index 3f0674dfd..61bf98fe3 100644 --- a/test/file_serve_test.go +++ b/test/file_serve_test.go @@ -3,13 +3,15 @@ package test import ( "testing" + "github.com/coredns/coredns/plugin/test" + "github.com/miekg/dns" ) func TestZoneEDNS0Lookup(t *testing.T) { t.Parallel() - name, rm, err := TempFile(".", `$ORIGIN example.org. + name, rm, err := test.TempFile(".", `$ORIGIN example.org. @ 3600 IN SOA sns.dns.icann.org. noc.dns.icann.org. ( 2017042745 ; serial 7200 ; refresh (2 hours) @@ -56,7 +58,7 @@ www IN AAAA ::1 func TestZoneNoNS(t *testing.T) { t.Parallel() - name, rm, err := TempFile(".", `$ORIGIN example.org. + name, rm, err := test.TempFile(".", `$ORIGIN example.org. @ 3600 IN SOA sns.dns.icann.org. noc.dns.icann.org. ( 2017042745 ; serial 7200 ; refresh (2 hours) diff --git a/test/file_srv_additional_test.go b/test/file_srv_additional_test.go index 9ac74d8a3..30e603588 100644 --- a/test/file_srv_additional_test.go +++ b/test/file_srv_additional_test.go @@ -3,13 +3,15 @@ package test import ( "testing" + "github.com/coredns/coredns/plugin/test" + "github.com/miekg/dns" ) func TestZoneSRVAdditional(t *testing.T) { t.Parallel() - name, rm, err := TempFile(".", exampleOrg) + name, rm, err := test.TempFile(".", exampleOrg) if err != nil { t.Fatalf("Failed to create zone: %s", err) } diff --git a/test/file_test.go b/test/file_test.go index 891e9d903..babee27f4 100644 --- a/test/file_test.go +++ b/test/file_test.go @@ -1,10 +1,14 @@ package test -import "testing" +import ( + "testing" + + "github.com/coredns/coredns/plugin/test" +) func TestTempFile(t *testing.T) { t.Parallel() - _, f, e := TempFile(".", "test") + _, f, e := test.TempFile(".", "test") if e != nil { t.Fatalf("Failed to create temp file: %s", e) } diff --git a/test/file_upstream_test.go b/test/file_upstream_test.go index 36f2bbc56..3c4296b99 100644 --- a/test/file_upstream_test.go +++ b/test/file_upstream_test.go @@ -3,11 +3,13 @@ package test import ( "testing" + "github.com/coredns/coredns/plugin/test" + "github.com/miekg/dns" ) func TestFileUpstream(t *testing.T) { - name, rm, err := TempFile(".", `$ORIGIN example.org. + name, rm, err := test.TempFile(".", `$ORIGIN example.org. @ 3600 IN SOA sns.dns.icann.org. noc.dns.icann.org. ( 2017042745 ; serial 7200 ; refresh (2 hours) @@ -61,7 +63,7 @@ www 3600 IN CNAME www.example.net. // TestFileUpstreamAdditional runs two CoreDNS servers that serve example.org and foo.example.org. // example.org contains a cname to foo.example.org; this should be resolved via upstream.Self. func TestFileUpstreamAdditional(t *testing.T) { - name, rm, err := TempFile(".", `$ORIGIN example.org. + name, rm, err := test.TempFile(".", `$ORIGIN example.org. @ 3600 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2017042745 7200 3600 1209600 3600 3600 IN NS b.iana-servers.net. @@ -73,7 +75,7 @@ www 3600 IN CNAME www.foo } defer rm() - name2, rm2, err2 := TempFile(".", `$ORIGIN foo.example.org. + name2, rm2, err2 := test.TempFile(".", `$ORIGIN foo.example.org. @ 3600 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2017042745 7200 3600 1209600 3600 3600 IN NS b.iana-servers.net.