v3.3.1 31f1eec

activate_test.go RawHistoryFolder

1package apptraffic_test
2
3import (
4	"context"
5	"testing"
6
7	"github.com/bnema/zerowrap"
8	"github.com/stretchr/testify/assert"
9	"github.com/stretchr/testify/require"
10
11	"github.com/bnema/gordon/internal/domain"
12	"github.com/bnema/gordon/internal/usecase/apptraffic"
13)
14
15type stubState struct {
16	intents map[string]domain.AppStopIntent
17	actives map[string]domain.AppActive
18}
19
20func (s stubState) ListApps(_ context.Context) ([]string, error) {
21	apps := make([]string, 0, len(s.actives)+len(s.intents))
22	seen := map[string]bool{}
23	for app := range s.actives {
24		if !seen[app] {
25			seen[app] = true
26			apps = append(apps, app)
27		}
28	}
29	for app := range s.intents {
30		if !seen[app] {
31			seen[app] = true
32			apps = append(apps, app)
33		}
34	}
35	return apps, nil
36}
37
38func (s stubState) LoadIntent(_ context.Context, app string) (domain.AppStopIntent, error) {
39	return s.intents[app], nil
40}
41
42func (s stubState) LoadActive(_ context.Context, app string) (domain.AppActive, bool, error) {
43	active, ok := s.actives[app]
44	return active, ok, nil
45}
46
47func TestActivator_RebuildHostIndex(t *testing.T) {
48	ctx := context.Background()
49	activator := apptraffic.NewActivator(zerowrap.Default())
50	index := apptraffic.NewHostIndex()
51
52	served := domain.AppActive{
53		App: "blog",
54		Services: map[string]domain.AppEffectiveService{
55			"web": {
56				EffectiveRevision: "rev-1", Image: "img:1",
57				Spec: domain.AppService{
58					HTTP: []domain.AppHTTPInterface{{Host: "blog.example.com", Port: 8080, TLS: "auto"}},
59				},
60			},
61		},
62	}
63	stopped := domain.AppActive{
64		App: "old",
65		Services: map[string]domain.AppEffectiveService{
66			"web": {
67				EffectiveRevision: "rev-1", Image: "img:1",
68				Spec: domain.AppService{
69					HTTP: []domain.AppHTTPInterface{{Host: "old.example.com", Port: 8080, TLS: "auto"}},
70				},
71			},
72		},
73	}
74	state := stubState{
75		actives: map[string]domain.AppActive{"blog": served, "old": stopped},
76		intents: map[string]domain.AppStopIntent{"old": {Stopped: true}},
77	}
78
79	require.NoError(t, activator.RebuildHostIndex(ctx, index, state, nil))
80
81	_, ok := index.Lookup("blog.example.com")
82	assert.True(t, ok)
83	_, ok = index.Lookup("old.example.com")
84	assert.False(t, ok, "STOPPED-intent app must not stay routable")
85}

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