Files
zeekayandHanzo Dev 7015fe8288 refactor: follow hanzokv/go v9.22.0 package rename redis -> kv
github.com/hanzokv/go/v9 v9.22.0 renamed its Go package from "redis" to
"kv"; the import path is unchanged. A mock library is typed against the
client it wraps, so this is not cosmetic: every exported signature in
this package (ClientMock, ClusterClientMock, all Expect* methods) is
expressed in terms of the client's types, and none of them resolve under
the old qualifier.

What changed:

- go.mod: github.com/hanzokv/go/v9 v9.21.1 -> v9.22.0
- every "redis." qualifier -> "kv." The import stays unaliased, matching
  the convention in hanzokv/go's own sources.
- package redismock -> package kvmock, matching the hanzokv/mock repo
- our own vocabulary follows the client it mocks: RedisNil() -> KVNil(),
  isRedisNil/redisNil -> isKVNil/kvNil, redisClientType -> kvClientType,
  redisClient/redisCluster -> kvClient/kvCluster,
  redisClientHook -> kvClientHook, TestRedisMock -> TestKVMock
- comments and README speak kv
- gofmt: import blocks in the ginkgo test files were left unsorted by the
  fork commit; formatting them is a side effect of touching them

Opaque test payloads are left alone -- they are data, not vocabulary.

Verified: go build ./..., go vet ./..., go test ./..., and
go test ./... -short -race all pass.

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-26 08:42:54 -07:00

67 lines
1.3 KiB
Go

package ordinary
import (
"errors"
"testing"
"github.com/hanzokv/mock/v9"
)
func TestItemCacheFail(t *testing.T) {
var (
itemID = "7d373ca58e"
setErr = errors.New("bomb")
)
db, mock := kvmock.NewClientMock()
mock.ExpectHGet(itemKey, itemID).KVNil()
mock.Regexp().ExpectHSet(itemKey, itemID, `^[a-z]+$`).SetErr(setErr)
_, err := ItemCache(db, itemID)
if err != setErr {
t.Error("expectation error")
}
if err := mock.ExpectationsWereMet(); err != nil {
t.Error(err)
}
}
func TestItemCacheSuccess(t *testing.T) {
var (
itemID = "7d373ca58e"
)
db, mock := kvmock.NewClientMock()
mock.ExpectHGet(itemKey, itemID).KVNil()
mock.Regexp().ExpectHSet(itemKey, itemID, `^[a-z]+$`).SetVal(1)
item, err := ItemCache(db, itemID)
if err != nil {
t.Errorf("unexpected error: %s", err.Error())
}
if item != "information" {
t.Errorf("unexpected item: %s", item)
}
if err := mock.ExpectationsWereMet(); err != nil {
t.Error(err)
}
//----------
//clean up all expectations
//reset expected kv command
mock.ClearExpect()
mock.ExpectHGet(itemKey, itemID).SetVal("news")
item, err = ItemCache(db, itemID)
if err != nil {
t.Errorf("unexpected error: %s", err.Error())
}
if item != "news" {
t.Errorf("unexpected item: %s", item)
}
if err := mock.ExpectationsWereMet(); err != nil {
t.Error(err)
}
}