broker_host_upgrade_test.go RawHistoryFolder

1package app
2
3import (
4	"path/filepath"
5	"testing"
6
7	"github.com/stretchr/testify/require"
8
9	"github.com/bnema/vev/internal/adapters/brokerstore"
10	"github.com/bnema/vev/internal/domain"
11	"github.com/bnema/vev/internal/ports"
12	"github.com/bnema/vev/internal/protocol"
13	"github.com/bnema/vev/internal/protocol/catalogue"
14)
15
16func TestUpgradeBrokerHostVersions(t *testing.T) {
17	tests := []struct {
18		name         string
19		policy       func() ports.BrokerPolicy
20		wantRevision uint64 // also the expected generation advance
21	}{
22		{
23			name: "older build policy is upgraded and identity kept",
24			policy: func() ports.BrokerPolicy {
25				p := remoteBrokerPolicy(hostTransportQUIC)
26				p.ProtocolVersion--
27				return p
28			},
29			wantRevision: 1,
30		},
31		{
32			name:         "current policy is left untouched",
33			policy:       func() ports.BrokerPolicy { return remoteBrokerPolicy(hostTransportQUIC) },
34			wantRevision: 0,
35		},
36	}
37	for _, tt := range tests {
38		t.Run(tt.name, func(t *testing.T) {
39			registration, err := domain.NewRemoteRegistration("user@host", [16]byte{1})
40			require.NoError(t, err)
41			policy := tt.policy()
42			route, err := ports.BrokerRouteForTransport(policy.Transport, registration.Endpoint)
43			require.NoError(t, err)
44			record := ports.BrokerHostRecord{Registration: registration, Pinned: true, Policy: policy, Route: route, Identity: "daemon-identity"}
45
46			store, err := brokerstore.Open(brokerstore.Options{Dir: filepath.Join(shortTempDir(t, "vevu"), "state"), InitialHosts: []ports.BrokerHostRecord{record}, InitialImportProvided: true})
47			require.NoError(t, err)
48			t.Cleanup(func() { require.NoError(t, store.Close()) })
49			before, err := store.LoadHosts()
50			require.NoError(t, err)
51
52			require.NoError(t, upgradeBrokerHostVersions(store))
53
54			after, err := store.LoadHosts()
55			require.NoError(t, err)
56			require.Equal(t, before.Revision+tt.wantRevision, after.Revision)
57			require.Len(t, after.Hosts, 1)
58			got := after.Hosts[0]
59			require.Equal(t, protocol.Version, got.Policy.ProtocolVersion)
60			require.Equal(t, catalogue.RemoteCatalogSchemaVersion, got.Policy.CatalogSchemaVersion)
61			require.Equal(t, ports.BrokerDaemonIdentity("daemon-identity"), got.Identity)
62			require.Equal(t, registration.Endpoint, got.Registration.Endpoint)
63			require.Equal(t, registration.Incarnation, got.Registration.Incarnation)
64			require.Equal(t, registration.Generation+domain.RemoteGeneration(tt.wantRevision), got.Registration.Generation)
65		})
66	}
67}

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