blob: ee65327c9fe5bff76560cc8a05367b6bf962e2a0 [file] [log] [blame]
package validators
import (
"strconv"
)
// HasDocumentsValidator validate whether the count of manifests rendered form template is Count
type HasDocumentsValidator struct {
Count int
}
func (v HasDocumentsValidator) failInfo(actual int, not bool) []string {
var notAnnotation string
if not {
notAnnotation = " NOT to be"
}
hasDocumentsFailFormat := "Expected documents count" + notAnnotation + ":%s"
if not {
return splitInfof(hasDocumentsFailFormat, -1, strconv.Itoa(v.Count))
}
return splitInfof(
hasDocumentsFailFormat+"\nActual:%s",
-1,
strconv.Itoa(v.Count),
strconv.Itoa(actual),
)
}
// Validate implement Validatable
func (v HasDocumentsValidator) Validate(context *ValidateContext) (bool, []string) {
if len(context.Docs) == v.Count != context.Negative {
return true, []string{}
}
return false, v.failInfo(len(context.Docs), context.Negative)
}