Adding test cases for Corefile parsing (#193)

Adding test cases for Corefile parsing.
Some code refactoring to allow test reuse.
This commit is contained in:
Michael Richmond
2016-07-22 16:07:27 -07:00
committed by GitHub
parent 3ba86f2421
commit 4a3b57d81b
7 changed files with 260 additions and 44 deletions

View File

@@ -37,6 +37,11 @@ var types = []string{
"pod",
}
var requiredSymbols = []string{
"namespace",
"service",
}
// TODO: Validate that provided NameTemplate string only contains:
// * valid, known symbols, or
// * static strings
@@ -90,6 +95,12 @@ func (t *NameTemplate) SetTemplate(s string) error {
}
}
if err == nil && !t.IsValid() {
err = errors.New("Record name template does not pass NameTemplate validation")
log.Printf("[debug] %v\n", err)
return err
}
return err
}
@@ -157,6 +168,20 @@ func (t *NameTemplate) GetRecordNameFromNameValues(values NameValues) string {
return strings.Join(recordName, ".")
}
func (t *NameTemplate) IsValid() bool {
result := true
// Ensure that all requiredSymbols are found in NameTemplate
for _, symbol := range requiredSymbols {
if _, ok := t.Element[symbol]; !ok {
result = false
break
}
}
return result
}
type NameValues struct {
ServiceName string
Namespace string