test(constraint): unit tests + integration tests + make validate

This commit is contained in:
Samuel BERTHE 2016-05-20 17:17:38 +02:00
parent cd2100ed84
commit f46accc74d
7 changed files with 362 additions and 40 deletions

View file

@ -29,22 +29,21 @@ type BaseProvider struct {
// MatchConstraints must match with EVERY single contraint
// returns first constraint that do not match or nil
// returns errors for future use (regex)
func (p *BaseProvider) MatchConstraints(tags []string) (bool, *types.Constraint, error) {
func (p *BaseProvider) MatchConstraints(tags []string) (bool, *types.Constraint) {
// if there is no tags and no contraints, filtering is disabled
if len(tags) == 0 && len(p.Constraints) == 0 {
return true, nil, nil
return true, nil
}
for _, constraint := range p.Constraints {
if ok := constraint.MatchConstraintWithAtLeastOneTag(tags); xor(ok == true, constraint.MustMatch == true) {
return false, constraint, nil
// xor: if ok and constraint.MustMatch are equal, then no tag is currently matching with the constraint
if ok := constraint.MatchConstraintWithAtLeastOneTag(tags); ok != constraint.MustMatch {
return false, constraint
}
}
// If no constraint or every constraints matching
return true, nil, nil
>>>>>>> e844462... feat(constraints): Implementation of constraints (cmd + toml + matching functions), implementation proposal with consul
return true, nil
}
func (p *BaseProvider) getConfiguration(defaultTemplateFile string, funcMap template.FuncMap, templateObjects interface{}) (*types.Configuration, error) {
@ -98,8 +97,3 @@ func normalize(name string) string {
// get function
return strings.Join(strings.FieldsFunc(name, fargs), "-")
}
// golang does not support ^ operator
func xor(cond1 bool, cond2 bool) bool {
return cond1 != cond2
}