detached 6e7b92e

test(cli): generate control plane mock

commit
6e7b92eea21119cf0764f7d72868008c140e9047
author
brice · · 2026-05-22 03:44 UTC
parent
0c06e0c
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
7 files · +2808 -54
M .mockery.yaml +1 -0
@@ -52,3 +52,4 @@ packages:
5252 github.com/bnema/gordon/internal/adapters/in/cli:
5353 interfaces:
5454 pushImageOps:
55+ ControlPlane:
@@ -52,3 +52,4 @@ packages:
52 github.com/bnema/gordon/internal/adapters/in/cli:52 github.com/bnema/gordon/internal/adapters/in/cli:
53 interfaces:53 interfaces:
54 pushImageOps:54 pushImageOps:
55+ ControlPlane:
M internal/adapters/in/cli/attachments_push_test.go +8 -0
@@ -81,6 +81,14 @@ func (c *attachmentPushTestControlPlane) GetAttachmentsConfig(context.Context, s
8181 panic("unexpected call")
8282 }
8383
84+func (c *attachmentPushTestControlPlane) ListOrphanedAttachments(context.Context) ([]domain.CleanupAttachment, error) {
85+ panic("unexpected call")
86+}
87+
88+func (c *attachmentPushTestControlPlane) CleanupOrphanedAttachments(context.Context, string, bool) (*domain.CleanupReport, error) {
89+ panic("unexpected call")
90+}
91+
8492 func (c *attachmentPushTestControlPlane) FindAttachmentTargetsByImage(ctx context.Context, imageName string) ([]string, error) {
8593 if c.findAttachmentTargets != nil {
8694 return c.findAttachmentTargets(ctx, imageName)
@@ -81,6 +81,14 @@ func (c *attachmentPushTestControlPlane) GetAttachmentsConfig(context.Context, s
81 panic("unexpected call")81 panic("unexpected call")
82 }82 }
83 83
84+func (c *attachmentPushTestControlPlane) ListOrphanedAttachments(context.Context) ([]domain.CleanupAttachment, error) {
85+ panic("unexpected call")
86+}
87+
88+func (c *attachmentPushTestControlPlane) CleanupOrphanedAttachments(context.Context, string, bool) (*domain.CleanupReport, error) {
89+ panic("unexpected call")
90+}
91+
84 func (c *attachmentPushTestControlPlane) FindAttachmentTargetsByImage(ctx context.Context, imageName string) ([]string, error) {92 func (c *attachmentPushTestControlPlane) FindAttachmentTargetsByImage(ctx context.Context, imageName string) ([]string, error) {
85 if c.findAttachmentTargets != nil {93 if c.findAttachmentTargets != nil {
86 return c.findAttachmentTargets(ctx, imageName)94 return c.findAttachmentTargets(ctx, imageName)
M internal/adapters/in/cli/controlplane.go +2 -0
@@ -30,6 +30,8 @@ type ControlPlane interface {
3030
3131 GetAllAttachmentsConfig(ctx context.Context) (map[string][]string, error)
3232 GetAttachmentsConfig(ctx context.Context, domainOrGroup string) ([]string, error)
33+ ListOrphanedAttachments(ctx context.Context) ([]domain.CleanupAttachment, error)
34+ CleanupOrphanedAttachments(ctx context.Context, owner string, stop bool) (*domain.CleanupReport, error)
3335 FindAttachmentTargetsByImage(ctx context.Context, imageName string) ([]string, error)
3436 AddAttachment(ctx context.Context, domainOrGroup, image string) error
3537 RemoveAttachment(ctx context.Context, domainOrGroup, image string) error
@@ -30,6 +30,8 @@ type ControlPlane interface {
30 30
31 GetAllAttachmentsConfig(ctx context.Context) (map[string][]string, error)31 GetAllAttachmentsConfig(ctx context.Context) (map[string][]string, error)
32 GetAttachmentsConfig(ctx context.Context, domainOrGroup string) ([]string, error)32 GetAttachmentsConfig(ctx context.Context, domainOrGroup string) ([]string, error)
33+ ListOrphanedAttachments(ctx context.Context) ([]domain.CleanupAttachment, error)
34+ CleanupOrphanedAttachments(ctx context.Context, owner string, stop bool) (*domain.CleanupReport, error)
33 FindAttachmentTargetsByImage(ctx context.Context, imageName string) ([]string, error)35 FindAttachmentTargetsByImage(ctx context.Context, imageName string) ([]string, error)
34 AddAttachment(ctx context.Context, domainOrGroup, image string) error36 AddAttachment(ctx context.Context, domainOrGroup, image string) error
35 RemoveAttachment(ctx context.Context, domainOrGroup, image string) error37 RemoveAttachment(ctx context.Context, domainOrGroup, image string) error
A internal/adapters/in/cli/mocks/mock_control_plane.go +2760 -0 large diff (2760 lines changed): collapsed
M internal/adapters/in/cli/push_test.go +8 -0
@@ -90,6 +90,14 @@ func (c *resolveFromImageTestControlPlane) GetAttachmentsConfig(context.Context,
9090 panic("unexpected call")
9191 }
9292
93+func (c *resolveFromImageTestControlPlane) ListOrphanedAttachments(context.Context) ([]domain.CleanupAttachment, error) {
94+ panic("unexpected call")
95+}
96+
97+func (c *resolveFromImageTestControlPlane) CleanupOrphanedAttachments(context.Context, string, bool) (*domain.CleanupReport, error) {
98+ panic("unexpected call")
99+}
100+
93101 func (c *resolveFromImageTestControlPlane) FindAttachmentTargetsByImage(context.Context, string) ([]string, error) {
94102 panic("unexpected call")
95103 }
@@ -90,6 +90,14 @@ func (c *resolveFromImageTestControlPlane) GetAttachmentsConfig(context.Context,
90 panic("unexpected call")90 panic("unexpected call")
91 }91 }
92 92
93+func (c *resolveFromImageTestControlPlane) ListOrphanedAttachments(context.Context) ([]domain.CleanupAttachment, error) {
94+ panic("unexpected call")
95+}
96+
97+func (c *resolveFromImageTestControlPlane) CleanupOrphanedAttachments(context.Context, string, bool) (*domain.CleanupReport, error) {
98+ panic("unexpected call")
99+}
100+
93 func (c *resolveFromImageTestControlPlane) FindAttachmentTargetsByImage(context.Context, string) ([]string, error) {101 func (c *resolveFromImageTestControlPlane) FindAttachmentTargetsByImage(context.Context, string) ([]string, error) {
94 panic("unexpected call")102 panic("unexpected call")
95 }103 }
M internal/adapters/in/cli/routes_test.go +21 -54
@@ -13,7 +13,7 @@ import (
1313 "sync/atomic"
1414 "testing"
1515
16- "github.com/bnema/gordon/internal/adapters/dto"
16+ climocks "github.com/bnema/gordon/internal/adapters/in/cli/mocks"
1717 "github.com/bnema/gordon/internal/adapters/in/cli/remote"
1818 "github.com/bnema/gordon/internal/adapters/in/cli/ui/components"
1919 "github.com/bnema/gordon/internal/adapters/in/cli/ui/styles"
@@ -40,6 +40,14 @@ func (c *routesShowTestControlPlane) GetHealth(ctx context.Context) (map[string]
4040 panic("unexpected call")
4141 }
4242
43+func (c *routesShowTestControlPlane) ListOrphanedAttachments(context.Context) ([]domain.CleanupAttachment, error) {
44+ panic("unexpected call")
45+}
46+
47+func (c *routesShowTestControlPlane) CleanupOrphanedAttachments(context.Context, string, bool) (*domain.CleanupReport, error) {
48+ panic("unexpected call")
49+}
50+
4351 func TestTruncateImage(t *testing.T) {
4452 tests := []struct {
4553 name string
@@ -945,65 +953,24 @@ func TestAttachmentsForRouteDiagnosisUsesOwner(t *testing.T) {
945953 }
946954
947955 func TestRunRoutePurge_AttachmentsForceIsScopedToRoute(t *testing.T) {
948- cp := &routePurgeTestControlPlane{
949- route: &domain.Route{Domain: "app.example.com", Image: "app:latest"},
950- orphanedAttachments: []domain.CleanupAttachment{
951- {ContainerID: "app-attachment", Owner: "app.example.com", Name: "postgres"},
952- {ContainerID: "other-attachment", Owner: "other.example.com", Name: "redis"},
953- },
956+ cp := climocks.NewMockControlPlane(t)
957+ orphanedAttachments := []domain.CleanupAttachment{
958+ {ContainerID: "app-attachment", Owner: "app.example.com", Name: "postgres"},
959+ {ContainerID: "other-attachment", Owner: "other.example.com", Name: "redis"},
954960 }
961+ cp.EXPECT().GetRoute(context.Background(), "app.example.com").Return(&domain.Route{Domain: "app.example.com", Image: "app:latest"}, nil).Once()
962+ cp.EXPECT().ListRoutesWithDetails(context.Background()).Return(nil, nil).Once()
963+ cp.EXPECT().GetHealth(context.Background()).Return(nil, nil).Once()
964+ cp.EXPECT().ListVolumes(context.Background()).Return(nil, nil).Once()
965+ cp.EXPECT().ListOrphanedAttachments(context.Background()).Return(orphanedAttachments, nil).Once()
966+ cp.EXPECT().CleanupOrphanedAttachments(context.Background(), "app.example.com", true).Return(&domain.CleanupReport{
967+ RemovedContainers: []domain.CleanupContainer{{ID: "app-attachment", Name: "postgres"}},
968+ }, nil).Once()
955969
956970 report, err := runRoutePurge(context.Background(), cp, "app.example.com", routePurgeOptions{Force: true, Attachments: true})
957971
958972 require.NoError(t, err)
959973 require.NotNil(t, report)
960- require.Len(t, cp.cleanedAttachments, 1)
961- assert.Equal(t, "app-attachment", cp.cleanedAttachments[0].ContainerID)
962974 require.Len(t, report.RemovedContainers, 1)
963975 assert.Equal(t, "app-attachment", report.RemovedContainers[0].ID)
964976 }
965-
966-type routePurgeTestControlPlane struct {
967- resolveFromImageTestControlPlane
968- route *domain.Route
969- orphanedAttachments []domain.CleanupAttachment
970- cleanedAttachments []domain.CleanupAttachment
971-}
972-
973-func (c *routePurgeTestControlPlane) GetRoute(context.Context, string) (*domain.Route, error) {
974- if c.route == nil {
975- return nil, domain.ErrRouteNotFound
976- }
977- return c.route, nil
978-}
979-
980-func (c *routePurgeTestControlPlane) ListRoutesWithDetails(context.Context) ([]remote.RouteInfo, error) {
981- return nil, nil
982-}
983-
984-func (c *routePurgeTestControlPlane) GetHealth(context.Context) (map[string]*remote.RouteHealth, error) {
985- return nil, nil
986-}
987-
988-func (c *routePurgeTestControlPlane) ListVolumes(context.Context) ([]dto.Volume, error) {
989- return nil, nil
990-}
991-
992-func (c *routePurgeTestControlPlane) ListOrphanedAttachments(context.Context) ([]domain.CleanupAttachment, error) {
993- return c.orphanedAttachments, nil
994-}
995-
996-func (c *routePurgeTestControlPlane) CleanupOrphanedAttachments(_ context.Context, owner string, stop bool) (*domain.CleanupReport, error) {
997- if !stop {
998- return &domain.CleanupReport{}, nil
999- }
1000- var report domain.CleanupReport
1001- for _, attachment := range c.orphanedAttachments {
1002- if attachment.Owner != owner {
1003- continue
1004- }
1005- c.cleanedAttachments = append(c.cleanedAttachments, attachment)
1006- report.RemovedContainers = append(report.RemovedContainers, domain.CleanupContainer{ID: attachment.ContainerID, Name: attachment.Name})
1007- }
1008- return &report, nil
1009-}
@@ -13,7 +13,7 @@ import (
13 "sync/atomic"13 "sync/atomic"
14 "testing"14 "testing"
15 15
16- "github.com/bnema/gordon/internal/adapters/dto"16+ climocks "github.com/bnema/gordon/internal/adapters/in/cli/mocks"
17 "github.com/bnema/gordon/internal/adapters/in/cli/remote"17 "github.com/bnema/gordon/internal/adapters/in/cli/remote"
18 "github.com/bnema/gordon/internal/adapters/in/cli/ui/components"18 "github.com/bnema/gordon/internal/adapters/in/cli/ui/components"
19 "github.com/bnema/gordon/internal/adapters/in/cli/ui/styles"19 "github.com/bnema/gordon/internal/adapters/in/cli/ui/styles"
@@ -40,6 +40,14 @@ func (c *routesShowTestControlPlane) GetHealth(ctx context.Context) (map[string]
40 panic("unexpected call")40 panic("unexpected call")
41 }41 }
42 42
43+func (c *routesShowTestControlPlane) ListOrphanedAttachments(context.Context) ([]domain.CleanupAttachment, error) {
44+ panic("unexpected call")
45+}
46+
47+func (c *routesShowTestControlPlane) CleanupOrphanedAttachments(context.Context, string, bool) (*domain.CleanupReport, error) {
48+ panic("unexpected call")
49+}
50+
43 func TestTruncateImage(t *testing.T) {51 func TestTruncateImage(t *testing.T) {
44 tests := []struct {52 tests := []struct {
45 name string53 name string
@@ -945,65 +953,24 @@ func TestAttachmentsForRouteDiagnosisUsesOwner(t *testing.T) {
945 }953 }
946 954
947 func TestRunRoutePurge_AttachmentsForceIsScopedToRoute(t *testing.T) {955 func TestRunRoutePurge_AttachmentsForceIsScopedToRoute(t *testing.T) {
948- cp := &routePurgeTestControlPlane{956+ cp := climocks.NewMockControlPlane(t)
949- route: &domain.Route{Domain: "app.example.com", Image: "app:latest"},957+ orphanedAttachments := []domain.CleanupAttachment{
950- orphanedAttachments: []domain.CleanupAttachment{958+ {ContainerID: "app-attachment", Owner: "app.example.com", Name: "postgres"},
951- {ContainerID: "app-attachment", Owner: "app.example.com", Name: "postgres"},959+ {ContainerID: "other-attachment", Owner: "other.example.com", Name: "redis"},
952- {ContainerID: "other-attachment", Owner: "other.example.com", Name: "redis"},
953- },
954 }960 }
961+ cp.EXPECT().GetRoute(context.Background(), "app.example.com").Return(&domain.Route{Domain: "app.example.com", Image: "app:latest"}, nil).Once()
962+ cp.EXPECT().ListRoutesWithDetails(context.Background()).Return(nil, nil).Once()
963+ cp.EXPECT().GetHealth(context.Background()).Return(nil, nil).Once()
964+ cp.EXPECT().ListVolumes(context.Background()).Return(nil, nil).Once()
965+ cp.EXPECT().ListOrphanedAttachments(context.Background()).Return(orphanedAttachments, nil).Once()
966+ cp.EXPECT().CleanupOrphanedAttachments(context.Background(), "app.example.com", true).Return(&domain.CleanupReport{
967+ RemovedContainers: []domain.CleanupContainer{{ID: "app-attachment", Name: "postgres"}},
968+ }, nil).Once()
955 969
956 report, err := runRoutePurge(context.Background(), cp, "app.example.com", routePurgeOptions{Force: true, Attachments: true})970 report, err := runRoutePurge(context.Background(), cp, "app.example.com", routePurgeOptions{Force: true, Attachments: true})
957 971
958 require.NoError(t, err)972 require.NoError(t, err)
959 require.NotNil(t, report)973 require.NotNil(t, report)
960- require.Len(t, cp.cleanedAttachments, 1)
961- assert.Equal(t, "app-attachment", cp.cleanedAttachments[0].ContainerID)
962 require.Len(t, report.RemovedContainers, 1)974 require.Len(t, report.RemovedContainers, 1)
963 assert.Equal(t, "app-attachment", report.RemovedContainers[0].ID)975 assert.Equal(t, "app-attachment", report.RemovedContainers[0].ID)
964 }976 }
965-
966-type routePurgeTestControlPlane struct {
967- resolveFromImageTestControlPlane
968- route *domain.Route
969- orphanedAttachments []domain.CleanupAttachment
970- cleanedAttachments []domain.CleanupAttachment
971-}
972-
973-func (c *routePurgeTestControlPlane) GetRoute(context.Context, string) (*domain.Route, error) {
974- if c.route == nil {
975- return nil, domain.ErrRouteNotFound
976- }
977- return c.route, nil
978-}
979-
980-func (c *routePurgeTestControlPlane) ListRoutesWithDetails(context.Context) ([]remote.RouteInfo, error) {
981- return nil, nil
982-}
983-
984-func (c *routePurgeTestControlPlane) GetHealth(context.Context) (map[string]*remote.RouteHealth, error) {
985- return nil, nil
986-}
987-
988-func (c *routePurgeTestControlPlane) ListVolumes(context.Context) ([]dto.Volume, error) {
989- return nil, nil
990-}
991-
992-func (c *routePurgeTestControlPlane) ListOrphanedAttachments(context.Context) ([]domain.CleanupAttachment, error) {
993- return c.orphanedAttachments, nil
994-}
995-
996-func (c *routePurgeTestControlPlane) CleanupOrphanedAttachments(_ context.Context, owner string, stop bool) (*domain.CleanupReport, error) {
997- if !stop {
998- return &domain.CleanupReport{}, nil
999- }
1000- var report domain.CleanupReport
1001- for _, attachment := range c.orphanedAttachments {
1002- if attachment.Owner != owner {
1003- continue
1004- }
1005- c.cleanedAttachments = append(c.cleanedAttachments, attachment)
1006- report.RemovedContainers = append(report.RemovedContainers, domain.CleanupContainer{ID: attachment.ContainerID, Name: attachment.Name})
1007- }
1008- return &report, nil
1009-}
M internal/adapters/in/cli/tls_test.go +8 -0
@@ -82,6 +82,14 @@ func (c *tlsTestControlPlane) GetAttachmentsConfig(context.Context, string) ([]s
8282 panic("unexpected call")
8383 }
8484
85+func (c *tlsTestControlPlane) ListOrphanedAttachments(context.Context) ([]domain.CleanupAttachment, error) {
86+ panic("unexpected call")
87+}
88+
89+func (c *tlsTestControlPlane) CleanupOrphanedAttachments(context.Context, string, bool) (*domain.CleanupReport, error) {
90+ panic("unexpected call")
91+}
92+
8593 func (c *tlsTestControlPlane) FindAttachmentTargetsByImage(context.Context, string) ([]string, error) {
8694 panic("unexpected call")
8795 }
@@ -82,6 +82,14 @@ func (c *tlsTestControlPlane) GetAttachmentsConfig(context.Context, string) ([]s
82 panic("unexpected call")82 panic("unexpected call")
83 }83 }
84 84
85+func (c *tlsTestControlPlane) ListOrphanedAttachments(context.Context) ([]domain.CleanupAttachment, error) {
86+ panic("unexpected call")
87+}
88+
89+func (c *tlsTestControlPlane) CleanupOrphanedAttachments(context.Context, string, bool) (*domain.CleanupReport, error) {
90+ panic("unexpected call")
91+}
92+
85 func (c *tlsTestControlPlane) FindAttachmentTargetsByImage(context.Context, string) ([]string, error) {93 func (c *tlsTestControlPlane) FindAttachmentTargetsByImage(context.Context, string) ([]string, error) {
86 panic("unexpected call")94 panic("unexpected call")
87 }95 }

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close