v0.15.0 9006957

store_test.go RawHistoryFolder

1package filtering
2
3import (
4	"os"
5	"path/filepath"
6	"testing"
7	"time"
8
9	"github.com/stretchr/testify/assert"
10	"github.com/stretchr/testify/require"
11)
12
13func TestFileFilterStore_SourceVersions(t *testing.T) {
14	// Create temp directory for test
15	tmpDir, err := os.MkdirTemp("", "filter-store-test")
16	require.NoError(t, err)
17	defer os.RemoveAll(tmpDir)
18
19	// Create store with temp paths
20	store := &FileFilterStore{
21		cacheFile: filepath.Join(tmpDir, "cache.json"),
22		metaFile:  filepath.Join(tmpDir, "metadata.json"),
23	}
24
25	testURL := "https://easylist.to/easylist/easylist.txt"
26	testVersion := "202511291248"
27
28	t.Run("get version when no metadata exists", func(t *testing.T) {
29		version := store.GetSourceVersion(testURL)
30		assert.Empty(t, version)
31	})
32
33	t.Run("set and get version", func(t *testing.T) {
34		err := store.SetSourceVersion(testURL, testVersion)
35		require.NoError(t, err)
36
37		version := store.GetSourceVersion(testURL)
38		assert.Equal(t, testVersion, version)
39	})
40
41	t.Run("update existing version", func(t *testing.T) {
42		newVersion := "202511301000"
43		err := store.SetSourceVersion(testURL, newVersion)
44		require.NoError(t, err)
45
46		version := store.GetSourceVersion(testURL)
47		assert.Equal(t, newVersion, version)
48	})
49
50	t.Run("multiple URLs", func(t *testing.T) {
51		url1 := "https://example.com/list1.txt"
52		url2 := "https://example.com/list2.txt"
53		version1 := "111111111111"
54		version2 := "222222222222"
55
56		err := store.SetSourceVersion(url1, version1)
57		require.NoError(t, err)
58		err = store.SetSourceVersion(url2, version2)
59		require.NoError(t, err)
60
61		assert.Equal(t, version1, store.GetSourceVersion(url1))
62		assert.Equal(t, version2, store.GetSourceVersion(url2))
63	})
64
65	t.Run("last check time is updated", func(t *testing.T) {
66		beforeSet := time.Now().Add(-time.Second)
67
68		err := store.SetSourceVersion(testURL, testVersion)
69		require.NoError(t, err)
70
71		lastCheck := store.GetLastCheckTime()
72		assert.True(t, lastCheck.After(beforeSet))
73	})
74}
75
76func TestCacheMetadata_SourceVersions(t *testing.T) {
77	t.Run("nil map handling", func(t *testing.T) {
78		metadata := &CacheMetadata{
79			Version:        cacheVersion,
80			SourceVersions: nil,
81		}
82
83		// Should handle nil map gracefully
84		assert.Nil(t, metadata.SourceVersions)
85	})
86
87	t.Run("initialized map", func(t *testing.T) {
88		metadata := &CacheMetadata{
89			Version: cacheVersion,
90			SourceVersions: map[string]string{
91				"url1": "v1",
92				"url2": "v2",
93			},
94		}
95
96		assert.Equal(t, "v1", metadata.SourceVersions["url1"])
97		assert.Equal(t, "v2", metadata.SourceVersions["url2"])
98		assert.Empty(t, metadata.SourceVersions["nonexistent"])
99	})
100}

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