kernel_test.go RawHistoryFolder

1package app
2
3import (
4	"errors"
5	"fmt"
6	"os"
7	"path/filepath"
8	"testing"
9
10	"github.com/bnema/zerowrap"
11	"github.com/stretchr/testify/assert"
12	"github.com/stretchr/testify/require"
13)
14
15func TestNewKernel(t *testing.T) {
16	t.Parallel()
17
18	tmpDir := t.TempDir()
19	cfgPath := filepath.Join(tmpDir, "gordon.toml")
20	dataDir := filepath.Join(tmpDir, "data")
21
22	cfg := fmt.Sprintf(`[server]
23gordon_domain = "gordon.local"
24data_dir = %q
25
26[auth]
27enabled = false
28secrets_backend = "unsafe"
29`, dataDir)
30
31	err := os.WriteFile(cfgPath, []byte(cfg), 0o600)
32	require.NoError(t, err)
33
34	kernel, err := NewKernel(cfgPath)
35	require.NoError(t, err)
36	require.NotNil(t, kernel)
37	t.Cleanup(func() { require.NoError(t, kernel.Close()) })
38
39	require.NotNil(t, kernel.Config())
40}
41
42// TestKernelClose_QuiescenceTimeoutSkipsCleanup proves the fail-closed kernel
43// Close ordering: daemon-owned app administration is cancelled and joined on
44// a bounded context before any remaining kernel resource is torn down, and
45// when that quiescence times out the dependency teardown is skipped and the
46// error is returned, so an unfinished deploy is never dropped onto a closed
47// state or runtime.
48func TestKernelClose_QuiescenceTimeoutSkipsCleanup(t *testing.T) {
49	t.Parallel()
50
51	order := []string{}
52	admin := &orderRecordingAdmin{order: &order, err: errors.New("in-flight deploy did not unwind")}
53	cleanedUp := false
54	kernel := &Kernel{
55		appAdmin: admin,
56		log:      zerowrap.Default(),
57		cleanup:  func() { cleanedUp = true; order = append(order, "cleanup") },
58	}
59
60	require.Error(t, kernel.Close())
61	require.Equal(t, []string{"app-shutdown"}, order, "teardown must stop when quiescence times out")
62	assert.False(t, cleanedUp)
63	assert.True(t, admin.deadline, "app administration shutdown must run on a bounded context")
64}
65
66// TestKernelClose_CleansUpAfterQuiescence keeps the normal path: once app
67// administration joined cleanly, the kernel still tears its resources down.
68func TestKernelClose_CleansUpAfterQuiescence(t *testing.T) {
69	t.Parallel()
70
71	order := []string{}
72	admin := &orderRecordingAdmin{order: &order}
73	kernel := &Kernel{
74		appAdmin: admin,
75		log:      zerowrap.Default(),
76		cleanup:  func() { order = append(order, "cleanup") },
77	}
78
79	require.NoError(t, kernel.Close())
80	require.Equal(t, []string{"app-shutdown", "cleanup"}, order)
81}
82
83// TestKernelClose_WithoutAppAdministrationStillCleansUp keeps the minimal
84// kernel path (no full service wiring) closing without a nil-interface trap.
85func TestKernelClose_WithoutAppAdministrationStillCleansUp(t *testing.T) {
86	t.Parallel()
87
88	cleaned := false
89	kernel := &Kernel{log: zerowrap.Default(), cleanup: func() { cleaned = true }}
90
91	require.NoError(t, kernel.Close())
92	assert.True(t, cleaned)
93}

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