v2.31.0-dev9 062dcae

unsafe_test.go RawHistoryFolder

1package tokenstore
2
3import (
4	"context"
5	"fmt"
6	"io"
7	"sync"
8	"testing"
9
10	"github.com/bnema/zerowrap"
11
12	"github.com/bnema/gordon/internal/domain"
13)
14
15// newTestUnsafeStore creates a UnsafeStore backed by a temp directory.
16func newTestUnsafeStore(t *testing.T) *UnsafeStore {
17	t.Helper()
18	dir := t.TempDir()
19	log := zerowrap.New(zerowrap.Config{Level: "disabled", Output: io.Discard})
20	store, err := NewUnsafeStore(dir, log)
21	if err != nil {
22		t.Fatalf("NewUnsafeStore: %v", err)
23	}
24	return store
25}
26
27func TestUnsafeStoreRevokeConcurrentNoLoss(t *testing.T) {
28	// Run with: go test -race ./internal/adapters/out/tokenstore/... -run TestUnsafeStoreRevokeConcurrentNoLoss -v
29	store := newTestUnsafeStore(t)
30
31	ctx := context.Background()
32	const n = 10
33
34	// Save n tokens
35	tokenIDs := make([]string, n)
36	for i := 0; i < n; i++ {
37		id := fmt.Sprintf("token-%d", i)
38		tokenIDs[i] = id
39		tok := &domain.Token{
40			ID:      id,
41			Subject: fmt.Sprintf("user-%d", i),
42			Scopes:  []string{"admin"},
43		}
44		if err := store.SaveToken(ctx, tok, "jwt-"+id); err != nil {
45			t.Fatal(err)
46		}
47	}
48
49	// Revoke all concurrently; collect errors via a buffered channel.
50	var wg sync.WaitGroup
51	errs := make(chan error, len(tokenIDs))
52	for _, id := range tokenIDs {
53		wg.Add(1)
54		go func(id string) {
55			defer wg.Done()
56			if err := store.Revoke(ctx, id); err != nil {
57				errs <- fmt.Errorf("Revoke(%q): %w", id, err)
58			}
59		}(id)
60	}
61	wg.Wait()
62	close(errs)
63	for err := range errs {
64		t.Error(err)
65	}
66
67	// Verify all n token IDs are in the revoked list
68	for _, id := range tokenIDs {
69		revoked, err := store.IsRevoked(ctx, id)
70		if err != nil {
71			t.Errorf("IsRevoked(%q): %v", id, err)
72			continue
73		}
74		if !revoked {
75			t.Errorf("token %q should be revoked but IsRevoked returned false", id)
76		}
77	}
78}

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