v2.31.0-dev23 58a92f3

volume_targets_test.go RawHistoryFolder

1package backup
2
3import (
4	"testing"
5
6	"github.com/stretchr/testify/assert"
7	"github.com/stretchr/testify/require"
8
9	"github.com/bnema/gordon/internal/domain"
10)
11
12func TestSelectVolumeBackupTargets(t *testing.T) {
13	containers := []*domain.Container{
14		{
15			ID:   "unmanaged",
16			Name: "unmanaged",
17			Labels: map[string]string{
18				domain.LabelDomain: "app.example.com",
19			},
20			VolumeMounts: []domain.ContainerVolumeMount{{Name: "gordon-app-data", Type: "volume", Destination: "/data"}},
21		},
22		{
23			ID:   "app",
24			Name: "app",
25			Labels: map[string]string{
26				domain.LabelManaged: "true",
27				domain.LabelDomain:  "app.example.com",
28			},
29			VolumeMounts: []domain.ContainerVolumeMount{
30				{Name: "gordon-app-example-com-data", Type: "volume", Destination: "/data"},
31				{Name: "gordon-app-example-com-cache", Type: "bind", Destination: "/cache"},
32				{Name: "random-anonymous", Type: "volume", Destination: "/anon"},
33				{Name: "", Type: "volume", Destination: "/empty"},
34			},
35		},
36		{
37			ID:   "postgres",
38			Name: "postgres",
39			Labels: map[string]string{
40				domain.LabelManaged:    "true",
41				domain.LabelAttachment: "true",
42				domain.LabelAttachedTo: "app.example.com",
43			},
44			VolumeMounts: []domain.ContainerVolumeMount{
45				{Name: "gordon-postgres-data", Type: "volume", Destination: "/var/lib/postgresql/data"},
46				{Name: "gordon-app-example-com-data", Type: "volume", Destination: "/shared"},
47			},
48		},
49	}
50
51	targets := SelectVolumeBackupTargets(containers, "gordon")
52
53	assert.Equal(t, []domain.VolumeBackupTarget{
54		{
55			Domain:        "app.example.com",
56			ContainerName: "app",
57			ContainerID:   "app",
58			VolumeName:    "gordon-app-example-com-data",
59			MountPath:     "/data",
60		},
61		{
62			Domain:        "app.example.com",
63			ContainerName: "postgres",
64			ContainerID:   "postgres",
65			VolumeName:    "gordon-postgres-data",
66			MountPath:     "/var/lib/postgresql/data",
67		},
68	}, targets)
69}
70
71func TestSelectVolumeBackupTargetsForScopeDedupesAfterFiltering(t *testing.T) {
72	containers := []*domain.Container{
73		{
74			ID:   "alpha",
75			Name: "alpha",
76			Labels: map[string]string{
77				domain.LabelManaged: "true",
78				domain.LabelDomain:  "alpha.example.com",
79			},
80			VolumeMounts: []domain.ContainerVolumeMount{{Name: "gordon-shared", Type: "volume", Destination: "/data"}},
81		},
82		{
83			ID:   "beta",
84			Name: "beta",
85			Labels: map[string]string{
86				domain.LabelManaged: "true",
87				domain.LabelDomain:  "beta.example.com",
88			},
89			VolumeMounts: []domain.ContainerVolumeMount{{Name: "gordon-shared", Type: "volume", Destination: "/data"}},
90		},
91	}
92
93	targets := SelectVolumeBackupTargetsForScope(containers, "gordon", "beta.example.com", "")
94
95	require.Len(t, targets, 1)
96	assert.Equal(t, "beta.example.com", targets[0].Domain)
97	assert.Equal(t, "gordon-shared", targets[0].VolumeName)
98}
99
100func TestSelectVolumeBackupTargetsRequiresDomain(t *testing.T) {
101	containers := []*domain.Container{
102		{
103			ID:   "missing-domain",
104			Name: "missing-domain",
105			Labels: map[string]string{
106				domain.LabelManaged: "true",
107			},
108			VolumeMounts: []domain.ContainerVolumeMount{{Name: "gordon-data", Type: "volume", Destination: "/data"}},
109		},
110	}
111
112	targets := SelectVolumeBackupTargets(containers, "gordon")
113
114	assert.Empty(t, targets)
115}

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