test(app): use generated broker connector mock
- commit
- d60044dfbc16e8705e823f167a8e04ed85e65f8d
- author
- brice · · 2026-09-22 21:22 UTC
- parent
- 644a9a8
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
1 file · +5 -12
M internal/app/attach_missing_prompt_test.go +5 -12
| @@ -21,6 +21,7 @@ import ( | |||
| 21 | 21 | "testing" | |
| 22 | 22 | "time" | |
| 23 | 23 | ||
| 24 | + | "github.com/stretchr/testify/mock" | |
| 24 | 25 | "github.com/stretchr/testify/require" | |
| 25 | 26 | ||
| 26 | 27 | "github.com/bnema/vev/internal/adapters/term" | |
| @@ -449,32 +450,24 @@ func openAttachPtySlave(t *testing.T) *os.File { | |||
| 449 | 450 | func TestPreconnectedBrokerConnectorReusesThenFallsBack(t *testing.T) { | |
| 450 | 451 | first := portsmocks.NewMockBrokerService(t) | |
| 451 | 452 | second := portsmocks.NewMockBrokerService(t) | |
| 452 | - | fallbackCalls := 0 | |
| 453 | - | fallback := brokerConnectorFunc(func(context.Context) (ports.BrokerService, error) { | |
| 454 | - | fallbackCalls++ | |
| 455 | - | return second, nil | |
| 456 | - | }) | |
| 453 | + | fallback := portsmocks.NewMockBrokerConnector(t) | |
| 454 | + | fallback.EXPECT().Connect(mock.Anything).Return(second, nil).Once() | |
| 457 | 455 | connector := withPreconnected(fallback, first) | |
| 458 | 456 | ||
| 459 | 457 | got, err := connector.Connect(context.Background()) | |
| 460 | 458 | require.NoError(t, err) | |
| 461 | 459 | require.Same(t, first, got, "the first Connect reuses the preflight's own connection") | |
| 462 | - | require.Zero(t, fallbackCalls) | |
| 463 | 460 | ||
| 464 | 461 | got, err = connector.Connect(context.Background()) | |
| 465 | 462 | require.NoError(t, err) | |
| 466 | 463 | require.Same(t, second, got, "a later Connect reconnects through the fallback") | |
| 467 | - | require.Equal(t, 1, fallbackCalls) | |
| 468 | 464 | } | |
| 469 | 465 | ||
| 470 | 466 | func TestWithPreconnectedNilPassesThroughUnchanged(t *testing.T) { | |
| 471 | - | fallback := brokerConnectorFunc(func(context.Context) (ports.BrokerService, error) { return nil, nil }) | |
| 467 | + | fallback := portsmocks.NewMockBrokerConnector(t) | |
| 468 | + | fallback.EXPECT().Connect(mock.Anything).Return(nil, nil).Once() | |
| 472 | 469 | got := withPreconnected(fallback, nil) | |
| 473 | 470 | service, err := got.Connect(context.Background()) | |
| 474 | 471 | require.NoError(t, err) | |
| 475 | 472 | require.Nil(t, service) | |
| 476 | 473 | } | |
| 477 | - | ||
| 478 | - | type brokerConnectorFunc func(context.Context) (ports.BrokerService, error) | |
| 479 | - | ||
| 480 | - | func (f brokerConnectorFunc) Connect(ctx context.Context) (ports.BrokerService, error) { return f(ctx) } | |
| @@ -21,6 +21,7 @@ import ( | |||||
| 21 | "testing" | 21 | "testing" | ||
| 22 | "time" | 22 | "time" | ||
| 23 | 23 | ||||
| 24 | + | "github.com/stretchr/testify/mock" | |||
| 24 | "github.com/stretchr/testify/require" | 25 | "github.com/stretchr/testify/require" | ||
| 25 | 26 | ||||
| 26 | "github.com/bnema/vev/internal/adapters/term" | 27 | "github.com/bnema/vev/internal/adapters/term" | ||
| @@ -449,32 +450,24 @@ func openAttachPtySlave(t *testing.T) *os.File { | |||||
| 449 | func TestPreconnectedBrokerConnectorReusesThenFallsBack(t *testing.T) { | 450 | func TestPreconnectedBrokerConnectorReusesThenFallsBack(t *testing.T) { | ||
| 450 | first := portsmocks.NewMockBrokerService(t) | 451 | first := portsmocks.NewMockBrokerService(t) | ||
| 451 | second := portsmocks.NewMockBrokerService(t) | 452 | second := portsmocks.NewMockBrokerService(t) | ||
| 452 | - | fallbackCalls := 0 | 453 | + | fallback := portsmocks.NewMockBrokerConnector(t) |
| 453 | - | fallback := brokerConnectorFunc(func(context.Context) (ports.BrokerService, error) { | 454 | + | fallback.EXPECT().Connect(mock.Anything).Return(second, nil).Once() |
| 454 | - | fallbackCalls++ | |||
| 455 | - | return second, nil | |||
| 456 | - | }) | |||
| 457 | connector := withPreconnected(fallback, first) | 455 | connector := withPreconnected(fallback, first) | ||
| 458 | 456 | ||||
| 459 | got, err := connector.Connect(context.Background()) | 457 | got, err := connector.Connect(context.Background()) | ||
| 460 | require.NoError(t, err) | 458 | require.NoError(t, err) | ||
| 461 | require.Same(t, first, got, "the first Connect reuses the preflight's own connection") | 459 | require.Same(t, first, got, "the first Connect reuses the preflight's own connection") | ||
| 462 | - | require.Zero(t, fallbackCalls) | |||
| 463 | 460 | ||||
| 464 | got, err = connector.Connect(context.Background()) | 461 | got, err = connector.Connect(context.Background()) | ||
| 465 | require.NoError(t, err) | 462 | require.NoError(t, err) | ||
| 466 | require.Same(t, second, got, "a later Connect reconnects through the fallback") | 463 | require.Same(t, second, got, "a later Connect reconnects through the fallback") | ||
| 467 | - | require.Equal(t, 1, fallbackCalls) | |||
| 468 | } | 464 | } | ||
| 469 | 465 | ||||
| 470 | func TestWithPreconnectedNilPassesThroughUnchanged(t *testing.T) { | 466 | func TestWithPreconnectedNilPassesThroughUnchanged(t *testing.T) { | ||
| 471 | - | fallback := brokerConnectorFunc(func(context.Context) (ports.BrokerService, error) { return nil, nil }) | 467 | + | fallback := portsmocks.NewMockBrokerConnector(t) |
| 468 | + | fallback.EXPECT().Connect(mock.Anything).Return(nil, nil).Once() | |||
| 472 | got := withPreconnected(fallback, nil) | 469 | got := withPreconnected(fallback, nil) | ||
| 473 | service, err := got.Connect(context.Background()) | 470 | service, err := got.Connect(context.Background()) | ||
| 474 | require.NoError(t, err) | 471 | require.NoError(t, err) | ||
| 475 | require.Nil(t, service) | 472 | require.Nil(t, service) | ||
| 476 | } | 473 | } | ||
| 477 | - | ||||
| 478 | - | type brokerConnectorFunc func(context.Context) (ports.BrokerService, error) | |||
| 479 | - | ||||
| 480 | - | func (f brokerConnectorFunc) Connect(ctx context.Context) (ports.BrokerService, error) { return f(ctx) } | |||