mirror of
				https://github.com/coredns/coredns.git
				synced 2025-11-03 18:53:13 -05:00 
			
		
		
		
	Be more explicit in the logs when a notify fails. New notify error message looks like: 2016/11/07 18:21:42 [ERROR] Notify for zone "example.org." was not accepted by "8.8.8.8:53": rcode was "SERVFAIL" Correctly pick up secondaries When multiple secondary are specified make sure they are picked up. Fixes #393 #398
		
			
				
	
	
		
			94 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			94 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package auto
 | 
						|
 | 
						|
import (
 | 
						|
	"testing"
 | 
						|
 | 
						|
	"github.com/mholt/caddy"
 | 
						|
)
 | 
						|
 | 
						|
func TestAutoParse(t *testing.T) {
 | 
						|
	tests := []struct {
 | 
						|
		inputFileRules    string
 | 
						|
		shouldErr         bool
 | 
						|
		expectedDirectory string
 | 
						|
		expectedTempl     string
 | 
						|
		expectedRe        string
 | 
						|
		expectedTo        []string
 | 
						|
	}{
 | 
						|
		{
 | 
						|
			`auto example.org {
 | 
						|
				directory /tmp
 | 
						|
				transfer to 127.0.0.1
 | 
						|
			}`,
 | 
						|
			false, "/tmp", "${1}", `db\.(.*)`, []string{"127.0.0.1:53"},
 | 
						|
		},
 | 
						|
		{
 | 
						|
			`auto {
 | 
						|
				directory /tmp
 | 
						|
			}`,
 | 
						|
			false, "/tmp", "${1}", `db\.(.*)`, nil,
 | 
						|
		},
 | 
						|
		{
 | 
						|
			`auto {
 | 
						|
				directory /tmp (.*) bliep
 | 
						|
			}`,
 | 
						|
			false, "/tmp", "bliep", `(.*)`, nil,
 | 
						|
		},
 | 
						|
		{
 | 
						|
			`auto {
 | 
						|
				directory /tmp (.*) bliep
 | 
						|
				transfer to 127.0.0.1
 | 
						|
				transfer to 127.0.0.2
 | 
						|
			}`,
 | 
						|
			false, "/tmp", "bliep", `(.*)`, []string{"127.0.0.1:53", "127.0.0.2:53"},
 | 
						|
		},
 | 
						|
		// errors
 | 
						|
		{
 | 
						|
			`auto example.org {
 | 
						|
				directory
 | 
						|
			}`,
 | 
						|
			true, "", "${1}", `db\.(.*)`, nil,
 | 
						|
		},
 | 
						|
		{
 | 
						|
			`auto example.org {
 | 
						|
				directory /tmp * {1}
 | 
						|
			}`,
 | 
						|
			true, "", "${1}", ``, nil,
 | 
						|
		},
 | 
						|
		{
 | 
						|
			`auto example.org {
 | 
						|
				directory /tmp .* {1}
 | 
						|
			}`,
 | 
						|
			true, "", "${1}", ``, nil,
 | 
						|
		},
 | 
						|
	}
 | 
						|
 | 
						|
	for i, test := range tests {
 | 
						|
		c := caddy.NewTestController("dns", test.inputFileRules)
 | 
						|
		a, err := autoParse(c)
 | 
						|
 | 
						|
		if err == nil && test.shouldErr {
 | 
						|
			t.Fatalf("Test %d expected errors, but got no error", i)
 | 
						|
		} else if err != nil && !test.shouldErr {
 | 
						|
			t.Fatalf("Test %d expected no errors, but got '%v'", i, err)
 | 
						|
		} else if !test.shouldErr {
 | 
						|
			if a.loader.directory != test.expectedDirectory {
 | 
						|
				t.Fatalf("Test %d expected %v, got %v", i, test.expectedDirectory, a.loader.directory)
 | 
						|
			}
 | 
						|
			if a.loader.template != test.expectedTempl {
 | 
						|
				t.Fatalf("Test %d expected %v, got %v", i, test.expectedTempl, a.loader.template)
 | 
						|
			}
 | 
						|
			if a.loader.re.String() != test.expectedRe {
 | 
						|
				t.Fatalf("Test %d expected %v, got %v", i, test.expectedRe, a.loader.re)
 | 
						|
			}
 | 
						|
			if test.expectedTo != nil {
 | 
						|
				for j, got := range a.loader.transferTo {
 | 
						|
					if got != test.expectedTo[j] {
 | 
						|
						t.Fatalf("Test %d expected %v, got %v", i, test.expectedTo[j], got)
 | 
						|
					}
 | 
						|
				}
 | 
						|
			}
 | 
						|
		}
 | 
						|
	}
 | 
						|
}
 |