diff --git a/wait/walk_test.go b/wait/walk_test.go index d81cbedbed..0a1ed5b247 100644 --- a/wait/walk_test.go +++ b/wait/walk_test.go @@ -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 { @@ -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) { @@ -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) }