mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-27 16:24:19 -04:00 
			
		
		
		
	* Clean up tests logging This cleans up the travis logs so you can see the failures better. Older tests in tests/ would call log.SetOutput(ioutil.Discard) in a haphazard way. This add log.Discard and put an `init` function in each package's dir (no way to do this globally). The cleanup in tests/ is clear. All plugins also got this init function to have some uniformity and kill any (future) logging there in the tests as well. There is a one-off in pkg/healthcheck because that does log. Signed-off-by: Miek Gieben <miek@miek.nl> * bring back original log_test.go Signed-off-by: Miek Gieben <miek@miek.nl> * suppress logging here as well Signed-off-by: Miek Gieben <miek@miek.nl>
		
			
				
	
	
		
			77 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			77 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package test
 | |
| 
 | |
| import (
 | |
| 	"io/ioutil"
 | |
| 	"os"
 | |
| 	"testing"
 | |
| 
 | |
| 	"github.com/coredns/coredns/plugin/test"
 | |
| 
 | |
| 	"github.com/miekg/dns"
 | |
| )
 | |
| 
 | |
| func TestLookupBalanceRewriteCacheDnssec(t *testing.T) {
 | |
| 	t.Parallel()
 | |
| 	name, rm, err := test.TempFile(".", exampleOrg)
 | |
| 	if err != nil {
 | |
| 		t.Fatalf("Failed to create zone: %s", err)
 | |
| 	}
 | |
| 	defer rm()
 | |
| 	rm1 := createKeyFile(t)
 | |
| 	defer rm1()
 | |
| 
 | |
| 	corefile := `example.org:0 {
 | |
|     file ` + name + `
 | |
|     rewrite type ANY HINFO
 | |
|     dnssec {
 | |
|         key file ` + base + `
 | |
|     }
 | |
|     loadbalance
 | |
| }
 | |
| `
 | |
| 	ex, udp, _, err := CoreDNSServerAndPorts(corefile)
 | |
| 	if err != nil {
 | |
| 		t.Fatalf("Could not get CoreDNS serving instance: %s", err)
 | |
| 	}
 | |
| 	defer ex.Stop()
 | |
| 
 | |
| 	c := new(dns.Client)
 | |
| 	m := new(dns.Msg)
 | |
| 	m.SetQuestion("example.org.", dns.TypeA)
 | |
| 	m.SetEdns0(4096, true)
 | |
| 	res, _, err := c.Exchange(m, udp)
 | |
| 	if err != nil {
 | |
| 		t.Fatalf("Could not send query: %s", err)
 | |
| 	}
 | |
| 	sig := 0
 | |
| 	for _, a := range res.Answer {
 | |
| 		if a.Header().Rrtype == dns.TypeRRSIG {
 | |
| 			sig++
 | |
| 		}
 | |
| 	}
 | |
| 	if sig == 0 {
 | |
| 		t.Errorf("Expected RRSIGs, got none")
 | |
| 		t.Logf("%v\n", res)
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func createKeyFile(t *testing.T) func() {
 | |
| 	ioutil.WriteFile(base+".key",
 | |
| 		[]byte(`example.org. IN DNSKEY 256 3 13 tDyI0uEIDO4SjhTJh1AVTFBLpKhY3He5BdAlKztewiZ7GecWj94DOodg ovpN73+oJs+UfZ+p9zOSN5usGAlHrw==`),
 | |
| 		0644)
 | |
| 	ioutil.WriteFile(base+".private",
 | |
| 		[]byte(`Private-key-format: v1.3
 | |
| Algorithm: 13 (ECDSAP256SHA256)
 | |
| PrivateKey: HPmldSNfrkj/aDdUMFwuk/lgzaC5KIsVEG3uoYvF4pQ=
 | |
| Created: 20160426083115
 | |
| Publish: 20160426083115
 | |
| Activate: 20160426083115`),
 | |
| 		0644)
 | |
| 	return func() {
 | |
| 		os.Remove(base + ".key")
 | |
| 		os.Remove(base + ".private")
 | |
| 	}
 | |
| }
 | |
| 
 | |
| const base = "Kexample.org.+013+44563"
 |