[feat] Rewrite stub + comprehensive mirror pull tests#323
Open
[feat] Rewrite stub + comprehensive mirror pull tests#323
Conversation
Signed-off-by: Pavel Okhlopkov <pavel.okhlopkov@flant.com>
Signed-off-by: Pavel Okhlopkov <pavel.okhlopkov@flant.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR replaces the monolithic, brittle
pkg/stub/registry_client.go(932 lines) with a clean, composable in-memory stub library split into focused files. It then uses the new stub to write 168 passing tests across the entiremirrorpull pipeline — platform, installer, security, modules, and the top-levelPullService.Why
The previous stub was a single 932-line file that embedded hard-coded
switchstatements to guessversion.jsoncontent from tag names, re-implemented raw gzip/tar construction manually, and had no way to register custom repos or images. Adding new tests required patching the stub itself. Any image the stub hadn't anticipated returned wrong data silently.What changed
stub — rewritten from scratch
registry_client.goMustAddImage, tag listingClientimplementinglocalreg.ClientviaWithSegmentpath routingImageBuilderfluent API:WithFile,WithLabel,MustBuildNewRegistryClientStub()— Deckhouse-shaped default fixtureclient_test.go/registry_test.go/image_test.go/ deckhouse_stub_test.goKey design properties:
NewRegistry(host)+reg.MustAddImage(repo, tag, img)— tests control exactly what's in the registry.client.WithSegment("release-channel")builds a scoped client for therelease-channelrepo — identical interface to the real registry client.PushImageauto-creates repos, making push-path tests possible.service.go
NewServicenow skipsWithSegment(edition)whenedition == pkg.NoEdition. This prevents double-scoping when the stub's host URL already includes the edition path segment.platform_dryrun.go
Extracted the dry-run execution path for
PullPlatforminto a separate file to keep platform.go focused on the real pull logic.pull.go
When
STUB_REGISTRY_CLIENT=truethe stub client is substituted andeditionis reset topkg.NoEdition, preventing the double-scope bug (…/fe/fe).mirror-pull-dry-run.md
New architecture document describing the DryRun execution path, what each service does/skips, and the stub fixture design.