2022-03-22 11:03:15 -04:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2022-06-30 09:24:36 -04:00
|
|
|
"go.uber.org/goleak"
|
2022-03-22 11:03:15 -04:00
|
|
|
)
|
|
|
|
|
2022-06-30 09:24:36 -04:00
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
goleak.VerifyTestMain(m,
|
|
|
|
// https://github.com/census-instrumentation/opencensus-go/issues/1262
|
|
|
|
goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-03-22 11:03:15 -04:00
|
|
|
func TestMemMapStorage(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
storage := NewMemMapStorage()
|
|
|
|
|
|
|
|
testDEK1 := []byte("test DEK")
|
|
|
|
testDEK2 := []byte("more test DEK")
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
// request unset value
|
|
|
|
_, err := storage.Get(ctx, "test:input")
|
2022-03-28 08:16:58 -04:00
|
|
|
assert.ErrorIs(err, ErrDEKUnset)
|
2022-03-22 11:03:15 -04:00
|
|
|
|
|
|
|
// test Put method
|
|
|
|
assert.NoError(storage.Put(ctx, "volume01", testDEK1))
|
|
|
|
assert.NoError(storage.Put(ctx, "volume02", testDEK2))
|
|
|
|
|
|
|
|
// make sure values have been set
|
|
|
|
val, err := storage.Get(ctx, "volume01")
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.Equal(testDEK1, val)
|
|
|
|
val, err = storage.Get(ctx, "volume02")
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.Equal(testDEK2, val)
|
|
|
|
|
|
|
|
_, err = storage.Get(ctx, "invalid:key")
|
2022-03-28 08:16:58 -04:00
|
|
|
assert.ErrorIs(err, ErrDEKUnset)
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|