forked from p93542168/wheat-cache
test(structure-hashx): add hashx test
This commit is contained in:
parent
06baf3993d
commit
c3cff03b2b
|
@ -0,0 +1,62 @@
|
|||
package hashx
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestHashX_Set_SetX(t *testing.T) {
|
||||
h := NewHashXSingle()
|
||||
h.Set("key", "opq")
|
||||
res, err := h.Get("key")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, res, "opq")
|
||||
b, _ := h.SetX("key", "opq")
|
||||
require.Equal(t, b, false)
|
||||
|
||||
b, _ = h.SetX("key1", "opq")
|
||||
require.Equal(t, b, true)
|
||||
res, err = h.Get("key1")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, res, "opq")
|
||||
}
|
||||
|
||||
func TestHashX_Del(t *testing.T) {
|
||||
h := NewHashXSingle()
|
||||
up := h.Set("key", "opq")
|
||||
upu, err := h.Del("key")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, up, upu)
|
||||
}
|
||||
|
||||
func TestHashX_Key(t *testing.T) {
|
||||
h := NewHashXSingle()
|
||||
h.Set("key", "opq")
|
||||
h.Set("key1", "opq")
|
||||
h.Set("key2", "opq")
|
||||
|
||||
require.Equal(t, h.Key(), []string{"key", "key1", "key2"})
|
||||
}
|
||||
|
||||
func TestHashX_Value(t *testing.T) {
|
||||
h := NewHashXSingle()
|
||||
h.Set("key", "opq")
|
||||
h.Set("key1", "opq")
|
||||
h.Set("key2", "opq")
|
||||
|
||||
require.Equal(t, h.Value(), []string{"opq", "opq", "opq"})
|
||||
}
|
||||
|
||||
func TestHashX_Add(t *testing.T) {
|
||||
h := NewHashXSingle()
|
||||
h.Set("1", "1")
|
||||
c, res, err := h.Add(1, "1")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, c, 1)
|
||||
require.Equal(t, res, []string{"2"})
|
||||
|
||||
s, err := h.Get("1")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, s, "2")
|
||||
}
|
Loading…
Reference in New Issue