pkg/fall: make Zero and Root vars not funcs (#1367)

These can be just vars. Think that was intended as well.
This commit is contained in:
Miek Gieben 2018-01-09 22:29:19 +00:00 committed by GitHub
parent a19ea63d3a
commit cced1a4c12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 51 additions and 52 deletions

View file

@ -19,43 +19,43 @@ func TestHostsParse(t *testing.T) {
{
`hosts
`,
false, "/etc/hosts", nil, fall.Zero(),
false, "/etc/hosts", nil, fall.Zero,
},
{
`hosts /tmp`,
false, "/tmp", nil, fall.Zero(),
false, "/tmp", nil, fall.Zero,
},
{
`hosts /etc/hosts miek.nl.`,
false, "/etc/hosts", []string{"miek.nl."}, fall.Zero(),
false, "/etc/hosts", []string{"miek.nl."}, fall.Zero,
},
{
`hosts /etc/hosts miek.nl. pun.gent.`,
false, "/etc/hosts", []string{"miek.nl.", "pun.gent."}, fall.Zero(),
false, "/etc/hosts", []string{"miek.nl.", "pun.gent."}, fall.Zero,
},
{
`hosts {
fallthrough
}`,
false, "/etc/hosts", nil, fall.Root(),
false, "/etc/hosts", nil, fall.Root,
},
{
`hosts /tmp {
fallthrough
}`,
false, "/tmp", nil, fall.Root(),
false, "/tmp", nil, fall.Root,
},
{
`hosts /etc/hosts miek.nl. {
fallthrough
}`,
false, "/etc/hosts", []string{"miek.nl."}, fall.Root(),
false, "/etc/hosts", []string{"miek.nl."}, fall.Root,
},
{
`hosts /etc/hosts miek.nl 10.0.0.9/8 {
fallthrough
}`,
false, "/etc/hosts", []string{"miek.nl.", "10.in-addr.arpa."}, fall.Root(),
false, "/etc/hosts", []string{"miek.nl.", "10.in-addr.arpa."}, fall.Root,
},
}
@ -105,7 +105,7 @@ func TestHostsInlineParse(t *testing.T) {
`example.org.`,
},
},
fall.Root(),
fall.Root,
},
{
`hosts highly_unlikely_to_exist_hosts_file example.org {
@ -117,7 +117,7 @@ func TestHostsInlineParse(t *testing.T) {
`example.org.`,
},
},
fall.Zero(),
fall.Zero,
},
{
`hosts highly_unlikely_to_exist_hosts_file example.org {
@ -126,7 +126,7 @@ func TestHostsInlineParse(t *testing.T) {
}`,
true,
map[string][]string{},
fall.Root(),
fall.Root,
},
}

View file

@ -34,7 +34,7 @@ func TestKubernetesParse(t *testing.T) {
defaultResyncPeriod,
"",
podModeDisabled,
fall.Zero(),
fall.Zero,
nil,
},
{
@ -46,7 +46,7 @@ func TestKubernetesParse(t *testing.T) {
defaultResyncPeriod,
"",
podModeDisabled,
fall.Zero(),
fall.Zero,
nil,
},
{
@ -59,7 +59,7 @@ func TestKubernetesParse(t *testing.T) {
defaultResyncPeriod,
"",
podModeDisabled,
fall.Zero(),
fall.Zero,
nil,
},
{
@ -73,7 +73,7 @@ func TestKubernetesParse(t *testing.T) {
defaultResyncPeriod,
"",
podModeDisabled,
fall.Zero(),
fall.Zero,
nil,
},
{
@ -87,7 +87,7 @@ func TestKubernetesParse(t *testing.T) {
defaultResyncPeriod,
"",
podModeDisabled,
fall.Zero(),
fall.Zero,
nil,
},
{
@ -101,7 +101,7 @@ func TestKubernetesParse(t *testing.T) {
defaultResyncPeriod,
"",
podModeDisabled,
fall.Zero(),
fall.Zero,
nil,
},
{
@ -115,7 +115,7 @@ func TestKubernetesParse(t *testing.T) {
30 * time.Second,
"",
podModeDisabled,
fall.Zero(),
fall.Zero,
nil,
},
{
@ -129,7 +129,7 @@ func TestKubernetesParse(t *testing.T) {
15 * time.Minute,
"",
podModeDisabled,
fall.Zero(),
fall.Zero,
nil,
},
{
@ -143,7 +143,7 @@ func TestKubernetesParse(t *testing.T) {
defaultResyncPeriod,
"environment=prod",
podModeDisabled,
fall.Zero(),
fall.Zero,
nil,
},
{
@ -157,7 +157,7 @@ func TestKubernetesParse(t *testing.T) {
defaultResyncPeriod,
"application=nginx,environment in (production,qa,staging)",
podModeDisabled,
fall.Zero(),
fall.Zero,
nil,
},
{
@ -175,7 +175,7 @@ func TestKubernetesParse(t *testing.T) {
15 * time.Minute,
"application=nginx,environment in (production,qa,staging)",
podModeDisabled,
fall.Root(),
fall.Root,
nil,
},
// negative
@ -190,7 +190,7 @@ func TestKubernetesParse(t *testing.T) {
defaultResyncPeriod,
"",
podModeDisabled,
fall.Zero(),
fall.Zero,
nil,
},
{
@ -204,7 +204,7 @@ func TestKubernetesParse(t *testing.T) {
defaultResyncPeriod,
"",
podModeDisabled,
fall.Zero(),
fall.Zero,
nil,
},
{
@ -218,7 +218,7 @@ func TestKubernetesParse(t *testing.T) {
0 * time.Minute,
"",
podModeDisabled,
fall.Zero(),
fall.Zero,
nil,
},
{
@ -232,7 +232,7 @@ func TestKubernetesParse(t *testing.T) {
0 * time.Second,
"",
podModeDisabled,
fall.Zero(),
fall.Zero,
nil,
},
{
@ -246,7 +246,7 @@ func TestKubernetesParse(t *testing.T) {
0 * time.Second,
"",
podModeDisabled,
fall.Zero(),
fall.Zero,
nil,
},
{
@ -260,7 +260,7 @@ func TestKubernetesParse(t *testing.T) {
0 * time.Second,
"",
podModeDisabled,
fall.Zero(),
fall.Zero,
nil,
},
{
@ -274,7 +274,7 @@ func TestKubernetesParse(t *testing.T) {
0 * time.Second,
"",
podModeDisabled,
fall.Zero(),
fall.Zero,
nil,
},
// pods disabled
@ -289,7 +289,7 @@ func TestKubernetesParse(t *testing.T) {
defaultResyncPeriod,
"",
podModeDisabled,
fall.Zero(),
fall.Zero,
nil,
},
// pods insecure
@ -304,7 +304,7 @@ func TestKubernetesParse(t *testing.T) {
defaultResyncPeriod,
"",
podModeInsecure,
fall.Zero(),
fall.Zero,
nil,
},
// pods verified
@ -319,7 +319,7 @@ func TestKubernetesParse(t *testing.T) {
defaultResyncPeriod,
"",
podModeVerified,
fall.Zero(),
fall.Zero,
nil,
},
// pods invalid
@ -334,7 +334,7 @@ func TestKubernetesParse(t *testing.T) {
defaultResyncPeriod,
"",
podModeVerified,
fall.Zero(),
fall.Zero,
nil,
},
// fallthrough with zones
@ -364,7 +364,7 @@ func TestKubernetesParse(t *testing.T) {
defaultResyncPeriod,
"",
podModeDisabled,
fall.Zero(),
fall.Zero,
[]string{"13.14.15.16:53"},
},
// Invalid upstream
@ -379,7 +379,7 @@ func TestKubernetesParse(t *testing.T) {
defaultResyncPeriod,
"",
podModeDisabled,
fall.Zero(),
fall.Zero,
nil,
},
}

View file

@ -28,7 +28,7 @@ func (f *F) setZones(zones []string) {
// SetZonesFromArgs sets zones in f to the passed value or to "." if the slice is empty.
func (f *F) SetZonesFromArgs(zones []string) {
if len(zones) == 0 {
f.setZones(Root().Zones)
f.setZones(Root.Zones)
return
}
f.setZones(zones)
@ -50,9 +50,9 @@ func (f F) Equal(g F) bool {
// Zero returns a zero valued F.
var Zero = func() F {
return F{[]string{}}
}
}()
// Root returns F set to only ".".
var Root = func() F {
return F{[]string{"."}}
}
}()

View file

@ -23,7 +23,7 @@ func TestEqual(t *testing.T) {
func TestZero(t *testing.T) {
var f F
if !f.Equal(Zero()) {
if !f.Equal(Zero) {
t.Errorf("F should be zero")
}
}
@ -31,7 +31,7 @@ func TestZero(t *testing.T) {
func TestSetZonesFromArgs(t *testing.T) {
var f F
f.SetZonesFromArgs([]string{})
if !f.Equal(Root()) {
if !f.Equal(Root) {
t.Errorf("F should have the root zone")
}

View file

@ -16,13 +16,12 @@ import (
)
func TestHandler(t *testing.T) {
rcodeFallthrough := 3841 // reserved for private use, used to indicate a fallthrough
exampleDomainATemplate := template{
regex: []*regexp.Regexp{regexp.MustCompile("(^|[.])ip-10-(?P<b>[0-9]*)-(?P<c>[0-9]*)-(?P<d>[0-9]*)[.]example[.]$")},
answer: []*gotmpl.Template{gotmpl.Must(gotmpl.New("answer").Parse("{{ .Name }} 60 IN A 10.{{ .Group.b }}.{{ .Group.c }}.{{ .Group.d }}"))},
qclass: dns.ClassANY,
qtype: dns.TypeANY,
fall: fall.F{Zones: []string{"."}},
fall: fall.Root,
zones: []string{"."},
}
exampleDomainANSTemplate := template{
@ -32,7 +31,7 @@ func TestHandler(t *testing.T) {
authority: []*gotmpl.Template{gotmpl.Must(gotmpl.New("authority").Parse("example. IN NS ns0.example.com."))},
qclass: dns.ClassANY,
qtype: dns.TypeANY,
fall: fall.F{Zones: []string{"."}},
fall: fall.Root,
zones: []string{"."},
}
exampleDomainMXTemplate := template{
@ -41,7 +40,7 @@ func TestHandler(t *testing.T) {
additional: []*gotmpl.Template{gotmpl.Must(gotmpl.New("additional").Parse("{{ .Name }} 60 IN A 10.{{ .Group.b }}.{{ .Group.c }}.{{ .Group.d }}"))},
qclass: dns.ClassANY,
qtype: dns.TypeANY,
fall: fall.F{Zones: []string{"."}},
fall: fall.Root,
zones: []string{"."},
}
invalidDomainTemplate := template{
@ -50,7 +49,7 @@ func TestHandler(t *testing.T) {
answer: []*gotmpl.Template{gotmpl.Must(gotmpl.New("answer").Parse("invalid. 60 {{ .Class }} SOA a.invalid. b.invalid. (1 60 60 60 60)"))},
qclass: dns.ClassANY,
qtype: dns.TypeANY,
fall: fall.F{Zones: []string{"."}},
fall: fall.Root,
zones: []string{"."},
}
rcodeServfailTemplate := template{
@ -58,7 +57,7 @@ func TestHandler(t *testing.T) {
rcode: dns.RcodeServerFailure,
qclass: dns.ClassANY,
qtype: dns.TypeANY,
fall: fall.F{Zones: []string{"."}},
fall: fall.Root,
zones: []string{"."},
}
brokenTemplate := template{
@ -66,7 +65,7 @@ func TestHandler(t *testing.T) {
answer: []*gotmpl.Template{gotmpl.Must(gotmpl.New("answer").Parse("{{ .Name }} 60 IN TXT \"{{ index .Match 2 }}\""))},
qclass: dns.ClassANY,
qtype: dns.TypeANY,
fall: fall.F{Zones: []string{"."}},
fall: fall.Root,
zones: []string{"."},
}
nonRRTemplate := template{
@ -74,7 +73,7 @@ func TestHandler(t *testing.T) {
answer: []*gotmpl.Template{gotmpl.Must(gotmpl.New("answer").Parse("{{ .Name }}"))},
qclass: dns.ClassANY,
qtype: dns.TypeANY,
fall: fall.F{Zones: []string{"."}},
fall: fall.Root,
zones: []string{"."},
}
nonRRAdditionalTemplate := template{
@ -82,7 +81,7 @@ func TestHandler(t *testing.T) {
additional: []*gotmpl.Template{gotmpl.Must(gotmpl.New("answer").Parse("{{ .Name }}"))},
qclass: dns.ClassANY,
qtype: dns.TypeANY,
fall: fall.F{Zones: []string{"."}},
fall: fall.Root,
zones: []string{"."},
}
nonRRAuthoritativeTemplate := template{
@ -90,7 +89,7 @@ func TestHandler(t *testing.T) {
authority: []*gotmpl.Template{gotmpl.Must(gotmpl.New("authority").Parse("{{ .Name }}"))},
qclass: dns.ClassANY,
qtype: dns.TypeANY,
fall: fall.F{Zones: []string{"."}},
fall: fall.Root,
zones: []string{"."},
}
@ -297,7 +296,6 @@ func TestHandler(t *testing.T) {
// TestMultiSection verfies that a corefile with mutliple but different template sections works
func TestMultiSection(t *testing.T) {
rcodeFallthrough := 3841 // reserved for private use, used to indicate a fallthrough
ctx := context.TODO()
multisectionConfig := `
@ -438,5 +436,6 @@ func TestMultiSection(t *testing.T) {
if code != dns.RcodeNameError {
t.Fatalf("TestMultiSection expected NXDOMAIN resolving something.example. IN MX, got %v, %v", code, dns.RcodeToString[code])
}
}
const rcodeFallthrough = 3841 // reserved for private use, used to indicate a fallthrough