main 5041353

logo_test.go RawHistoryFolder

1package component
2
3import (
4	"encoding/binary"
5	"errors"
6	"sync"
7	"sync/atomic"
8	"testing"
9
10	"github.com/bnema/dumber/assets"
11	"github.com/bnema/puregotk/v4/gdk"
12	"github.com/stretchr/testify/require"
13)
14
15func resetLogoForTest() {
16	logoTexture = nil
17	logoTextureOnce = sync.Once{}
18}
19
20func TestLogoPNG512AssetSignatureAndDimensions(t *testing.T) {
21	data := assets.LogoPNG512
22	require.NotEmpty(t, data)
23	require.Equal(t, []byte{0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A}, data[:8])
24	require.GreaterOrEqual(t, len(data), 33)
25	require.Equal(t, "IHDR", string(data[12:16]))
26	width := binary.BigEndian.Uint32(data[16:20])
27	height := binary.BigEndian.Uint32(data[20:24])
28	require.Equal(t, uint32(512), width)
29	require.Equal(t, uint32(512), height)
30	require.NotEmpty(t, assets.LogoSVG, "SVG source for desktop icons must remain")
31}
32
33func TestGetLogoTextureRequestsRasterOnce(t *testing.T) {
34	resetLogoForTest()
35	origAsset, origDecode := logoAssetBytes, logoDecodeTexture
36	defer func() {
37		logoAssetBytes, logoDecodeTexture = origAsset, origDecode
38		resetLogoForTest()
39	}()
40	var calls atomic.Int32
41	logoAssetBytes = func() []byte {
42		calls.Add(1)
43		return assets.LogoPNG512
44	}
45	logoDecodeTexture = func(data []byte) (*gdk.Texture, error) {
46		require.Equal(t, assets.LogoPNG512, data)
47		return nil, errors.New("native unavailable in unit test")
48	}
49	require.NotPanics(t, func() {
50		require.Nil(t, GetLogoTexture())
51		require.Nil(t, GetLogoTexture())
52	})
53	require.Equal(t, int32(1), calls.Load(), "raster bytes must be requested once")
54}
55
56func TestGetLogoTextureConcurrentCallersShareResult(t *testing.T) {
57	resetLogoForTest()
58	origAsset, origDecode := logoAssetBytes, logoDecodeTexture
59	defer func() {
60		logoAssetBytes, logoDecodeTexture = origAsset, origDecode
61		resetLogoForTest()
62	}()
63	var calls atomic.Int32
64	logoAssetBytes = func() []byte {
65		calls.Add(1)
66		return assets.LogoPNG512
67	}
68	logoDecodeTexture = func([]byte) (*gdk.Texture, error) {
69		return nil, errors.New("native unavailable in unit test")
70	}
71	var wg sync.WaitGroup
72	for range 16 {
73		wg.Add(1)
74		go func() {
75			defer wg.Done()
76			_ = GetLogoTexture()
77		}()
78	}
79	wg.Wait()
80	require.Equal(t, int32(1), calls.Load())
81}
82
83func TestGetLogoTextureFailureDoesNotPanic(t *testing.T) {
84	resetLogoForTest()
85	origAsset, origDecode := logoAssetBytes, logoDecodeTexture
86	defer func() {
87		logoAssetBytes, logoDecodeTexture = origAsset, origDecode
88		resetLogoForTest()
89	}()
90	logoAssetBytes = func() []byte { return nil }
91	logoDecodeTexture = func([]byte) (*gdk.Texture, error) {
92		return nil, errors.New("must not be called with empty asset")
93	}
94	require.NotPanics(t, func() {
95		require.Nil(t, GetLogoTexture())
96	})
97}

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