Exemple #1
0
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())
	}
}
Exemple #2
0
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")
	}
}
Exemple #3
0
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)
	}
}
Exemple #4
0
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")
	}
}
Exemple #5
0
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)
	}
}
Exemple #6
0
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)
	}
}
Exemple #7
0
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)
	}
}