Files
o11y/pkg/cache/rediscache/provider_test.go
zeekay bf8f46d0fa refactor(cache): bump kv-go to v9.22.0 and rename qualifier redis -> kv
hanzokv/go v9.22.0 renames its Go package from `redis` to `kv`, and its
companion modules were renamed too. Import paths that moved:

  extra/redisotel/v9 -> extra/kvotel/v9  (pkg redisotel -> kvotel)
  extra/rediscmd/v9  -> extra/kvcmd/v9   (indirect)

hanzokv/mock v9.2.2 follows suit: package redismock -> kvmock.

rediscache/provider.go imported both unaliased, so the qualifiers changed
along with the paths. go/v9 is now aliased `kv` explicitly, since the
package name is not derivable from its import path.

Deliberately NOT renamed:
- the pkg/cache/rediscache directory. This fork re-syncs pkg/ and cmd/
  wholesale from upstream o11y main, so renaming a directory buys a
  permanent conflict on every future re-sync for zero functional gain.
- the provider selector factory.MustNewName("redis") and the config key
  mapstructure:"redis". Both are operator config surface, matching the
  existing convention that kept the "clickhouse" selector value.

go mod tidy was NOT run: this repo's go.mod is paired with the ci.yaml
cloud pin and tidy resolves against whatever ../cloud is checked out.
Used go mod edit + go mod download instead, so go.sum keeps some inert
entries for the old module paths.

Verified: go build ./... exit 0, go vet ./pkg/cache/... exit 0, and
pkg/cache TestSet passes against the renamed kvmock.
2026-07-26 08:50:04 -07:00

61 lines
1.5 KiB
Go

package rediscache
import (
"context"
"encoding/json"
"strings"
"testing"
"time"
"github.com/hanzoai/o11y/pkg/factory"
"github.com/hanzoai/o11y/pkg/instrumentation/instrumentationtest"
"github.com/hanzoai/o11y/pkg/types/cachetypes"
"github.com/hanzoai/o11y/pkg/valuer"
kvmock "github.com/hanzokv/mock/v9"
"github.com/stretchr/testify/assert"
)
type CacheableA struct {
Key string
Value int
Expiry time.Duration
}
func (cacheable *CacheableA) Clone() cachetypes.Cacheable {
return &CacheableA{
Key: cacheable.Key,
Value: cacheable.Value,
Expiry: cacheable.Expiry,
}
}
func (cacheable *CacheableA) Cost() int64 {
return int64(len(cacheable.Key)) + 16
}
func (cacheable *CacheableA) MarshalBinary() ([]byte, error) {
return json.Marshal(cacheable)
}
func (cacheable *CacheableA) UnmarshalBinary(data []byte) error {
return json.Unmarshal(data, cacheable)
}
func TestSet(t *testing.T) {
db, mock := kvmock.NewClientMock()
providerSettings := instrumentationtest.New().ToProviderSettings()
cache := &provider{client: db, settings: factory.NewScopedProviderSettings(providerSettings, "github.com/hanzoai/o11y/pkg/cache/rediscache")}
cacheable := &CacheableA{
Key: "some-random-key",
Value: 1,
Expiry: time.Microsecond,
}
orgID := valuer.GenerateUUID()
mock.ExpectSet(strings.Join([]string{orgID.StringValue(), "key"}, "::"), cacheable, 10*time.Second).SetVal("ok")
assert.NoError(t, cache.Set(context.Background(), orgID, "key", cacheable, 10*time.Second))
assert.NoError(t, mock.ExpectationsWereMet())
}