v2.31.0-dev8 ec8c5b9

dispatcher_test.go RawHistoryFolder

1package auto
2
3import (
4	"context"
5	"testing"
6
7	"github.com/stretchr/testify/assert"
8
9	"github.com/bnema/gordon/internal/domain"
10)
11
12type mockHandler struct {
13	called bool
14}
15
16func (m *mockHandler) Handle(_ context.Context, _ domain.Event) error {
17	m.called = true
18	return nil
19}
20
21func (m *mockHandler) CanHandle(t domain.EventType) bool {
22	return t == domain.EventImagePushed
23}
24
25type mockAutoConfig struct {
26	previewEnabled bool
27	tagPatterns    []string
28}
29
30func (m *mockAutoConfig) IsAutoEnabled() bool                    { return true }
31func (m *mockAutoConfig) IsPreviewEnabled() bool                 { return m.previewEnabled }
32func (m *mockAutoConfig) GetPreviewTagPatterns() []string        { return m.tagPatterns }
33func (m *mockAutoConfig) GetPreviewConfig() domain.PreviewConfig { return domain.PreviewConfig{} }
34func (m *mockAutoConfig) GetAllowedDomains() []string            { return nil }
35func (m *mockAutoConfig) FindRoutesByImage(_ context.Context, _ string) []domain.Route {
36	return nil
37}
38
39func TestDispatcher_PreviewTag_DelegatesToPreview(t *testing.T) {
40	route := &mockHandler{}
41	preview := &mockHandler{}
42	d := NewImagePushDispatcher(
43		&mockAutoConfig{previewEnabled: true, tagPatterns: []string{"preview-*"}},
44		route, preview,
45	)
46	event := domain.Event{
47		Type: domain.EventImagePushed,
48		Data: domain.ImagePushedPayload{Name: "myapp", Reference: "preview-feat"},
49	}
50	err := d.Handle(context.Background(), event)
51	assert.NoError(t, err)
52	assert.True(t, preview.called)
53	assert.False(t, route.called)
54}
55
56func TestDispatcher_NormalTag_DelegatesToRoute(t *testing.T) {
57	route := &mockHandler{}
58	preview := &mockHandler{}
59	d := NewImagePushDispatcher(
60		&mockAutoConfig{previewEnabled: true, tagPatterns: []string{"preview-*"}},
61		route, preview,
62	)
63	event := domain.Event{
64		Type: domain.EventImagePushed,
65		Data: domain.ImagePushedPayload{Name: "myapp", Reference: "v1.0.0"},
66	}
67	err := d.Handle(context.Background(), event)
68	assert.NoError(t, err)
69	assert.True(t, route.called)
70	assert.False(t, preview.called)
71}
72
73func TestDispatcher_PreviewDisabled_AlwaysRoute(t *testing.T) {
74	route := &mockHandler{}
75	preview := &mockHandler{}
76	d := NewImagePushDispatcher(
77		&mockAutoConfig{previewEnabled: false, tagPatterns: []string{"preview-*"}},
78		route, preview,
79	)
80	event := domain.Event{
81		Type: domain.EventImagePushed,
82		Data: domain.ImagePushedPayload{Name: "myapp", Reference: "preview-feat"},
83	}
84	err := d.Handle(context.Background(), event)
85	assert.NoError(t, err)
86	assert.True(t, route.called)
87	assert.False(t, preview.called)
88}
89
90func TestDispatcher_CanHandle(t *testing.T) {
91	d := &ImagePushDispatcher{}
92	assert.True(t, d.CanHandle(domain.EventImagePushed))
93	assert.False(t, d.CanHandle(domain.EventConfigReload))
94}

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