detached b9cf20d

test(cli): preserve mock call ordering

commit
b9cf20dd996ff11475aa30ef8f0b6b0874be6cfa
author
brice · · 2026-05-22 04:25 UTC
parent
899a76d
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
2 files · +11 -6
M internal/adapters/in/cli/push_test.go +7 -4
@@ -15,6 +15,7 @@ import (
1515 "github.com/bnema/gordon/internal/adapters/in/cli/remote"
1616 "github.com/bnema/gordon/internal/domain"
1717 "github.com/stretchr/testify/assert"
18+ "github.com/stretchr/testify/mock"
1819 )
1920
2021 func TestValidateBuildArg(t *testing.T) {
@@ -474,8 +475,9 @@ func TestResolveRoute_DottedBareImageUsesImageLookup(t *testing.T) {
474475
475476 func TestResolveRoute_DottedBareImageNoRoutesKeepsBootstrapError(t *testing.T) {
476477 cpMock := climocks.NewMockControlPlane(t)
477- cpMock.EXPECT().FindRoutesByImage(context.Background(), "my.app").Return(nil, nil).Once()
478- cpMock.EXPECT().GetRoute(context.Background(), "my.app").Return(nil, domain.ErrRouteNotFound).Once()
478+ imageLookup := cpMock.EXPECT().FindRoutesByImage(context.Background(), "my.app").Return(nil, nil).Once()
479+ routeLookup := cpMock.EXPECT().GetRoute(context.Background(), "my.app").Return(nil, domain.ErrRouteNotFound).Once()
480+ mock.InOrder(imageLookup, routeLookup)
479481
480482 _, _, _, err := resolveRoute(context.Background(), cpMock, "my.app", "", "Dockerfile")
481483
@@ -495,8 +497,9 @@ func TestNoRouteForImageErrorWrapsSentinel(t *testing.T) {
495497
496498 func TestResolveRoute_DottedBareDomainFallsBackToLegacyLookup(t *testing.T) {
497499 cpMock := climocks.NewMockControlPlane(t)
498- cpMock.EXPECT().FindRoutesByImage(context.Background(), "app.example.com").Return(nil, nil).Once()
499- cpMock.EXPECT().GetRoute(context.Background(), "app.example.com").Return(&domain.Route{Domain: "app.example.com", Image: "registry.example.com/myapp:latest"}, nil).Once()
500+ imageLookup := cpMock.EXPECT().FindRoutesByImage(context.Background(), "app.example.com").Return(nil, nil).Once()
501+ routeLookup := cpMock.EXPECT().GetRoute(context.Background(), "app.example.com").Return(&domain.Route{Domain: "app.example.com", Image: "registry.example.com/myapp:latest"}, nil).Once()
502+ mock.InOrder(imageLookup, routeLookup)
500503
501504 registry, imageName, pushDomain, err := resolveRoute(context.Background(), cpMock, "app.example.com", "", "Dockerfile")
502505
@@ -15,6 +15,7 @@ import (
15 "github.com/bnema/gordon/internal/adapters/in/cli/remote"15 "github.com/bnema/gordon/internal/adapters/in/cli/remote"
16 "github.com/bnema/gordon/internal/domain"16 "github.com/bnema/gordon/internal/domain"
17 "github.com/stretchr/testify/assert"17 "github.com/stretchr/testify/assert"
18+ "github.com/stretchr/testify/mock"
18 )19 )
19 20
20 func TestValidateBuildArg(t *testing.T) {21 func TestValidateBuildArg(t *testing.T) {
@@ -474,8 +475,9 @@ func TestResolveRoute_DottedBareImageUsesImageLookup(t *testing.T) {
474 475
475 func TestResolveRoute_DottedBareImageNoRoutesKeepsBootstrapError(t *testing.T) {476 func TestResolveRoute_DottedBareImageNoRoutesKeepsBootstrapError(t *testing.T) {
476 cpMock := climocks.NewMockControlPlane(t)477 cpMock := climocks.NewMockControlPlane(t)
477- cpMock.EXPECT().FindRoutesByImage(context.Background(), "my.app").Return(nil, nil).Once()478+ imageLookup := cpMock.EXPECT().FindRoutesByImage(context.Background(), "my.app").Return(nil, nil).Once()
478- cpMock.EXPECT().GetRoute(context.Background(), "my.app").Return(nil, domain.ErrRouteNotFound).Once()479+ routeLookup := cpMock.EXPECT().GetRoute(context.Background(), "my.app").Return(nil, domain.ErrRouteNotFound).Once()
480+ mock.InOrder(imageLookup, routeLookup)
479 481
480 _, _, _, err := resolveRoute(context.Background(), cpMock, "my.app", "", "Dockerfile")482 _, _, _, err := resolveRoute(context.Background(), cpMock, "my.app", "", "Dockerfile")
481 483
@@ -495,8 +497,9 @@ func TestNoRouteForImageErrorWrapsSentinel(t *testing.T) {
495 497
496 func TestResolveRoute_DottedBareDomainFallsBackToLegacyLookup(t *testing.T) {498 func TestResolveRoute_DottedBareDomainFallsBackToLegacyLookup(t *testing.T) {
497 cpMock := climocks.NewMockControlPlane(t)499 cpMock := climocks.NewMockControlPlane(t)
498- cpMock.EXPECT().FindRoutesByImage(context.Background(), "app.example.com").Return(nil, nil).Once()500+ imageLookup := cpMock.EXPECT().FindRoutesByImage(context.Background(), "app.example.com").Return(nil, nil).Once()
499- cpMock.EXPECT().GetRoute(context.Background(), "app.example.com").Return(&domain.Route{Domain: "app.example.com", Image: "registry.example.com/myapp:latest"}, nil).Once()501+ routeLookup := cpMock.EXPECT().GetRoute(context.Background(), "app.example.com").Return(&domain.Route{Domain: "app.example.com", Image: "registry.example.com/myapp:latest"}, nil).Once()
502+ mock.InOrder(imageLookup, routeLookup)
500 503
501 registry, imageName, pushDomain, err := resolveRoute(context.Background(), cpMock, "app.example.com", "", "Dockerfile")504 registry, imageName, pushDomain, err := resolveRoute(context.Background(), cpMock, "app.example.com", "", "Dockerfile")
502 505
M internal/adapters/in/cli/volumes_test.go +4 -2
@@ -6,6 +6,7 @@ import (
66 "testing"
77
88 "github.com/stretchr/testify/assert"
9+ "github.com/stretchr/testify/mock"
910 "github.com/stretchr/testify/require"
1011
1112 "github.com/bnema/gordon/internal/adapters/dto"
@@ -45,8 +46,9 @@ func TestRunVolumesPrune_JSONExecutesActualPrune(t *testing.T) {
4546 SpaceReclaimed: 1024,
4647 Volumes: []dto.Volume{{Name: "orphan1", Size: 1024}},
4748 }
48- clientMock.EXPECT().PruneVolumes(context.Background(), dto.VolumePruneRequest{DryRun: true}).Return(resp, nil).Once()
49- clientMock.EXPECT().PruneVolumes(context.Background(), dto.VolumePruneRequest{DryRun: false}).Return(resp, nil).Once()
49+ previewCall := clientMock.EXPECT().PruneVolumes(context.Background(), dto.VolumePruneRequest{DryRun: true}).Return(resp, nil).Once()
50+ pruneCall := clientMock.EXPECT().PruneVolumes(context.Background(), dto.VolumePruneRequest{DryRun: false}).Return(resp, nil).Once()
51+ mock.InOrder(previewCall, pruneCall)
5052
5153 var out bytes.Buffer
5254 err := runVolumesPrune(context.Background(), clientMock, volumesPruneOptions{Json: true}, &out)
@@ -6,6 +6,7 @@ import (
6 "testing"6 "testing"
7 7
8 "github.com/stretchr/testify/assert"8 "github.com/stretchr/testify/assert"
9+ "github.com/stretchr/testify/mock"
9 "github.com/stretchr/testify/require"10 "github.com/stretchr/testify/require"
10 11
11 "github.com/bnema/gordon/internal/adapters/dto"12 "github.com/bnema/gordon/internal/adapters/dto"
@@ -45,8 +46,9 @@ func TestRunVolumesPrune_JSONExecutesActualPrune(t *testing.T) {
45 SpaceReclaimed: 1024,46 SpaceReclaimed: 1024,
46 Volumes: []dto.Volume{{Name: "orphan1", Size: 1024}},47 Volumes: []dto.Volume{{Name: "orphan1", Size: 1024}},
47 }48 }
48- clientMock.EXPECT().PruneVolumes(context.Background(), dto.VolumePruneRequest{DryRun: true}).Return(resp, nil).Once()49+ previewCall := clientMock.EXPECT().PruneVolumes(context.Background(), dto.VolumePruneRequest{DryRun: true}).Return(resp, nil).Once()
49- clientMock.EXPECT().PruneVolumes(context.Background(), dto.VolumePruneRequest{DryRun: false}).Return(resp, nil).Once()50+ pruneCall := clientMock.EXPECT().PruneVolumes(context.Background(), dto.VolumePruneRequest{DryRun: false}).Return(resp, nil).Once()
51+ mock.InOrder(previewCall, pruneCall)
50 52
51 var out bytes.Buffer53 var out bytes.Buffer
52 err := runVolumesPrune(context.Background(), clientMock, volumesPruneOptions{Json: true}, &out)54 err := runVolumesPrune(context.Background(), clientMock, volumesPruneOptions{Json: true}, &out)

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