2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-06-29 21:06:25 +01:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package redis
|
|
|
|
|
|
|
|
import (
|
2020-10-29 11:58:36 +00:00
|
|
|
"context"
|
2018-06-29 21:06:25 +01:00
|
|
|
"testing"
|
|
|
|
|
2020-01-31 18:28:42 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2020-10-29 11:58:36 +00:00
|
|
|
"storj.io/common/testcontext"
|
2023-04-06 14:54:41 +01:00
|
|
|
"storj.io/storj/private/kvstore/testsuite"
|
2021-03-09 17:42:10 +00:00
|
|
|
"storj.io/storj/private/testredis"
|
2018-06-29 21:06:25 +01:00
|
|
|
)
|
|
|
|
|
2018-09-05 17:10:35 +01:00
|
|
|
func TestSuite(t *testing.T) {
|
2020-10-29 11:58:36 +00:00
|
|
|
ctx := testcontext.New(t)
|
|
|
|
defer ctx.Cleanup()
|
|
|
|
|
2021-03-09 17:42:10 +00:00
|
|
|
redis, err := testredis.Start(ctx)
|
2018-06-29 21:06:25 +01:00
|
|
|
if err != nil {
|
2018-09-05 17:10:35 +01:00
|
|
|
t.Fatal(err)
|
2018-06-29 21:06:25 +01:00
|
|
|
}
|
2020-01-31 18:28:42 +00:00
|
|
|
defer func() { require.NoError(t, redis.Close()) }()
|
2018-06-29 21:06:25 +01:00
|
|
|
|
2021-03-24 19:22:50 +00:00
|
|
|
client, err := OpenClient(ctx, redis.Addr(), "", 1)
|
2018-06-29 21:06:25 +01:00
|
|
|
if err != nil {
|
2018-09-05 17:10:35 +01:00
|
|
|
t.Fatal(err)
|
2018-07-31 16:23:55 +01:00
|
|
|
}
|
|
|
|
|
2018-09-05 17:10:35 +01:00
|
|
|
testsuite.RunTests(t, client)
|
2018-07-31 16:23:55 +01:00
|
|
|
}
|
|
|
|
|
2018-09-05 17:10:35 +01:00
|
|
|
func TestInvalidConnection(t *testing.T) {
|
2021-03-24 19:22:50 +00:00
|
|
|
_, err := OpenClient(context.Background(), "", "", 1)
|
2018-09-05 17:10:35 +01:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("expected connection error")
|
2018-07-31 16:23:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-05 17:10:35 +01:00
|
|
|
func BenchmarkSuite(b *testing.B) {
|
2020-10-29 11:58:36 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
|
2021-03-09 17:42:10 +00:00
|
|
|
redis, err := testredis.Start(ctx)
|
2018-07-31 16:23:55 +01:00
|
|
|
if err != nil {
|
2018-09-05 17:10:35 +01:00
|
|
|
b.Fatal(err)
|
2018-07-31 16:23:55 +01:00
|
|
|
}
|
2020-01-31 18:28:42 +00:00
|
|
|
defer func() { require.NoError(b, redis.Close()) }()
|
2018-07-31 16:23:55 +01:00
|
|
|
|
2021-03-24 19:22:50 +00:00
|
|
|
client, err := OpenClient(ctx, redis.Addr(), "", 1)
|
2018-07-31 16:23:55 +01:00
|
|
|
if err != nil {
|
2018-09-05 17:10:35 +01:00
|
|
|
b.Fatal(err)
|
2018-07-31 16:23:55 +01:00
|
|
|
}
|
2018-09-05 17:10:35 +01:00
|
|
|
testsuite.RunBenchmarks(b, client)
|
2018-07-31 16:23:55 +01:00
|
|
|
}
|