detached d60044d

test(app): use generated broker connector mock

commit
d60044dfbc16e8705e823f167a8e04ed85e65f8d
author
brice · · 2026-09-22 21:22 UTC
parent
644a9a8
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · 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 (
2121 "testing"
2222 "time"
2323
24+ "github.com/stretchr/testify/mock"
2425 "github.com/stretchr/testify/require"
2526
2627 "github.com/bnema/vev/internal/adapters/term"
@@ -449,32 +450,24 @@ func openAttachPtySlave(t *testing.T) *os.File {
449450 func TestPreconnectedBrokerConnectorReusesThenFallsBack(t *testing.T) {
450451 first := portsmocks.NewMockBrokerService(t)
451452 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()
457455 connector := withPreconnected(fallback, first)
458456
459457 got, err := connector.Connect(context.Background())
460458 require.NoError(t, err)
461459 require.Same(t, first, got, "the first Connect reuses the preflight's own connection")
462- require.Zero(t, fallbackCalls)
463460
464461 got, err = connector.Connect(context.Background())
465462 require.NoError(t, err)
466463 require.Same(t, second, got, "a later Connect reconnects through the fallback")
467- require.Equal(t, 1, fallbackCalls)
468464 }
469465
470466 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()
472469 got := withPreconnected(fallback, nil)
473470 service, err := got.Connect(context.Background())
474471 require.NoError(t, err)
475472 require.Nil(t, service)
476473 }
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 := 0453+ 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) }

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 12

Tags 11

↑↓ moveenter openesc close