forked from peterbe/autocompeter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
authkeys_test.go
78 lines (68 loc) · 1.43 KB
/
authkeys_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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
// "fmt"
"github.com/fzzy/radix/extra/pool"
"github.com/fzzy/radix/redis"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"testing"
)
// Set up the suite for running tests with Redis
type Suite struct {
suite.Suite
}
func (suite *Suite) SetupTest() {
var err error
df := func(network, addr string) (*redis.Client, error) {
client, err := redis.Dial(network, addr)
// fmt.Println("DIaling")
if err != nil {
return nil, err
}
err = client.Cmd("SELECT", 8).Err
if err != nil {
return nil, err
}
err = client.Cmd("FLUSHDB").Err
if err != nil {
return nil, err
}
return client, nil
}
redisPool, err = pool.NewCustomPool("tcp", redisURL, 1, df)
if err != nil {
panic(err)
}
}
func TestSuite(t *testing.T) {
suite.Run(t, new(Suite))
}
func (suite *Suite) TestGetDomainSomething() {
// authKeys = new(AuthKeys)
// authKeys.Init()
c, err := redisPool.Get()
errorHandler(err)
defer redisPool.Put(c)
err = c.Cmd("HSET", "$domainkeys", "xyz1234567890", "peterbe.com").Err
errorHandler(err)
domain, err := GetDomain("xyz1234567890", c)
errorHandler(err)
assert.Equal(
suite.T(),
domain,
"peterbe.com",
)
}
func (suite *Suite) TestGetDomainNothing() {
// authKeys = new(AuthKeys)
// authKeys.Init()
c, err := redisPool.Get()
errorHandler(err)
domain, err := GetDomain("xyz1234567890", c)
errorHandler(err)
assert.Equal(
suite.T(),
domain,
"",
)
}