mirror of
https://github.com/hanzokv/go.git
synced 2026-09-24 00:31:51 +00:00
KV lives in its own org now, like hanzokms / hanzos3 / hanzo-ds. The repo moved hanzoai/kv-go -> hanzokv/go, so the module path follows: a Go module path must match where the repo actually is, or the proxy cannot resolve it. The name is `go`, not `kv-go`, following the hanzo-ds convention — that org holds go, mock, native, sqlbuilder, sqlparser, each named for its language or concern with the ORG supplying the product noun. Repeating "kv" inside a repo that already lives under hanzokv is the compound-word habit we are dropping. 349 occurrences across 188 files: the root module, all four extra/* modules, every example module, imports throughout the tree, and the docs. Builds clean. The package is still `package redis` and the extra dirs are still named redis*. That rename is deliberately NOT bundled here: it is 5,771 occurrences, it breaks all 11 consumers at once, and a large share are WIRE CONTRACTS rather than branding — the redis:// scheme parser, the "redis: nil" error string, RESP command names. Renaming those breaks protocol compatibility with the Valkey server. It needs the same our-vocabulary-vs-the-wire split the argo sweep used, as its own change. GitHub keeps the old path redirecting, and versions already published under github.com/hanzoai/kv-go/v9 stay resolvable, so nothing breaks the moment this lands. Consumers move on their own schedule.
102 lines
3.4 KiB
Go
102 lines
3.4 KiB
Go
package streaming
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/hanzokv/go/v9/auth"
|
|
"github.com/hanzokv/go/v9/internal/pool"
|
|
)
|
|
|
|
// Test that Listener returns the newly created listener, not nil
|
|
func TestManager_Listener_ReturnsNewListener(t *testing.T) {
|
|
// Create a mock pool
|
|
mockPool := &mockPooler{}
|
|
|
|
// Create manager
|
|
manager := NewManager(mockPool, time.Second)
|
|
|
|
// Create a mock connection
|
|
conn := &pool.Conn{}
|
|
|
|
// Mock functions
|
|
reAuth := func(cn *pool.Conn, creds auth.Credentials) error {
|
|
return nil
|
|
}
|
|
|
|
onErr := func(cn *pool.Conn, err error) {
|
|
}
|
|
|
|
// Get listener - this should create a new one
|
|
listener, err := manager.Listener(conn, reAuth, onErr)
|
|
|
|
// Verify no error
|
|
if err != nil {
|
|
t.Fatalf("Expected no error, got: %v", err)
|
|
}
|
|
|
|
// Verify listener is not nil (this was the bug!)
|
|
if listener == nil {
|
|
t.Fatal("Expected listener to be non-nil, but got nil")
|
|
}
|
|
|
|
// Verify it's the correct type
|
|
if _, ok := listener.(*ConnReAuthCredentialsListener); !ok {
|
|
t.Fatalf("Expected listener to be *ConnReAuthCredentialsListener, got %T", listener)
|
|
}
|
|
|
|
// Get the same listener again - should return the existing one
|
|
listener2, err := manager.Listener(conn, reAuth, onErr)
|
|
if err != nil {
|
|
t.Fatalf("Expected no error on second call, got: %v", err)
|
|
}
|
|
|
|
if listener2 == nil {
|
|
t.Fatal("Expected listener2 to be non-nil")
|
|
}
|
|
|
|
// Should be the same instance
|
|
if listener != listener2 {
|
|
t.Error("Expected to get the same listener instance on second call")
|
|
}
|
|
}
|
|
|
|
// Test that Listener returns error when conn is nil
|
|
func TestManager_Listener_NilConn(t *testing.T) {
|
|
mockPool := &mockPooler{}
|
|
manager := NewManager(mockPool, time.Second)
|
|
|
|
listener, err := manager.Listener(nil, nil, nil)
|
|
|
|
if err == nil {
|
|
t.Fatal("Expected error when conn is nil, got nil")
|
|
}
|
|
|
|
if listener != nil {
|
|
t.Error("Expected listener to be nil when error occurs")
|
|
}
|
|
|
|
expectedErr := "poolCn cannot be nil"
|
|
if err.Error() != expectedErr {
|
|
t.Errorf("Expected error message %q, got %q", expectedErr, err.Error())
|
|
}
|
|
}
|
|
|
|
// Mock pooler for testing
|
|
type mockPooler struct{}
|
|
|
|
func (m *mockPooler) NewConn(ctx context.Context) (*pool.Conn, error) { return nil, nil }
|
|
func (m *mockPooler) CloseConn(*pool.Conn) error { return nil }
|
|
func (m *mockPooler) Get(ctx context.Context) (*pool.Conn, error) { return nil, nil }
|
|
func (m *mockPooler) Put(ctx context.Context, conn *pool.Conn) {}
|
|
func (m *mockPooler) Remove(ctx context.Context, conn *pool.Conn, reason error) {}
|
|
func (m *mockPooler) RemoveWithoutTurn(ctx context.Context, conn *pool.Conn, reason error) {}
|
|
func (m *mockPooler) Len() int { return 0 }
|
|
func (m *mockPooler) IdleLen() int { return 0 }
|
|
func (m *mockPooler) Stats() *pool.Stats { return &pool.Stats{} }
|
|
func (m *mockPooler) Size() int { return 10 }
|
|
func (m *mockPooler) AddPoolHook(hook pool.PoolHook) {}
|
|
func (m *mockPooler) RemovePoolHook(hook pool.PoolHook) {}
|
|
func (m *mockPooler) Close() error { return nil }
|