8000 client: Migrate tests to use functional opts and extract `clientConfig` by vvoland · Pull Request #50847 · moby/moby · GitHub
[go: up one dir, main page]

Skip to content

Conversation

vvoland
Copy link
Contributor
@vvoland vvoland commented Aug 29, 2025
  • Add WithMockClient for the unit tests the create a client with mocked http transport (instead of creating the Client struct directly and messing with internal fields)
  • Refactor all unit tests to use functional opts
  • Change client.Opt to mutate an internal config field instead of the whole Client instance

- How to verify it

CI

vvoland added 21 commits August 29, 2025 15:07
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
All of its usage was replaced by WithMockClient

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Change functional options for the client so that they operate on an
intermediate struct instead of the public `Client` instance directly.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
@vvoland vvoland added this to the 29.0.0 milestone Aug 29, 2025
@vvoland vvoland self-assigned this Aug 29, 2025
@vvoland vvoland added kind/refactor PR's that refactor, or clean-up code area/go-sdk go-modules labels Aug 29, 2025
Copy link
Member
@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Left one blurb, but not sure if that makes sense; and we can probably still do so later on (as nothing from that is exported)

Comment on lines +26 to 27
err = client.CheckpointCreate(context.Background(), "nothing", checkpoint.CreateOptions{
CheckpointID: "noting",
Copy link
Member

Choose a reason for hiding this comment

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

Heh; interesting; looks like CheckpointID had a typo? (noting instead of nothing?) or was that intentional to produce the error? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't really matter - the nothing here is the container ID, and notin is the checkpoint ID.

// performed on the first request, after which negotiated is set to "true"
// so that subsequent requests do not re-negotiate.
negotiateVersion bool
clientConfig
Copy link
Member

Choose a reason for hiding this comment

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

The only thing I was considering was if we needed to keep the “config” struct separate from the “active” config, but I had to look at the actual code to see if that made sense.

i.e. considering if WithFoo() would update the config struct, but the client fields to be updated from that config; I was mostly wondering if there would be cases where applying the configs could not be done fully atomically, and if an intermediate struct (to be applied) would be good for that.

But I haven’t given that much thought yet; that was only thinking out loud.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently all of these are used later by the Client (except the traceOpts), so it would basically require duplicating almost whole struct inside the client.

IMO, too much churn for little benefit at this point. Should we need that in future, this is easier with this PR because the config struct is private and the whole logic is the implementation detail of the Client so we can do everything we want.

Copy link
Member

Choose a reason for hiding this comment

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

Should we need that in future, this is easier with this PR because the config struct is private and the whole logic is the implementation detail of the Client so we can do everything we want.

Yeah, that's what I concluded as well; if we need to / decide to make such a change, we can do so without breaking compatibility, so big win there.

@austinvazquez austinvazquez merged commit 50d281f into moby:master Sep 3, 2025
282 of 285 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/go-sdk go-modules kind/refactor PR's that refactor, or clean-up code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0