You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.4 KiB
Go

package redis
// Tests for Redis config defaults, address formatting, and placeholder methods.
import (
"context"
"testing"
"github.com/stretchr/testify/require"
)
// TestDefaultConfig verifies default configuration values for the client.
func TestDefaultConfig(t *testing.T) {
cfg := DefaultConfig()
require.Equal(t, "localhost", cfg.Host)
require.Equal(t, 6379, cfg.Port)
}
// TestAddr verifies Redis address formatting from config.
func TestAddr(t *testing.T) {
cfg := DefaultConfig()
require.Equal(t, "localhost:6379", cfg.Addr())
}
// TestHealthCheck verifies health checks delegate to Ping without error.
func TestHealthCheck(t *testing.T) {
client, err := NewClient(DefaultConfig())
require.NoError(t, err)
require.NoError(t, client.HealthCheck(context.Background()))
}
// TestNotImplemented verifies placeholder Redis methods return errors.
func TestNotImplemented(t *testing.T) {
client, err := NewClient(DefaultConfig())
require.NoError(t, err)
require.Error(t, client.Set(context.Background(), "k", "v", 0))
_, err = client.Get(context.Background(), "k")
require.Error(t, err)
require.Error(t, client.Delete(context.Background(), "k"))
_, err = client.Exists(context.Background(), "k")
require.Error(t, err)
_, err = client.Incr(context.Background(), "k")
require.Error(t, err)
require.Error(t, client.Expire(context.Background(), "k", 0))
}