test(cli): preserve mock call ordering
- commit
- b9cf20dd996ff11475aa30ef8f0b6b0874be6cfa
- author
- brice · · 2026-05-22 04:25 UTC
- parent
- 899a76d
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· 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 ( | |||
| 15 | 15 | "github.com/bnema/gordon/internal/adapters/in/cli/remote" | |
| 16 | 16 | "github.com/bnema/gordon/internal/domain" | |
| 17 | 17 | "github.com/stretchr/testify/assert" | |
| 18 | + | "github.com/stretchr/testify/mock" | |
| 18 | 19 | ) | |
| 19 | 20 | ||
| 20 | 21 | func TestValidateBuildArg(t *testing.T) { | |
| @@ -474,8 +475,9 @@ func TestResolveRoute_DottedBareImageUsesImageLookup(t *testing.T) { | |||
| 474 | 475 | ||
| 475 | 476 | func TestResolveRoute_DottedBareImageNoRoutesKeepsBootstrapError(t *testing.T) { | |
| 476 | 477 | 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) | |
| 479 | 481 | ||
| 480 | 482 | _, _, _, err := resolveRoute(context.Background(), cpMock, "my.app", "", "Dockerfile") | |
| 481 | 483 | ||
| @@ -495,8 +497,9 @@ func TestNoRouteForImageErrorWrapsSentinel(t *testing.T) { | |||
| 495 | 497 | ||
| 496 | 498 | func TestResolveRoute_DottedBareDomainFallsBackToLegacyLookup(t *testing.T) { | |
| 497 | 499 | 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) | |
| 500 | 503 | ||
| 501 | 504 | registry, imageName, pushDomain, err := resolveRoute(context.Background(), cpMock, "app.example.com", "", "Dockerfile") | |
| 502 | 505 | ||
| @@ -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 ( | |||
| 6 | 6 | "testing" | |
| 7 | 7 | ||
| 8 | 8 | "github.com/stretchr/testify/assert" | |
| 9 | + | "github.com/stretchr/testify/mock" | |
| 9 | 10 | "github.com/stretchr/testify/require" | |
| 10 | 11 | ||
| 11 | 12 | "github.com/bnema/gordon/internal/adapters/dto" | |
| @@ -45,8 +46,9 @@ func TestRunVolumesPrune_JSONExecutesActualPrune(t *testing.T) { | |||
| 45 | 46 | SpaceReclaimed: 1024, | |
| 46 | 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 | - | 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) | |
| 50 | 52 | ||
| 51 | 53 | var out bytes.Buffer | |
| 52 | 54 | 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.Buffer | 53 | var out bytes.Buffer | ||
| 52 | err := runVolumesPrune(context.Background(), clientMock, volumesPruneOptions{Json: true}, &out) | 54 | err := runVolumesPrune(context.Background(), clientMock, volumesPruneOptions{Json: true}, &out) | ||