mirror of
https://github.com/EchoVault/SugarDB.git
synced 2025-10-06 00:16:53 +08:00
Exported EchoVault interface now onlu contains the keyspace methods. All other methods are private. Private methods are accessed using the reflect package in the test folder
This commit is contained in:
@@ -19,16 +19,18 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/echovault/echovault/internal"
|
||||
"github.com/echovault/echovault/internal/clock"
|
||||
"github.com/echovault/echovault/internal/config"
|
||||
"github.com/echovault/echovault/pkg/constants"
|
||||
"github.com/echovault/echovault/pkg/echovault"
|
||||
"github.com/echovault/echovault/pkg/types"
|
||||
"github.com/tidwall/resp"
|
||||
"net"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var mockServer *echovault.EchoVault
|
||||
@@ -51,11 +53,17 @@ func init() {
|
||||
)
|
||||
}
|
||||
|
||||
func getHandler(commands ...string) types.HandlerFunc {
|
||||
func getUnexportedField(field reflect.Value) interface{} {
|
||||
return reflect.NewAt(field.Type(), unsafe.Pointer(field.UnsafeAddr())).Elem().Interface()
|
||||
}
|
||||
|
||||
func getHandler(commands ...string) internal.HandlerFunc {
|
||||
if len(commands) == 0 {
|
||||
return nil
|
||||
}
|
||||
for _, c := range mockServer.GetAllCommands() {
|
||||
getCommands :=
|
||||
getUnexportedField(reflect.ValueOf(mockServer).Elem().FieldByName("getCommands")).(func() []internal.Command)
|
||||
for _, c := range getCommands() {
|
||||
if strings.EqualFold(commands[0], c.Command) && len(commands) == 1 {
|
||||
// Get command handler
|
||||
return c.HandlerFunc
|
||||
@@ -72,8 +80,10 @@ func getHandler(commands ...string) types.HandlerFunc {
|
||||
return nil
|
||||
}
|
||||
|
||||
func getHandlerFuncParams(ctx context.Context, cmd []string, conn *net.Conn) types.HandlerFuncParams {
|
||||
return types.HandlerFuncParams{
|
||||
func getHandlerFuncParams(ctx context.Context, cmd []string, conn *net.Conn) internal.HandlerFuncParams {
|
||||
getClock :=
|
||||
getUnexportedField(reflect.ValueOf(mockServer).Elem().FieldByName("getClock")).(func() clock.Clock)
|
||||
return internal.HandlerFuncParams{
|
||||
Context: ctx,
|
||||
Command: cmd,
|
||||
Connection: conn,
|
||||
@@ -85,10 +95,10 @@ func getHandlerFuncParams(ctx context.Context, cmd []string, conn *net.Conn) typ
|
||||
KeyRUnlock: mockServer.KeyRUnlock,
|
||||
GetValue: mockServer.GetValue,
|
||||
SetValue: mockServer.SetValue,
|
||||
GetClock: mockServer.GetClock,
|
||||
GetExpiry: mockServer.GetExpiry,
|
||||
SetExpiry: mockServer.SetExpiry,
|
||||
DeleteKey: mockServer.DeleteKey,
|
||||
GetClock: getClock,
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user