mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 02:03:20 -04:00 
			
		
		
		
	* plugin/forward: on demand healtchecking Only start doing health checks when we encouner an error (any error). This uses the new pluing/pkg/up package to abstract away the actual checking. This reduces the LOC quite a bit; does need more testing, unit testing and tcpdumping a bit. * fix tests * Fix readme * Use pkg/up for healthchecks * remove unused channel * more cleanups * update readme * * Again do go generate and go build; still referencing the wrong forward repo? Anyway fixed. * Use pkg/up for doing the healtchecks to cut back on unwanted queries * Change up.Func to return an error instead of a boolean. * Drop the string target argument as it doesn't make sense. * Add healthcheck test on failing to get an upstream answer. TODO(miek): double check Forward and Lookup and how they interact with HC, and if we correctly call close() on those * actual test * Tests here * more tests * try getting rid of host * Get rid of the host indirection * Finish removing hosts * moar testing * import fmt * field is not used * docs * move some stuff * bring back health_check * maxfails=0 test * git and merging, bah * review
		
			
				
	
	
		
			43 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package forward
 | |
| 
 | |
| import (
 | |
| 	"testing"
 | |
| 
 | |
| 	"github.com/coredns/coredns/plugin/pkg/dnstest"
 | |
| 	"github.com/coredns/coredns/plugin/test"
 | |
| 	"github.com/coredns/coredns/request"
 | |
| 
 | |
| 	"github.com/miekg/dns"
 | |
| )
 | |
| 
 | |
| func TestLookup(t *testing.T) {
 | |
| 	s := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) {
 | |
| 		ret := new(dns.Msg)
 | |
| 		ret.SetReply(r)
 | |
| 		ret.Answer = append(ret.Answer, test.A("example.org. IN A 127.0.0.1"))
 | |
| 		w.WriteMsg(ret)
 | |
| 	})
 | |
| 	defer s.Close()
 | |
| 
 | |
| 	p := NewProxy(s.Addr, nil /* no TLS */)
 | |
| 	f := New()
 | |
| 	f.SetProxy(p)
 | |
| 	defer f.Close()
 | |
| 
 | |
| 	state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
 | |
| 	resp, err := f.Lookup(state, "example.org.", dns.TypeA)
 | |
| 	if err != nil {
 | |
| 		t.Fatal("Expected to receive reply, but didn't")
 | |
| 	}
 | |
| 	// expect answer section with A record in it
 | |
| 	if len(resp.Answer) == 0 {
 | |
| 		t.Fatalf("Expected to at least one RR in the answer section, got none: %s", resp)
 | |
| 	}
 | |
| 	if resp.Answer[0].Header().Rrtype != dns.TypeA {
 | |
| 		t.Errorf("Expected RR to A, got: %d", resp.Answer[0].Header().Rrtype)
 | |
| 	}
 | |
| 	if resp.Answer[0].(*dns.A).A.String() != "127.0.0.1" {
 | |
| 		t.Errorf("Expected 127.0.0.1, got: %s", resp.Answer[0].(*dns.A).A.String())
 | |
| 	}
 | |
| }
 |