Skip to content

chore(container): delegate FromID to FindContainerByID and add unit tests for errors#132

Open
xHozey wants to merge 3 commits intodocker:mainfrom
xHozey:chore/fromid-use-findcontainerbyid
Open

chore(container): delegate FromID to FindContainerByID and add unit tests for errors#132
xHozey wants to merge 3 commits intodocker:mainfrom
xHozey:chore/fromid-use-findcontainerbyid

Conversation

@xHozey
Copy link
Contributor

@xHozey xHozey commented Feb 11, 2026

What does this PR do?

This PR refactors the FromID helper to delegate container lookup to FindContainerByID instead of manually calling ContainerList and applying filters internally.

It also adds unit tests for error cases, including empty container ID and non-existent container ID, to ensure proper handling of failure scenarios.

As a result, the error messages and types returned by FromID may differ slightly:

  • Errors are now wrapped with "find container by ID" prefixes.

  • The empty-containerID case now returns an invalid-argument error from FindContainerByID rather than going through ContainerList.

Why is it important?

This change reduces duplication and centralizes container ID lookup logic in a single place. By relying on FindContainerByID, we ensure consistent filtering behavior across the SDK and make future maintenance easier.

If the lookup implementation changes in the future, it only needs to be updated in one location. This improves code clarity and maintainability without modifying the public API or core functionality.

How to test this PR

inside container package in container.from_test.go run TestFromID function

Copilot AI review requested due to automatic review settings February 11, 2026 18:03
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors container.FromID to centralize container ID lookup by delegating to SDKClient.FindContainerByID, instead of calling ContainerList and filtering within the container package.

Changes:

  • Replaced ContainerList + manual filtering in FromID with a call to FindContainerByID.
  • Simplified FromID to only build a Container from the returned summary via FromResponse.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@xHozey xHozey changed the title chore(container): reuse FindContainerByID in FromID chore(container): delegate FromID to FindContainerByID and add unit tests for errors Feb 11, 2026
@mdelapenya mdelapenya self-assigned this Feb 17, 2026
Comment on lines +50 to +53
ctr, err := container.Run(context.Background(), container.WithImage("alpine:latest"))
require.NoError(t, err)

cli := ctr.Client()
Copy link
Member

Choose a reason for hiding this comment

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

bug: I think this container is going to be running forever. Not an issue on CI because of the ephemeral nature of the workers. I think we can get a new fresh client without the ctr.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants