chore(dynamodb): use require in tests

This commit is contained in:
Manuel de la Peña
2025-04-15 16:17:17 +02:00
parent c2122f7e4a
commit c38280d308

View File

@@ -16,7 +16,7 @@ const (
dynamoDBImageEnvVar string = "TEST_DYNAMODB_IMAGE"
)
func newTestStore(t testing.TB) (*Storage, error) {
func newTestStore(t testing.TB) *Storage {
t.Helper()
img := dynamoDBImage
@@ -28,14 +28,10 @@ func newTestStore(t testing.TB) (*Storage, error) {
c, err := dynamodb.Run(ctx, img, dynamodb.WithDisableTelemetry())
testcontainers.CleanupContainer(t, c)
if err != nil {
return nil, err
}
require.NoError(t, err)
hostPort, err := c.ConnectionString(ctx)
if err != nil {
return nil, err
}
require.NoError(t, err)
return New(
Config{
@@ -48,7 +44,7 @@ func newTestStore(t testing.TB) (*Storage, error) {
},
Reset: true,
},
), nil
)
}
func Test_DynamoDB_Set(t *testing.T) {
@@ -57,11 +53,10 @@ func Test_DynamoDB_Set(t *testing.T) {
val = []byte("doe")
)
testStore, err := newTestStore(t)
require.NoError(t, err)
testStore := newTestStore(t)
defer testStore.Close()
err = testStore.Set(key, val, 0)
err := testStore.Set(key, val, 0)
require.NoError(t, err)
}
@@ -71,11 +66,10 @@ func Test_DynamoDB_Set_Override(t *testing.T) {
val = []byte("doe")
)
testStore, err := newTestStore(t)
require.NoError(t, err)
testStore := newTestStore(t)
defer testStore.Close()
err = testStore.Set(key, val, 0)
err := testStore.Set(key, val, 0)
require.NoError(t, err)
err = testStore.Set(key, val, 0)
@@ -88,11 +82,10 @@ func Test_DynamoDB_Get(t *testing.T) {
val = []byte("doe")
)
testStore, err := newTestStore(t)
require.NoError(t, err)
testStore := newTestStore(t)
defer testStore.Close()
err = testStore.Set(key, val, 0)
err := testStore.Set(key, val, 0)
require.NoError(t, err)
result, err := testStore.Get(key)
@@ -101,8 +94,7 @@ func Test_DynamoDB_Get(t *testing.T) {
}
func Test_DynamoDB_Get_NotExist(t *testing.T) {
testStore, err := newTestStore(t)
require.NoError(t, err)
testStore := newTestStore(t)
defer testStore.Close()
result, err := testStore.Get("notexist")
@@ -116,11 +108,10 @@ func Test_DynamoDB_Delete(t *testing.T) {
val = []byte("doe")
)
testStore, err := newTestStore(t)
require.NoError(t, err)
testStore := newTestStore(t)
defer testStore.Close()
err = testStore.Set(key, val, 0)
err := testStore.Set(key, val, 0)
require.NoError(t, err)
err = testStore.Delete(key)
@@ -134,11 +125,10 @@ func Test_DynamoDB_Delete(t *testing.T) {
func Test_DynamoDB_Reset(t *testing.T) {
val := []byte("doe")
testStore, err := newTestStore(t)
require.NoError(t, err)
testStore := newTestStore(t)
defer testStore.Close()
err = testStore.Set("john1", val, 0)
err := testStore.Set("john1", val, 0)
require.NoError(t, err)
err = testStore.Set("john2", val, 0)
@@ -157,28 +147,25 @@ func Test_DynamoDB_Reset(t *testing.T) {
}
func Test_DynamoDB_Close(t *testing.T) {
testStore, err := newTestStore(t)
require.NoError(t, err)
testStore := newTestStore(t)
require.Nil(t, testStore.Close())
}
func Test_DynamoDB_Conn(t *testing.T) {
testStore, err := newTestStore(t)
require.NoError(t, err)
testStore := newTestStore(t)
defer testStore.Close()
require.True(t, testStore.Conn() != nil)
}
func Benchmark_DynamoDB_Set(b *testing.B) {
testStore := newTestStore(b)
defer testStore.Close()
b.ReportAllocs()
b.ResetTimer()
testStore, err := newTestStore(b)
require.NoError(b, err)
defer testStore.Close()
var err error
for i := 0; i < b.N; i++ {
err = testStore.Set("john", []byte("doe"), 0)
}
@@ -187,11 +174,10 @@ func Benchmark_DynamoDB_Set(b *testing.B) {
}
func Benchmark_DynamoDB_Get(b *testing.B) {
testStore, err := newTestStore(b)
require.NoError(b, err)
testStore := newTestStore(b)
defer testStore.Close()
err = testStore.Set("john", []byte("doe"), 0)
err := testStore.Set("john", []byte("doe"), 0)
require.NoError(b, err)
b.ReportAllocs()
@@ -205,13 +191,13 @@ func Benchmark_DynamoDB_Get(b *testing.B) {
}
func Benchmark_DynamoDB_SetAndDelete(b *testing.B) {
testStore := newTestStore(b)
defer testStore.Close()
b.ReportAllocs()
b.ResetTimer()
testStore, err := newTestStore(b)
require.NoError(b, err)
defer testStore.Close()
var err error
for i := 0; i < b.N; i++ {
_ = testStore.Set("john", []byte("doe"), 0)
err = testStore.Delete("john")