Files
go-zero/core/stores/cache/util_test.go

49 lines
750 B
Go
Raw Normal View History

2020-10-01 11:57:06 +08:00
package cache
import (
"testing"
2020-10-11 22:07:50 +08:00
"time"
2020-10-01 11:57:06 +08:00
2020-10-11 22:07:50 +08:00
"github.com/alicebob/miniredis"
2020-10-01 11:57:06 +08:00
"github.com/stretchr/testify/assert"
2020-10-11 22:07:50 +08:00
"github.com/tal-tech/go-zero/core/lang"
2020-10-01 11:57:06 +08:00
)
func TestFormatKeys(t *testing.T) {
assert.Equal(t, "a,b", formatKeys([]string{"a", "b"}))
}
func TestTotalWeights(t *testing.T) {
val := TotalWeights([]NodeConf{
{
Weight: -1,
},
{
Weight: 0,
},
{
Weight: 1,
},
})
assert.Equal(t, 1, val)
}
2020-10-11 22:07:50 +08:00
func createMiniRedis() (r *miniredis.Miniredis, clean func(), err error) {
r, err = miniredis.Run()
if err != nil {
return nil, nil, err
}
return r, func() {
ch := make(chan lang.PlaceholderType)
go func() {
r.Close()
close(ch)
}()
select {
case <-ch:
case <-time.After(time.Second):
}
}, nil
}