mirror of
https://github.com/go-eagle/eagle.git
synced 2025-10-07 01:22:53 +08:00
133 lines
2.4 KiB
Go
133 lines
2.4 KiB
Go
package redis
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/go-redis/redis"
|
|
)
|
|
|
|
func TestNew(t *testing.T) {
|
|
InitTestRedis()
|
|
|
|
type args struct {
|
|
conn *redis.Client
|
|
key string
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want *IdAlloc
|
|
}{
|
|
{
|
|
name: "test new id alloc",
|
|
args: args{
|
|
conn: RedisClient,
|
|
key: "test_id",
|
|
},
|
|
want: &IdAlloc{
|
|
key: "test_id",
|
|
redisClient: RedisClient,
|
|
},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := New(tt.args.conn, tt.args.key); !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("New() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestIdAlloc_GetCurrentID(t *testing.T) {
|
|
type fields struct {
|
|
key string
|
|
redisClient *redis.Client
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
fields fields
|
|
want int64
|
|
wantErr bool
|
|
}{
|
|
// TODO: Add test cases.
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
ia := &IdAlloc{
|
|
key: tt.fields.key,
|
|
redisClient: tt.fields.redisClient,
|
|
}
|
|
got, err := ia.GetCurrentID()
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("GetCurrentID() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if got != tt.want {
|
|
t.Errorf("GetCurrentID() got = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestIdAlloc_GetKey(t *testing.T) {
|
|
type fields struct {
|
|
key string
|
|
redisClient *redis.Client
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
fields fields
|
|
want string
|
|
}{
|
|
// TODO: Add test cases.
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
ia := &IdAlloc{
|
|
key: tt.fields.key,
|
|
redisClient: tt.fields.redisClient,
|
|
}
|
|
if got := ia.GetKey(); got != tt.want {
|
|
t.Errorf("GetKey() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestIdAlloc_GetNewID(t *testing.T) {
|
|
type fields struct {
|
|
key string
|
|
redisClient *redis.Client
|
|
}
|
|
type args struct {
|
|
step int64
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
fields fields
|
|
args args
|
|
want int64
|
|
wantErr bool
|
|
}{
|
|
// TODO: Add test cases.
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
ia := &IdAlloc{
|
|
key: tt.fields.key,
|
|
redisClient: tt.fields.redisClient,
|
|
}
|
|
got, err := ia.GetNewID(tt.args.step)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("GetNewID() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if got != tt.want {
|
|
t.Errorf("GetNewID() got = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|