зеркало из https://github.com/mozilla/scribe.git
add validation for test sources
This commit is contained in:
Родитель
db0846a475
Коммит
a76b89868f
|
@ -18,8 +18,8 @@ type Document struct {
|
|||
}
|
||||
|
||||
func (d *Document) Validate() error {
|
||||
for _, x := range d.Tests {
|
||||
err := x.validate(d)
|
||||
for i := range d.Tests {
|
||||
err := d.Tests[i].validate(d)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -34,6 +34,27 @@ type matchLine struct {
|
|||
groups []string
|
||||
}
|
||||
|
||||
func (f *FileContent) validate() error {
|
||||
if len(f.Path) == 0 {
|
||||
return fmt.Errorf("filecontent path must be set")
|
||||
}
|
||||
if len(f.File) == 0 {
|
||||
return fmt.Errorf("filecontent file must be set")
|
||||
}
|
||||
_, err := regexp.Compile(f.File)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(f.Expression) == 0 {
|
||||
return fmt.Errorf("filecontent expression must be set")
|
||||
}
|
||||
_, err = regexp.Compile(f.Expression)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *FileContent) expandVariables(v []Variable) {
|
||||
f.Path = variableExpansion(v, f.Path)
|
||||
f.File = variableExpansion(v, f.File)
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
package scribe
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
|
@ -22,6 +23,16 @@ type nameMatch struct {
|
|||
match string
|
||||
}
|
||||
|
||||
func (f *FileName) validate() error {
|
||||
if len(f.Path) == 0 {
|
||||
return fmt.Errorf("filename path must be set")
|
||||
}
|
||||
if len(f.File) == 0 {
|
||||
return fmt.Errorf("filename file must be set")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *FileName) expandVariables(v []Variable) {
|
||||
f.Path = variableExpansion(v, f.Path)
|
||||
}
|
||||
|
|
|
@ -81,6 +81,13 @@ func (c *ConcatModifier) prepare() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *ConcatModifier) validate() error {
|
||||
if len(c.Operator) == 0 {
|
||||
return fmt.Errorf("must specify concat operator")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *ConcatModifier) expandVariables(v []Variable) {
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,10 @@
|
|||
// - Aaron Meihm ameihm@mozilla.com
|
||||
package scribe
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Package struct {
|
||||
Name string `json:"name"`
|
||||
pkgInfo []PackageInfo
|
||||
|
@ -16,6 +20,13 @@ type PackageInfo struct {
|
|||
Version string
|
||||
}
|
||||
|
||||
func (p *Package) validate() error {
|
||||
if len(p.Name) == 0 {
|
||||
return fmt.Errorf("package must specify name")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Package) getCriteria() (ret []EvaluationCriteria) {
|
||||
for _, x := range p.pkgInfo {
|
||||
n := EvaluationCriteria{}
|
||||
|
|
|
@ -63,6 +63,7 @@ type genericSource interface {
|
|||
prepare() error
|
||||
getCriteria() []EvaluationCriteria
|
||||
expandVariables([]Variable)
|
||||
validate() error
|
||||
}
|
||||
|
||||
type genericEvaluator interface {
|
||||
|
@ -76,9 +77,14 @@ func (t *Test) validate(d *Document) error {
|
|||
if len(t.Identifier) == 0 {
|
||||
return fmt.Errorf("%v: no identifier", t.Name)
|
||||
}
|
||||
if t.getSourceInterface() == nil {
|
||||
si := t.getSourceInterface()
|
||||
if si == nil {
|
||||
return fmt.Errorf("%v: no valid source interface", t.Name)
|
||||
}
|
||||
err := si.validate()
|
||||
if err != nil {
|
||||
return fmt.Errorf("%v: %v", t.Name, err)
|
||||
}
|
||||
if t.getEvaluationInterface() == nil {
|
||||
return fmt.Errorf("%v: no valid evaluation interface", t.Name)
|
||||
}
|
||||
|
@ -88,10 +94,13 @@ func (t *Test) validate(d *Document) error {
|
|||
}
|
||||
}
|
||||
for _, x := range t.If {
|
||||
_, err := d.getTest(x)
|
||||
ptr, err := d.getTest(x)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%v: %v", t.Name, err)
|
||||
}
|
||||
if ptr == t {
|
||||
return fmt.Errorf("%v: test cannot reference itself", t.Name)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче