Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions modules/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,24 @@ func (c *RegistryContainer) PushImage(ctx context.Context, ref string) error {
return fmt.Errorf("failed to encode image auth: %w", err)
}

_, err = dockerCli.ImagePush(ctx, ref, client.ImagePushOptions{
output, err := dockerCli.ImagePush(ctx, ref, client.ImagePushOptions{
All: true,
RegistryAuth: encodedAuth,
})
if err != nil {
return fmt.Errorf("push image %q: %w", ref, err)
}

return c.ImageExists(ctx, ref)
for m, err := range output.JSONMessages(ctx) {
if err != nil {
return fmt.Errorf("push image %q: %w", ref, err)
}
if err := m.Error; err != nil {
return fmt.Errorf("push image %q: %w", ref, err)
}
Comment on lines +203 to +209

@coderabbitai coderabbitai Bot Jun 25, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Locate PushImage/ImagePush tests and check whether JSONMessages iterator
# errors and per-message push errors are covered.

rg -n -C4 --type go '\bPushImage\b|\bImagePush\b|JSONMessages|\.Error\b' .

Repository: testcontainers/testcontainers-go

Length of output: 50389


🏁 Script executed:

cat -n modules/registry/registry_test.go | head -250

Repository: testcontainers/testcontainers-go

Length of output: 9168


🏁 Script executed:

grep -n "PushImage" modules/registry/registry_test.go

Repository: testcontainers/testcontainers-go

Length of output: 170


🏁 Script executed:

grep -rn "PushImage" modules/registry/

Repository: testcontainers/testcontainers-go

Length of output: 781


🏁 Script executed:

cat -n modules/registry/examples_test.go | sed -n '178,230p'

Repository: testcontainers/testcontainers-go

Length of output: 2016


Add coverage for push stream errors.

The PushImage implementation now iterates the push stream to detect errors. Currently, PushImage is only exercised in example code which assumes success. Add a unit test to explicitly verify that both the iterator error (range loop err) and the per-message m.Error are handled and returned.

func TestPushImage_HandleStreamErrors(t *testing.T) {
	// TODO: Mock the Docker client ImagePush to return a stream that yields:
	// 1. An iterator error (e.g., context cancellation).
	// 2. An `m.Error` in the JSON message payload.
	// Verify that PushImage returns the wrapped error in both cases.
	// This confirms the silent-push regression is addressed.
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@modules/registry/registry.go` around lines 203 - 209, Add a unit test around
PushImage in registry.go to cover push stream failure handling. Create
TestPushImage_HandleStreamErrors that mocks Docker client ImagePush and
exercises the JSONMessages(ctx) iteration path in both failure modes: a non-nil
iterator error from the range loop and a non-nil m.Error on a JSON message.
Verify PushImage returns the wrapped ref-specific error in each case, using the
PushImage and JSONMessages symbols to target the behavior.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@austindrenski can you add the unit test, as suggested by the bot?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mdelapenya Agreed — adding that targeted coverage would be helpful here, especially for both JSONMessages(ctx) failure modes: iterator errors and per-message m.Error values.

}

return nil
}

// PullImage pulls an image from an external registry into the local Docker daemon.
Expand Down