Skip to content

fix: consume ImagePushResponse - #3739

Open
austindrenski wants to merge 1 commit into
testcontainers:mainfrom
austindrenski:patch-1
Open

fix: consume ImagePushResponse#3739
austindrenski wants to merge 1 commit into
testcontainers:mainfrom
austindrenski:patch-1

Conversation

@austindrenski

Copy link
Copy Markdown

What does this PR do?

Fix to consume the image push response (mirrors existing handling for image pull response).

Why is it important?

Encountered an issue this afternoon where pushing to the testcontainers-hosted registry silently failed, leaving tests to hang on the c.ImageExists(...) check.

I initially patched this locally just to bubble the error message, but surprisingly enough it also fixed the silent failure. I'm not sure if it's entirely deterministic (e.g., tcp backpressure?), or depends on the complexity of the image being pushed (in my case, pushing the registry:latest image into the testcontainers-hosted registry:latest container :D).

This bug probably deserves more test coverage, but I'm short on time tonight, and wanted to at least get the patch posted before I lose track of it (c'est la vie).

@austindrenski
austindrenski requested a review from a team as a code owner June 25, 2026 00:33
@netlify

netlify Bot commented Jun 25, 2026

Copy link
Copy Markdown

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit 6ea6bf7
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-go/deploys/6a3c852cec1bfd00089f5c8c
😎 Deploy Preview https://deploy-preview-3739--testcontainers-go.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Summary by CodeRabbit

  • Bug Fixes
    • Improved image push reliability by ensuring the full push output is fully processed before reporting success.
    • Enhanced error reporting with clearer context for failures during both the push start and while handling the push stream.
    • Removed the extra post-push verification step; success is now determined after successful completion of the push and its output processing.

Walkthrough

RegistryContainer.PushImage now consumes Docker push output messages and returns after successful message processing instead of verifying image existence afterward.

Changes

Registry image push completion

Layer / File(s) Summary
Push output wait
modules/registry/registry.go
PushImage stores the ImagePush output handle, reads JSONMessages(ctx), wraps stream and message errors, and returns nil after successful processing.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I hopped along the registry stream,
Watching push messages gleam.
When the last one passed through clean,
I bounced away with nil unseen!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: consuming the image push response.
Description check ✅ Passed The description is clearly related and explains the push-response handling fix and its motivation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@austindrenski austindrenski changed the title Consume ImagePushResponse fix: consume ImagePushResponse Jun 25, 2026
@austindrenski
austindrenski force-pushed the patch-1 branch 2 times, most recently from 8aa14ae to 93de899 Compare June 25, 2026 00:55

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with 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.

Inline comments:
In `@modules/registry/registry.go`:
- Around line 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.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 55bfaf99-3946-41ea-bdee-554f2a0a409e

📥 Commits

Reviewing files that changed from the base of the PR and between 93de899 and 6ea6bf7.

📒 Files selected for processing (1)
  • modules/registry/registry.go

Comment on lines +203 to +209
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)
}

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants