v0.23.1 6c872d5

session_repo_test.go RawHistoryFolder

1package sqlite_test
2
3import (
4	"context"
5	"path/filepath"
6	"testing"
7	"time"
8
9	"github.com/bnema/dumber/internal/domain/entity"
10	"github.com/bnema/dumber/internal/infrastructure/persistence/sqlite"
11	"github.com/bnema/dumber/internal/logging"
12	"github.com/stretchr/testify/assert"
13	"github.com/stretchr/testify/require"
14)
15
16func testCtx() context.Context {
17	logger := logging.NewFromConfigValues("debug", "console")
18	return logging.WithContext(context.Background(), logger)
19}
20
21func TestSessionRepository_CRUD(t *testing.T) {
22	ctx := testCtx()
23	dbPath := filepath.Join(t.TempDir(), "dumber.db")
24
25	db, err := sqlite.NewConnection(ctx, dbPath)
26	require.NoError(t, err)
27	t.Cleanup(func() { _ = db.Close() })
28
29	repo := sqlite.NewSessionRepository(db)
30
31	startedAt := time.Date(2025, 12, 22, 8, 0, 0, 0, time.UTC)
32	s := &entity.Session{ID: "20251222_080000_abcd", Type: entity.SessionTypeBrowser, StartedAt: startedAt}
33	require.NoError(t, repo.Save(ctx, s))
34
35	got, err := repo.FindByID(ctx, s.ID)
36	require.NoError(t, err)
37	require.NotNil(t, got)
38	assert.Equal(t, s.ID, got.ID)
39	assert.Equal(t, s.Type, got.Type)
40	assert.True(t, got.StartedAt.Equal(startedAt))
41	assert.Nil(t, got.EndedAt)
42
43	active, err := repo.GetActive(ctx)
44	require.NoError(t, err)
45	require.NotNil(t, active)
46	assert.Equal(t, s.ID, active.ID)
47
48	endedAt := time.Date(2025, 12, 22, 9, 0, 0, 0, time.UTC)
49	require.NoError(t, repo.MarkEnded(ctx, s.ID, endedAt))
50
51	active2, err := repo.GetActive(ctx)
52	require.NoError(t, err)
53	assert.Nil(t, active2)
54
55	got2, err := repo.FindByID(ctx, s.ID)
56	require.NoError(t, err)
57	require.NotNil(t, got2.EndedAt)
58	assert.True(t, got2.EndedAt.Equal(endedAt))
59
60	recent, err := repo.GetRecent(ctx, 10)
61	require.NoError(t, err)
62	require.Len(t, recent, 1)
63	assert.Equal(t, s.ID, recent[0].ID)
64}

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 8

Tags 42

↑↓ moveenter openesc close