Skip to content

Commit

Permalink
More lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ordishs committed Nov 1, 2024
1 parent 490b5ef commit 1bdd8e1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize
ExposedPorts: []string{redisServicePort},
WaitingFor: newRedisWaitStrategy(),
}

genericContainerRequest := testcontainers.GenericContainerRequest{
ContainerRequest: containerRequest,
Started: true,
}

for _, opt := range opts {
if err := opt.Customize(&genericContainerRequest); err != nil {
return nil, fmt.Errorf("failed to apply option: %w", err)
Expand All @@ -47,6 +49,7 @@ func (c RedisContainer) ServicePort(ctx context.Context) (int, error) {
if err != nil {
return 0, err
}

return port.Int(), nil
}

Expand Down
2 changes: 2 additions & 0 deletions redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ func TestSet(t *testing.T) {

container, err := RunContainer(ctx)
require.NoError(t, err)

t.Cleanup(func() {
err := container.Terminate(ctx)
require.NoErrorf(t, err, "failed to terminate Redis container")
})

host, err := container.Host(ctx)
require.NoErrorf(t, err, "failed to fetch Redis host")

port, err := container.ServicePort(ctx)
require.NoErrorf(t, err, "failed to fetch Redis port")

Expand Down
5 changes: 5 additions & 0 deletions wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ func (s redisWaitStrategy) WaitUntilReady(ctx context.Context, target wait.Strat
if err != nil {
return fmt.Errorf("failed to fetch host: %w", err)
}

port, err := target.MappedPort(ctx, redisServicePort)
if err != nil {
return fmt.Errorf("failed to fetch port: %w", err)
}

return s.pollUntilReady(ctx, host, port.Int())
}

Expand All @@ -46,11 +48,13 @@ func (s redisWaitStrategy) pollUntilReady(ctx context.Context, host string, port
select {
case <-ctx.Done():
return fmt.Errorf("timed out while waiting for Redis to start: %w", ctx.Err())

case <-time.After(defaultPollInterval):
isReady, err := s.isReady(ctx, host, port)
if err != nil {
return err
}

if isReady {
return nil
}
Expand All @@ -68,5 +72,6 @@ func (s redisWaitStrategy) isReady(ctx context.Context, host string, port int) (
if err != nil {
return false, nil
}

return true, nil
}

0 comments on commit 1bdd8e1

Please sign in to comment.