app_network_test.go RawHistoryFolder

1package domain_test
2
3import (
4	"testing"
5
6	"github.com/stretchr/testify/assert"
7
8	"github.com/bnema/gordon/internal/domain"
9)
10
11func TestAppPrivateNetworkName_DerivesFromUUIDNotName(t *testing.T) {
12	first := domain.AppPrivateNetworkName("gordon", "app-1")
13	second := domain.AppPrivateNetworkName("gordon", "app-2")
14	assert.NotEqual(t, first, second, "distinct incarnations must not share a network")
15	assert.Equal(t, first, domain.AppPrivateNetworkName("gordon", "app-1"), "derivation is deterministic for recovery")
16	assert.NotEqual(t, "default", first)
17	assert.NotEqual(t, "bridge", first)
18
19	// Same public name, new incarnation UUID: a different network.
20	reused := domain.AppPrivateNetworkName("gordon", "app-9")
21	assert.NotEqual(t, first, reused, "name reuse must not reattach the old network")
22}
23
24func TestAppPrivateNetworkName_AppliesDefaultPrefix(t *testing.T) {
25	assert.Equal(t,
26		domain.AppPrivateNetworkName("gordon", "app-1"),
27		domain.AppPrivateNetworkName("", "app-1"),
28	)
29}
30
31func TestAppSharedNetworkName_StablePerDeclaration(t *testing.T) {
32	assert.Equal(t, domain.AppSharedNetworkName("gordon", "db"), domain.AppSharedNetworkName("gordon", "db"))
33	assert.NotEqual(t, domain.AppSharedNetworkName("gordon", "db"), domain.AppSharedNetworkName("gordon", "cache"))
34}
35
36func TestNetworkOwnedBy_RequiresEveryExpectedLabel(t *testing.T) {
37	expected := domain.AppPrivateNetworkLabels("blog", "app-1")
38	assert.True(t, domain.NetworkOwnedBy(expected, expected))
39	assert.True(t, domain.NetworkOwnedBy(map[string]string{
40		domain.LabelManaged:        "true",
41		domain.LabelApp:            "blog",
42		domain.LabelAppNetworkRole: domain.AppNetworkRolePrivate,
43		domain.LabelAppID:          "app-1",
44		"extra":                    "tolerated",
45	}, expected))
46	assert.False(t, domain.NetworkOwnedBy(map[string]string{domain.LabelManaged: "true"}, expected))
47	assert.False(t, domain.NetworkOwnedBy(nil, expected))
48	assert.False(t, domain.NetworkOwnedBy(expected, nil), "empty expectation is never proof of ownership")
49	assert.False(t, domain.NetworkOwnedBy(map[string]string{
50		domain.LabelManaged:        "true",
51		domain.LabelApp:            "blog",
52		domain.LabelAppNetworkRole: domain.AppNetworkRolePrivate,
53		domain.LabelAppID:          "app-2",
54	}, expected), "a different incarnation is foreign")
55}
56
57func TestAppServiceSharedNetworks_FiltersAndDeduplicates(t *testing.T) {
58	spec := domain.AppSpec{
59		Name: "blog",
60		Networks: []domain.AppSharedNetwork{
61			{Network: "db", Services: []string{"web", "worker"}},
62			{Network: "cache", Services: []string{"worker"}},
63			{Network: "db", Services: []string{"web"}},
64		},
65	}
66	web := domain.AppServiceSharedNetworks(spec, "web")
67	assert.Equal(t, []domain.AppSharedNetwork{{Network: "db", Services: []string{"web", "worker"}}}, web)
68
69	worker := domain.AppServiceSharedNetworks(spec, "worker")
70	assert.Len(t, worker, 2)
71	assert.Equal(t, "db", worker[0].Network)
72	assert.Equal(t, "cache", worker[1].Network)
73
74	assert.Empty(t, domain.AppServiceSharedNetworks(spec, "absent"))
75}

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