Add multiple keys to client test

master
Bel LaPointe 2019-03-15 09:33:00 -06:00
parent c5b6ad08e4
commit b7771dee17
2 changed files with 14 additions and 7 deletions

View File

@ -4,6 +4,7 @@ import (
"bytes"
"errors"
"io/ioutil"
"log"
"net"
"net/http"
"strings"
@ -57,6 +58,7 @@ func New(addrs ...string) (*Client, error) {
func (c *Client) Get(key string) ([]byte, error) {
addr := c.hash.LocateKey([]byte(key)).String()
log.Printf("GET %s FROM %s", key, addr)
resp, err := http.Get(addr + "/" + key)
if err != nil {
return nil, err
@ -73,6 +75,7 @@ func (c *Client) Get(key string) ([]byte, error) {
func (c *Client) Set(key string, value []byte) error {
addr := c.hash.LocateKey([]byte(key)).String()
log.Printf("SET %s FROM %s", key, addr)
r, err := http.NewRequest("PUT", addr+"/"+key, bytes.NewBuffer(value))
if err != nil {
return err

View File

@ -1,6 +1,7 @@
package client
import (
"fmt"
"local/dynamodb/server/config"
"local/dynamodb/server/serve"
"net/http/httptest"
@ -27,14 +28,17 @@ func TestAll(t *testing.T) {
t.Fatalf("cannot make client: %v", err)
}
if err := client.Set(validKey, []byte(validValue)); err != nil {
t.Fatalf("cannot set with client: %v", err)
}
for i := 0; i < 5; i++ {
key := fmt.Sprintf("%s-%d", validKey, i)
if err := client.Set(key, []byte(validValue)); err != nil {
t.Fatalf("cannot set with client: %v", err)
}
if v, err := client.Get(validKey); err != nil {
t.Fatalf("cannot get with client: %v", err)
} else if string(v) != validValue {
t.Fatalf("wrong get with client: got %q, want %q", v, validValue)
if v, err := client.Get(key); err != nil {
t.Fatalf("cannot get with client: %v", err)
} else if string(v) != validValue {
t.Fatalf("wrong get with client: got %q, want %q", v, validValue)
}
}
}