dont require/allow "_" prefix for srv wildcard fields (#472)

* dont require/allow "_" prefix for srv wildcard fields

* streamline parse/validation of req name

* removing nametemplate

* error when zone not found, loopify unit tests
This commit is contained in:
Chris O'Haver 2017-01-15 03:12:28 -05:00 committed by Miek Gieben
parent b6a2a5aeaa
commit a6d232a622
9 changed files with 245 additions and 600 deletions

View file

@ -16,7 +16,6 @@ func TestKubernetesParse(t *testing.T) {
shouldErr bool // true if test case is exected to produce an error.
expectedErrContent string // substring from the expected error. Empty for positive cases.
expectedZoneCount int // expected count of defined zones.
expectedNTValid bool // NameTemplate to be initialized and valid
expectedNSCount int // expected count of namespaces.
expectedResyncPeriod time.Duration // expected resync period value
expectedLabelSelector string // expected label selector value
@ -28,7 +27,6 @@ func TestKubernetesParse(t *testing.T) {
false,
"",
1,
true,
0,
defaultResyncPeriod,
"",
@ -39,7 +37,6 @@ func TestKubernetesParse(t *testing.T) {
false,
"",
2,
true,
0,
defaultResyncPeriod,
"",
@ -51,7 +48,6 @@ func TestKubernetesParse(t *testing.T) {
false,
"",
1,
true,
0,
defaultResyncPeriod,
"",
@ -64,20 +60,6 @@ func TestKubernetesParse(t *testing.T) {
false,
"",
1,
true,
0,
defaultResyncPeriod,
"",
},
{
"template keyword with valid template",
`kubernetes coredns.local {
template {service}.{namespace}.{zone}
}`,
false,
"",
1,
true,
0,
defaultResyncPeriod,
"",
@ -90,7 +72,6 @@ func TestKubernetesParse(t *testing.T) {
false,
"",
1,
true,
1,
defaultResyncPeriod,
"",
@ -103,7 +84,6 @@ func TestKubernetesParse(t *testing.T) {
false,
"",
1,
true,
2,
defaultResyncPeriod,
"",
@ -116,7 +96,6 @@ func TestKubernetesParse(t *testing.T) {
false,
"",
1,
true,
0,
30 * time.Second,
"",
@ -129,7 +108,6 @@ func TestKubernetesParse(t *testing.T) {
false,
"",
1,
true,
0,
15 * time.Minute,
"",
@ -142,7 +120,6 @@ func TestKubernetesParse(t *testing.T) {
false,
"",
1,
true,
0,
defaultResyncPeriod,
"environment=prod",
@ -155,7 +132,6 @@ func TestKubernetesParse(t *testing.T) {
false,
"",
1,
true,
0,
defaultResyncPeriod,
"application=nginx,environment in (production,qa,staging)",
@ -165,14 +141,12 @@ func TestKubernetesParse(t *testing.T) {
`kubernetes coredns.local test.local {
resyncperiod 15m
endpoint http://localhost:8080
template {service}.{namespace}.{zone}
namespaces demo test
labels environment in (production, staging, qa),application=nginx
}`,
false,
"",
2,
true,
2,
15 * time.Minute,
"application=nginx,environment in (production,qa,staging)",
@ -184,7 +158,6 @@ func TestKubernetesParse(t *testing.T) {
true,
"Kubernetes setup called without keyword 'kubernetes' in Corefile",
-1,
false,
-1,
defaultResyncPeriod,
"",
@ -195,7 +168,6 @@ func TestKubernetesParse(t *testing.T) {
true,
"Zone name must be provided for kubernetes middleware",
-1,
true,
0,
defaultResyncPeriod,
"",
@ -208,37 +180,10 @@ func TestKubernetesParse(t *testing.T) {
true,
"Wrong argument count or unexpected line ending after 'endpoint'",
-1,
true,
-1,
defaultResyncPeriod,
"",
},
{
"template keyword without a template value",
`kubernetes coredns.local {
template
}`,
true,
"Wrong argument count or unexpected line ending after 'template'",
-1,
false,
0,
defaultResyncPeriod,
"",
},
{
"template keyword with an invalid template value",
`kubernetes coredns.local {
template {namespace}.{zone}
}`,
true,
"Record name template does not pass NameTemplate validation",
-1,
false,
0,
defaultResyncPeriod,
"",
},
{
"namespace keyword without a namespace value",
`kubernetes coredns.local {
@ -247,7 +192,6 @@ func TestKubernetesParse(t *testing.T) {
true,
"Parse error: Wrong argument count or unexpected line ending after 'namespaces'",
-1,
true,
-1,
defaultResyncPeriod,
"",
@ -260,7 +204,6 @@ func TestKubernetesParse(t *testing.T) {
true,
"Wrong argument count or unexpected line ending after 'resyncperiod'",
-1,
true,
0,
0 * time.Minute,
"",
@ -273,7 +216,6 @@ func TestKubernetesParse(t *testing.T) {
true,
"Unable to parse resync duration value. Value provided was ",
-1,
true,
0,
0 * time.Second,
"",
@ -286,7 +228,6 @@ func TestKubernetesParse(t *testing.T) {
true,
"Unable to parse resync duration value. Value provided was ",
-1,
true,
0,
0 * time.Second,
"",
@ -299,7 +240,6 @@ func TestKubernetesParse(t *testing.T) {
true,
"Wrong argument count or unexpected line ending after 'labels'",
-1,
true,
0,
0 * time.Second,
"",
@ -312,7 +252,6 @@ func TestKubernetesParse(t *testing.T) {
true,
"Unable to parse label selector. Value provided was",
-1,
true,
0,
0 * time.Second,
"",
@ -354,16 +293,6 @@ func TestKubernetesParse(t *testing.T) {
t.Errorf("Test %d: Expected kubernetes controller to be initialized with %d zones, instead found %d zones: '%v' for input '%s'", i, test.expectedZoneCount, foundZoneCount, k8sController.Zones, test.input)
}
// NameTemplate
if k8sController.NameTemplate == nil {
t.Errorf("Test %d: Expected kubernetes controller to be initialized with a NameTemplate. Instead found '%v' for input '%s'", i, k8sController.NameTemplate, test.input)
} else {
foundNTValid := k8sController.NameTemplate.IsValid()
if foundNTValid != test.expectedNTValid {
t.Errorf("Test %d: Expected NameTemplate validity to be '%v', instead found '%v' for input '%s'", i, test.expectedNTValid, foundNTValid, test.input)
}
}
// Namespaces
foundNSCount := len(k8sController.Namespaces)
if foundNSCount != test.expectedNSCount {