Skip to content

Commit

Permalink
tests: improve test coverage
Browse files Browse the repository at this point in the history
Improve test coverage as per review feedback.
  • Loading branch information
stevenh committed Nov 22, 2024
1 parent 10f341e commit 83a7838
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions wait/walk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func TestWalk(t *testing.T) {
require.Equal(t, 2, matched)

count = 0
matched = 0
err = wait.Walk(&req.WaitingFor, func(s wait.Strategy) error {
count++
if _, ok := s.(*wait.FileStrategy); ok {
Expand All @@ -66,6 +67,7 @@ func TestWalk(t *testing.T) {
})
require.NoError(t, err)
require.Equal(t, 3, count)
require.Zero(t, matched)
})

t.Run("remove-stop", func(t *testing.T) {
Expand All @@ -84,4 +86,40 @@ func TestWalk(t *testing.T) {
require.Equal(t, 1, count)
require.Nil(t, req.WaitingFor)
})

t.Run("nil-root", func(t *testing.T) {
err := wait.Walk(nil, func(_ wait.Strategy) error {
return nil
})
require.EqualError(t, err, "root strategy is nil")
})

t.Run("direct-single", func(t *testing.T) {
req := testcontainers.ContainerRequest{
WaitingFor: wait.ForFile("/tmp/file"),
}
requireVisits(t, req, 1)
})

t.Run("for-all-single", func(t *testing.T) {
req := testcontainers.ContainerRequest{
WaitingFor: wait.ForAll(
wait.ForFile("/tmp/file"),
),
}
requireVisits(t, req, 2)
})
}

// requireVisits validates the number of visits for a given request.
func requireVisits(t *testing.T, req testcontainers.ContainerRequest, expected int) {
t.Helper()

var count int
err := wait.Walk(&req.WaitingFor, func(_ wait.Strategy) error {
count++
return nil
})
require.NoError(t, err)
require.Equal(t, expected, count)
}

0 comments on commit 83a7838

Please sign in to comment.