-
Notifications
You must be signed in to change notification settings - Fork 344
Expand file tree
/
Copy pathscripts_test.go
More file actions
51 lines (43 loc) · 1.18 KB
/
scripts_test.go
File metadata and controls
51 lines (43 loc) · 1.18 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
package redsync
import (
"context"
"testing"
"github.com/go-redsync/redsync/v4/redis"
"github.com/go-redsync/redsync/v4/redis/goredis/v9"
goredislib_v9 "github.com/redis/go-redis/v9"
"github.com/stvp/tempredis"
)
func TestScripts_Hash(t *testing.T) {
testScriptHash(t, "deleteScript", deleteScript)
testScriptHash(t, "touchWithSetNXScript", touchWithSetNXScript)
testScriptHash(t, "touchScript", touchScript)
}
func testScriptHash(t *testing.T, name string, script *redis.Script) {
t.Run(name, func(t *testing.T) {
server, err := tempredis.Start(tempredis.Config{})
if err != nil {
t.Fatal(err)
}
defer server.Term()
client := goredislib_v9.NewClient(&goredislib_v9.Options{
Network: "unix",
Addr: server.Socket(),
})
pool := goredis.NewPool(client)
conn, err := pool.Get(context.Background())
if err != nil {
t.Fatal(err)
}
dupscript := redis.NewScript(script.KeyCount, script.Src, "")
err = conn.ScriptLoad(dupscript)
if err != nil {
t.Fatal(err)
}
if dupscript.Hash == "" {
t.Fatal("script hash is empty")
}
if dupscript.Hash != script.Hash {
t.Fatalf("script hash mismatch; want %s, got %s", script.Hash, dupscript.Hash)
}
})
}