-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcommand_author_store_test.go
More file actions
83 lines (65 loc) · 2.56 KB
/
Copy pathcommand_author_store_test.go
File metadata and controls
83 lines (65 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// SPDX-License-Identifier: Apache-2.0
package queue
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func newTestCommandAuthorStore(t *testing.T) *CommandAuthorStore {
t.Helper()
return newTestRedisStore(t).CommandAuthorStore()
}
func TestCommandAuthorStore_RecordAndLookup(t *testing.T) {
store := newTestCommandAuthorStore(t)
ctx := context.Background()
author := CommandAuthor{
Author: "alice",
DisplayName: "Alice",
Email: "alice@example.com",
RequestedAt: "2026-06-29T00:00:00Z",
}
require.NoError(t, store.RecordCommandAuthor(ctx, "cr-uid", author))
got, ok := store.LookupCommandAuthor(ctx, "cr-uid")
require.True(t, ok)
require.Equal(t, author, got)
}
func TestCommandAuthorStore_LookupMissIsImmediate(t *testing.T) {
store := newTestCommandAuthorStore(t)
// Present-or-never: an unrecorded uid is an immediate miss, no wait.
_, ok := store.LookupCommandAuthor(context.Background(), "never-recorded")
require.False(t, ok)
}
func TestCommandAuthorStore_LastWriteWins(t *testing.T) {
store := newTestCommandAuthorStore(t)
ctx := context.Background()
require.NoError(t, store.RecordCommandAuthor(ctx, "cr-uid", CommandAuthor{Author: "alice"}))
require.NoError(t, store.RecordCommandAuthor(ctx, "cr-uid", CommandAuthor{Author: "bob"}))
got, ok := store.LookupCommandAuthor(ctx, "cr-uid")
require.True(t, ok)
require.Equal(t, "bob", got.Author)
}
func TestCommandAuthorStore_EmptyAuthorIsMiss(t *testing.T) {
store := newTestCommandAuthorStore(t)
ctx := context.Background()
// A record with no author cannot name a commit author, so it reads as a miss.
require.NoError(t, store.RecordCommandAuthor(ctx, "cr-uid", CommandAuthor{}))
_, ok := store.LookupCommandAuthor(ctx, "cr-uid")
require.False(t, ok)
}
func TestCommandAuthorStore_RecordCarriesCleanupTTL(t *testing.T) {
redisStore, mr := newTestRedisStoreWithRedis(t)
store := redisStore.CommandAuthorStore()
ctx := context.Background()
require.NoError(t, store.RecordCommandAuthor(ctx, "cr-uid", CommandAuthor{Author: "alice"}))
// The record carries a fixed cleanup TTL and self-cleans once it elapses (an orphan
// command deleted before its reconcile never blocks Redis).
require.Equal(t, commandAuthorRecordTTL, mr.TTL(store.key("cr-uid")))
mr.FastForward(commandAuthorRecordTTL + time.Second)
_, ok := store.LookupCommandAuthor(ctx, "cr-uid")
require.False(t, ok)
}
func TestCommandAuthorStore_KeyReadableFormat(t *testing.T) {
store := newTestCommandAuthorStore(t)
require.Equal(t, "gitops-reverser:author:v1:command:cr-uid", store.key("cr-uid"))
}