Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix filenotfound assertion validation #54

Merged
merged 1 commit into from
Aug 31, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions unittest/assertion.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ func (a *Assertion) Assert(
result.Not = a.Not

// Ensure assertion is succeeding or failing based on templates to test.
assertionPassed := len(a.defaultTemplates) > 0
assertionPassed := false
failInfo := make([]string, 0)

for _, template := range a.defaultTemplates {
for idx, template := range a.defaultTemplates {
rendered, ok := templatesResult[template]
var validatePassed bool
var singleFailInfo []string
if !ok {
noFile := []string{"Error:", a.noFileErrMessage()}
noFile := []string{"Error:", a.noFileErrMessage(template)}
failInfo = append(failInfo, noFile...)
assertionPassed = false
break
Expand All @@ -57,6 +57,10 @@ func (a *Assertion) Assert(
singleFailInfo = append(failInfoTemplate, singleFailInfo...)
}

if idx == 0 {
assertionPassed = true
}

assertionPassed = assertionPassed && validatePassed
failInfo = append(failInfo, singleFailInfo...)
}
Expand All @@ -67,13 +71,14 @@ func (a *Assertion) Assert(
return result
}

func (a *Assertion) noFileErrMessage() string {
if a.Template != "" {
func (a *Assertion) noFileErrMessage(template string) string {
if template != "" {
return fmt.Sprintf(
"\ttemplate \"%s\" not exists or not selected in test suite",
a.Template,
template,
)
}

return "\tassertion.template must be given if testsuite.templates is empty"
}

Expand All @@ -93,6 +98,7 @@ func (a *Assertion) UnmarshalYAML(unmarshal func(interface{}) error) error {
if not, ok := assertDef["not"].(bool); ok {
a.Not = not
}

if template, ok := assertDef["template"].(string); ok {
a.Template = template
}
Expand Down