func TestClient(t *testing.T) { server, client := redistest.NewServerClient(t) defer server.Close() if _, err := client.Call("SET", "foo", "foo"); err != nil { t.Fatal(err.Error()) } }
func TestDeadClient(t *testing.T) { server, client := redistest.NewServerClient(t) server.Close() store := bytestore.New(client) const key = "key" _, err := store.Get(key) if err == nil { t.Fatal("was expecting error") } }
func TestTimeout(t *testing.T) { server, client := redistest.NewServerClient(t) defer server.Close() client.Timeout = time.Nanosecond _, err := client.Call("SET", "foo", "foo") if err == nil { t.Fatal("was expecting timeout error but got no error. redis too fast?") } if !strings.HasSuffix(err.Error(), "i/o timeout") { t.Fatalf("was expecting timeout error but got: %s", err) } }
func BenchmarkSet(b *testing.B) { b.StopTimer() server, client := redistest.NewServerClient(b) b.StartTimer() defer func() { b.StopTimer() server.Close() b.StartTimer() }() for i := 0; i < b.N; i++ { client.Call("SET", "foo", "foo") } }
func TestGetMissing(t *testing.T) { server, client := redistest.NewServerClient(t) defer server.Close() store := bytestore.New(client) const key = "key" actual, err := store.Get(key) if err != nil { t.Fatal(err) } if actual != nil { t.Fatalf("found %s instead of nil", actual) } }
func TestSetGet(t *testing.T) { server, client := redistest.NewServerClient(t) defer server.Close() store := bytestore.New(client) const key = "key" expected := []byte("data") if err := store.Store(key, expected); err != nil { t.Fatal(err) } actual, err := store.Get(key) if err != nil { t.Fatal(err) } if !bytes.Equal(actual, expected) { t.Fatalf("found %s instead of %s", actual, expected) } }
func TestExpires(t *testing.T) { server, client := redistest.NewServerClient(t) defer server.Close() cache := bytecache.New(client) const key = "key" expected := []byte("data") if err := cache.Store(key, expected, time.Millisecond); err != nil { t.Fatal(err) } time.Sleep(3 * time.Millisecond) actual, err := cache.Get(key) if err != nil { t.Fatal(err) } if actual != nil { t.Fatalf("found %s instead of nil", actual) } }