Remove duplicated TempFile testsuit (#2508)
This commit is contained in:
parent
f300fa9bb2
commit
ffe79b026e
8 changed files with 25 additions and 31 deletions
|
@ -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)
|
||||
}
|
||||
|
|
19
test/file.go
19
test/file.go
|
@ -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
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Reference in a new issue