Skip to content

Commit

Permalink
fix failure evaluation
Browse files Browse the repository at this point in the history
There were two problems with gdt-kube's evaluation. First, I was
improperly passing a `*interface{}` instead of a `interface{}` to the
`newAssertions()` constructor. This mean the type-casting within
methods like `assertions.lenOK()` was failing.

Secondly, I was not calling `t.Error()` appropriately when there were
failures collected from the assertions.

Signed-off-by: Jay Pipes <[email protected]>
  • Loading branch information
jaypipes committed May 27, 2024
1 parent f2cbad8 commit 8a09da3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func (a *assertions) notFoundOK() bool {
// lenOK returns true if the subject matches the Len condition, false otherwise
func (a *assertions) lenOK() bool {
exp := a.exp
if exp.Len != nil {
if exp.Len != nil && a.hasSubject() {
// if the supplied resp is a list of objects returned by the dynamic
// client check its length
list, ok := a.r.(*unstructured.UnstructuredList)
Expand Down
10 changes: 8 additions & 2 deletions eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func (s *Spec) Eval(ctx context.Context, t *testing.T) *result.Result {
ticker := backoff.NewTicker(bo)
attempts := 0
start := time.Now().UTC()
success := false
for tick := range ticker.C {
attempts++
after := tick.Sub(start)
Expand All @@ -64,8 +65,8 @@ func (s *Spec) Eval(ctx context.Context, t *testing.T) *result.Result {
return result.New(result.WithRuntimeError(err))
}
}
a = newAssertions(s.Assert, err, &out)
success := a.OK()
a = newAssertions(s.Assert, err, out)
success = a.OK()
debug.Println(
ctx, t, "%s (try %d after %s) ok: %v",
s.Title(), attempts, after, success,
Expand All @@ -81,5 +82,10 @@ func (s *Spec) Eval(ctx context.Context, t *testing.T) *result.Result {
)
}
}
if !success {
for _, fail := range a.Failures() {
t.Error(fail)
}
}
return result.New(result.WithFailures(a.Failures()...))
}

0 comments on commit 8a09da3

Please sign in to comment.