Skip to content

[feat] Rewrite stub + comprehensive mirror pull tests#323

Open
ldmonster wants to merge 6 commits intomainfrom
feat/new-stub-client
Open

[feat] Rewrite stub + comprehensive mirror pull tests#323
ldmonster wants to merge 6 commits intomainfrom
feat/new-stub-client

Conversation

@ldmonster
Copy link
Copy Markdown
Collaborator

@ldmonster ldmonster commented Apr 8, 2026

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 entire mirror pull pipeline — platform, installer, security, modules, and the top-level PullService.


Why

The previous stub was a single 932-line file that embedded hard-coded switch statements to guess version.json content 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

File Purpose
registry_client.go deleted
registry.go In-memory registry: per-repo image store, MustAddImage, tag listing
client.go Client implementing localreg.Client via WithSegment path routing
image.go ImageBuilder fluent API: WithFile, WithLabel, MustBuild
deckhouse_stub.go NewRegistryClientStub() — Deckhouse-shaped default fixture
client_test.go / registry_test.go / image_test.go / deckhouse_stub_test.go Full coverage of all four new files

Key design properties:

  • Composable: NewRegistry(host) + reg.MustAddImage(repo, tag, img) — tests control exactly what's in the registry.
  • No inference: images contain what you put in them; no tag-name guessing.
  • Path-routed: client.WithSegment("release-channel") builds a scoped client for the release-channel repo — identical interface to the real registry client.
  • Push support: PushImage auto-creates repos, making push-path tests possible.

service.go

NewService now skips WithSegment(edition) when edition == 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 PullPlatform into a separate file to keep platform.go focused on the real pull logic.

pull.go

When STUB_REGISTRY_CLIENT=true the stub client is substituted and edition is reset to pkg.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.

Signed-off-by: Pavel Okhlopkov <pavel.okhlopkov@flant.com>
Signed-off-by: Pavel Okhlopkov <pavel.okhlopkov@flant.com>
@ldmonster ldmonster self-assigned this Apr 8, 2026
@ldmonster ldmonster added the enhancement New feature or request label Apr 8, 2026
Signed-off-by: Pavel Okhlopkov <pavel.okhlopkov@flant.com>
Signed-off-by: Pavel Okhlopkov <pavel.okhlopkov@flant.com>
Signed-off-by: Pavel Okhlopkov <pavel.okhlopkov@flant.com>
@ldmonster ldmonster changed the title [feat] new stub client [feat] Rewrite stub + comprehensive mirror pull tests Apr 8, 2026
@ldmonster ldmonster requested a review from Glitchy-Sheep April 8, 2026 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant