Skip to content

Commit

Permalink
Adds test client
Browse files Browse the repository at this point in the history
  • Loading branch information
brotherlogic committed Jun 26, 2023
1 parent f266995 commit 697d51d
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions client/testclient.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package rstore_client

import (
"context"
"strings"

pb "github.com/brotherlogic/rstore/proto"
"google.golang.org/protobuf/types/known/anypb"
)

type TestClient struct {
mapper map[string][]byte
}

func (c *TestClient) Read(ctx context.Context, req *pb.ReadRequest) (*pb.ReadResponse, error) {
return &pb.ReadResponse{Value: &anypb.Any{Value: c.mapper[req.GetKey()]}}, nil
}

func (c *TestClient) Write(ctx context.Context, req *pb.WriteRequest) (*pb.WriteResponse, error) {
c.mapper[req.Key] = req.GetValue().Value
return &pb.WriteResponse{}, nil
}

func (c *TestClient) GetKeys(ctx context.Context, req *pb.GetKeysRequest) (*pb.GetKeysResponse, error) {
var keys []string
for key := range c.mapper {
if strings.HasPrefix(key, req.GetPrefix()) {
keys = append(keys, key)
}
}
return &pb.GetKeysResponse{Keys: keys}, nil
}

func (c *TestClient) Delete(ctx context.Context, req *pb.DeleteRequest) (*pb.DeleteResponse, error) {
delete(c.mapper, req.GetKey())
return &pb.DeleteResponse{}, nil
}

0 comments on commit 697d51d

Please sign in to comment.