mirror of
https://github.com/coredns/coredns.git
synced 2025-11-01 02:33:14 -04:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user