-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtls_test.go
54 lines (43 loc) · 1.03 KB
/
tls_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 main
import (
"bytes"
"context"
"os"
"sync"
"testing"
"github.com/bsm/redislock"
"github.com/caddyserver/certmagic"
"github.com/redis/go-redis/v9"
)
func TestTLS(t *testing.T) {
redisAddr := os.Getenv("REDIS_ADDR")
if redisAddr == "" {
redisAddr = "localhost:6379"
}
rdb := redis.NewClient(&redis.Options{Addr: redisAddr})
rlock := redislock.New(rdb)
certmagic.Default.Storage = &storage{
rdb: rdb,
locker: rlock,
locks: sync.Map{},
}
ctx := context.Background()
domain := "example.com"
key := []byte("key value")
if err := certmagic.Default.Storage.Lock(ctx, domain); err != nil {
t.Fatalf("failed to lock %v", err)
}
if err := certmagic.Default.Storage.Unlock(ctx, domain); err != nil {
t.Fatalf("failed to unlock %v", err)
}
if err := certmagic.Default.Storage.Store(ctx, domain, key); err != nil {
t.Fatalf("failed to store %v", err)
}
b, err := certmagic.Default.Storage.Load(ctx, domain)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(b, key) {
t.Fatalf("keys not equal")
}
}