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 4ddf8da
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
20 changes: 16 additions & 4 deletions .github/workflows/gate-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
test-skip-kind:
strategy:
matrix:
go-version: [1.19.x, 1.20.x]
go: ['1.19', '1.20', '1.21']
os: [macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -24,10 +24,15 @@ jobs:
disable-sudo: true
allowed-endpoints: >
github.com:443
api.github.com:443
proxy.github.com:443
raw.githubusercontent.com:443
objects.githubusercontent.com:443
proxy.golang.org:443
- name: checkout code
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- name: setup go
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
go-version: ${{ matrix.go }}
- name: run non-Kind tests
Expand All @@ -37,7 +42,7 @@ jobs:
test-all:
strategy:
matrix:
go-version: [1.19.x, 1.20.x]
go: ['1.19', '1.20', '1.21']
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -46,10 +51,17 @@ jobs:
with:
egress-policy: audit
disable-sudo: false
allowed-endpoints: >
github.com:443
api.github.com:443
proxy.github.com:443
raw.githubusercontent.com:443
objects.githubusercontent.com:443
proxy.golang.org:443
- name: checkout code
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- name: setup go
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
go-version: ${{ matrix.go }}
- name: create KinD cluster
Expand Down
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 4ddf8da

Please sign in to comment.