-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_test.go
82 lines (67 loc) · 1.17 KB
/
server_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
79
80
81
82
package main
import (
"os"
"strconv"
"testing"
)
func initServer(t testing.TB) *Server {
var (
db int
err error
)
if os.Getenv("REDIS_DB") != "" {
db, err = strconv.Atoi(os.Getenv("REDIS_DB"))
if err != nil {
t.Fatal(err)
}
}
s := &Server{
RedisAddr: os.Getenv("REDIS_ADDR"),
RedisDB: int(db),
}
s.Init()
// Flush the DB.
c := s.Pool.Get()
defer c.Close()
if _, err = c.Do("FLUSHDB"); err != nil {
t.Fatal(err)
}
return s
}
func TestServer(t *testing.T) {
s := initServer(t)
n := "test"
def := NewDef()
def.Name = n
def.Type = "seq"
def.Offset = 100000
if err := s.CreateDef(def); err != nil {
t.Fatal(err)
}
idents := []*IdentAlias{
{Ident: "a"},
{Ident: "b"},
{Ident: "c"},
{Ident: "d"},
{Ident: "e"},
{Ident: "f"},
}
idents, err := s.Gen(def, idents)
if err != nil {
t.Fatal(err)
}
for _, ia := range idents {
if ia.Alias == "" || ia.Status != StatusCreated {
t.Errorf("%s alias failed", ia.Ident)
}
}
idents, err = s.Get(def, idents)
if err != nil {
t.Fatal(err)
}
for _, ia := range idents {
if ia.Alias == "" || ia.Status != StatusExists {
t.Errorf("%s alias missing", ia.Ident)
}
}
}