46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
|
package domain
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
// TestRedisKeyToString 測試 ToString 方法
|
||
|
func TestRedisKeyToString(t *testing.T) {
|
||
|
key := RedisKey("user:timeline")
|
||
|
expected := "user:timeline"
|
||
|
result := key.ToString()
|
||
|
|
||
|
assert.Equal(t, expected, result, "ToString should return the correct string representation of RedisKey")
|
||
|
}
|
||
|
|
||
|
// TestRedisKeyWith 測試 With 方法
|
||
|
func TestRedisKeyWith(t *testing.T) {
|
||
|
key := RedisKey("user:timeline")
|
||
|
subKey := "12345"
|
||
|
expected := "user:timeline:12345"
|
||
|
result := key.With(subKey)
|
||
|
|
||
|
assert.Equal(t, RedisKey(expected), result, "With should correctly concatenate the RedisKey with the provided subKey")
|
||
|
}
|
||
|
|
||
|
// TestRedisKeyWithMultiple 測試 With 方法與多個參數
|
||
|
func TestRedisKeyWithMultiple(t *testing.T) {
|
||
|
key := RedisKey("user:timeline")
|
||
|
subKeys := []string{"12345", "posts"}
|
||
|
expected := "user:timeline:12345:posts"
|
||
|
result := key.With(subKeys...)
|
||
|
|
||
|
assert.Equal(t, RedisKey(expected), result, "With should correctly concatenate the RedisKey with multiple provided subKeys")
|
||
|
}
|
||
|
|
||
|
// TestRedisKeyWithEmpty 測試 With 方法與空參數
|
||
|
func TestRedisKeyWithEmpty(t *testing.T) {
|
||
|
key := RedisKey("user:timeline")
|
||
|
expected := "user:timeline"
|
||
|
result := key.With()
|
||
|
|
||
|
assert.Equal(t, RedisKey(expected), result, "With should return the original key when no subKeys are provided")
|
||
|
}
|