From 8a09da33110104756d72a19510823eee28d4b880 Mon Sep 17 00:00:00 2001 From: Jay Pipes Date: Mon, 27 May 2024 10:40:23 -0400 Subject: [PATCH] fix failure evaluation 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 --- assertions.go | 2 +- eval.go | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/assertions.go b/assertions.go index a9cb881..b1043e5 100644 --- a/assertions.go +++ b/assertions.go @@ -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) diff --git a/eval.go b/eval.go index 5638547..cde1f94 100644 --- a/eval.go +++ b/eval.go @@ -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) @@ -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, @@ -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()...)) }