forked from launchdarkly/go-server-sdk-redis-redigo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
redis_big_segments_test.go
54 lines (47 loc) · 1.33 KB
/
redis_big_segments_test.go
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
package ldredis
import (
"fmt"
"testing"
"github.com/launchdarkly/go-server-sdk/v7/subsystems"
"github.com/launchdarkly/go-server-sdk/v7/testhelpers/storetest"
r "github.com/gomodule/redigo/redis"
"github.com/stretchr/testify/require"
)
func TestBigSegmentStore(t *testing.T) {
client, err := r.DialURL(redisURL)
require.NoError(t, err)
defer client.Close()
setTestMetadata := func(prefix string, metadata subsystems.BigSegmentStoreMetadata) error {
if prefix == "" {
prefix = DefaultPrefix
}
_, err := client.Do("SET", bigSegmentsSyncTimeKey(prefix), fmt.Sprintf("%d", metadata.LastUpToDate))
return err
}
setTestSegments := func(prefix string, contextHashKey string, included []string, excluded []string) error {
if prefix == "" {
prefix = DefaultPrefix
}
for _, inc := range included {
_, err := client.Do("SADD", bigSegmentsIncludeKey(prefix, contextHashKey), inc)
if err != nil {
return err
}
}
for _, exc := range excluded {
_, err := client.Do("SADD", bigSegmentsExcludeKey(prefix, contextHashKey), exc)
if err != nil {
return err
}
}
return nil
}
storetest.NewBigSegmentStoreTestSuite(
func(prefix string) subsystems.ComponentConfigurer[subsystems.BigSegmentStore] {
return BigSegmentStore().Prefix(prefix)
},
clearTestData,
setTestMetadata,
setTestSegments,
).Run(t)
}