mirror of
				https://github.com/coredns/coredns.git
				synced 2025-11-04 03:03:14 -05:00 
			
		
		
		
	* plugin/file: make non-existent file non-fatal If the zone file being loaded doesn't exist *and* reload is enabled, just wait the file to pop up in the normal Reload routine. If reload is set to 0s; we keep this a fatal error on startup. Aslo fix the ticker in z.Reload(): remove the per second ticks and just use the reload interval for the ticker. Brush up the documentation a bit as well. Fixes: #2951 Signed-off-by: Miek Gieben <miek@miek.nl> * Stickler and test compile Signed-off-by: Miek Gieben <miek@miek.nl> * Remove there too Signed-off-by: Miek Gieben <miek@miek.nl> * Cant README test these because zone files dont exist Signed-off-by: Miek Gieben <miek@miek.nl>
		
			
				
	
	
		
			68 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			68 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package test
 | 
						|
 | 
						|
import (
 | 
						|
	"io/ioutil"
 | 
						|
	"testing"
 | 
						|
	"time"
 | 
						|
 | 
						|
	"github.com/coredns/coredns/plugin/test"
 | 
						|
 | 
						|
	"github.com/miekg/dns"
 | 
						|
)
 | 
						|
 | 
						|
func TestZoneReload(t *testing.T) {
 | 
						|
	name, rm, err := test.TempFile(".", exampleOrg)
 | 
						|
	if err != nil {
 | 
						|
		t.Fatalf("Failed to create zone: %s", err)
 | 
						|
	}
 | 
						|
	defer rm()
 | 
						|
 | 
						|
	// Corefile with two stanzas
 | 
						|
	corefile := `example.org:0 {
 | 
						|
       file ` + name + ` {
 | 
						|
           reload 1s
 | 
						|
       }
 | 
						|
}
 | 
						|
 | 
						|
example.net:0 {
 | 
						|
	file ` + name + `
 | 
						|
}
 | 
						|
`
 | 
						|
	i, udp, _, err := CoreDNSServerAndPorts(corefile)
 | 
						|
	if err != nil {
 | 
						|
		t.Fatalf("Could not get CoreDNS serving instance: %s", err)
 | 
						|
	}
 | 
						|
	defer i.Stop()
 | 
						|
 | 
						|
	m := new(dns.Msg)
 | 
						|
	m.SetQuestion("example.org.", dns.TypeA)
 | 
						|
	resp, err := dns.Exchange(m, udp)
 | 
						|
	if err != nil {
 | 
						|
		t.Fatalf("Expected to receive reply, but didn't: %s", err)
 | 
						|
	}
 | 
						|
	if len(resp.Answer) != 2 {
 | 
						|
		t.Fatalf("Expected two RR in answer section got %d", len(resp.Answer))
 | 
						|
	}
 | 
						|
 | 
						|
	// Remove RR from the Apex
 | 
						|
	ioutil.WriteFile(name, []byte(exampleOrgUpdated), 0644)
 | 
						|
 | 
						|
	time.Sleep(2 * time.Second) // reload time
 | 
						|
 | 
						|
	resp, err = dns.Exchange(m, udp)
 | 
						|
	if err != nil {
 | 
						|
		t.Fatal("Expected to receive reply, but didn't")
 | 
						|
	}
 | 
						|
 | 
						|
	if len(resp.Answer) != 1 {
 | 
						|
		t.Fatalf("Expected two RR in answer section got %d", len(resp.Answer))
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
const exampleOrgUpdated = `; example.org test file
 | 
						|
example.org.		IN	SOA	sns.dns.icann.org. noc.dns.icann.org. 2016082541 7200 3600 1209600 3600
 | 
						|
example.org.		IN	NS	b.iana-servers.net.
 | 
						|
example.org.		IN	NS	a.iana-servers.net.
 | 
						|
example.org.		IN	A	127.0.0.2
 | 
						|
`
 |