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

Add TestAssert support for errors files #457

Closed
wants to merge 4 commits into from
Closed
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
24 changes: 23 additions & 1 deletion pkg/test/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,10 @@ func (s *Step) LoadYAML(file string) error {

for _, obj := range s.Asserts {
if obj.GetObjectKind().GroupVersionKind().Kind == "TestAssert" {
if s.Assert != nil {
return fmt.Errorf("more than 1 TestAssert not allowed in step %q", s.Name)
}

if testAssert, ok := obj.DeepCopyObject().(*harness.TestAssert); ok {
s.Assert = testAssert
} else {
Expand All @@ -535,6 +539,23 @@ func (s *Step) LoadYAML(file string) error {
}
}

errors := []client.Object{}

for _, obj := range s.Errors {
if obj.GetObjectKind().GroupVersionKind().Kind == "TestAssert" {
if s.Assert != nil {
return fmt.Errorf("more than 1 TestAssert not allowed in step %q", s.Name)
}
if testAssert, ok := obj.DeepCopyObject().(*harness.TestAssert); ok {
s.Assert = testAssert
} else {
return fmt.Errorf("failed to load TestAssert object from %s: it contains an object of type %T", file, obj)
}
} else {
errors = append(errors, obj)
}
}

applies := []client.Object{}

for _, obj := range s.Apply {
Expand Down Expand Up @@ -587,12 +608,13 @@ func (s *Step) LoadYAML(file string) error {
if err != nil {
return fmt.Errorf("step %q error path %s: %w", s.Name, exError, err)
}
s.Errors = append(s.Errors, errObjs...)
errors = append(errors, errObjs...)
}
}

s.Apply = applies
s.Asserts = asserts
s.Errors = errors
return nil
}

Expand Down
Loading