2022-09-05 03:06:08 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2023-03-02 09:08:31 -05:00
|
|
|
package memfs
|
2022-03-22 11:03:15 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
2023-03-02 09:08:31 -05:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/kms/storage"
|
2022-03-22 11:03:15 -04:00
|
|
|
"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)
|
|
|
|
|
2023-03-02 09:08:31 -05:00
|
|
|
store := New()
|
2022-03-22 11:03:15 -04:00
|
|
|
|
|
|
|
testDEK1 := []byte("test DEK")
|
|
|
|
testDEK2 := []byte("more test DEK")
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
// request unset value
|
2023-03-02 09:08:31 -05:00
|
|
|
_, err := store.Get(ctx, "test:input")
|
|
|
|
assert.ErrorIs(err, storage.ErrDEKUnset)
|
2022-03-22 11:03:15 -04:00
|
|
|
|
|
|
|
// test Put method
|
2023-03-02 09:08:31 -05:00
|
|
|
assert.NoError(store.Put(ctx, "volume01", testDEK1))
|
|
|
|
assert.NoError(store.Put(ctx, "volume02", testDEK2))
|
2022-03-22 11:03:15 -04:00
|
|
|
|
|
|
|
// make sure values have been set
|
2023-03-02 09:08:31 -05:00
|
|
|
val, err := store.Get(ctx, "volume01")
|
2022-03-22 11:03:15 -04:00
|
|
|
assert.NoError(err)
|
|
|
|
assert.Equal(testDEK1, val)
|
2023-03-02 09:08:31 -05:00
|
|
|
val, err = store.Get(ctx, "volume02")
|
2022-03-22 11:03:15 -04:00
|
|
|
assert.NoError(err)
|
|
|
|
assert.Equal(testDEK2, val)
|
|
|
|
|
2023-03-02 09:08:31 -05:00
|
|
|
_, err = store.Get(ctx, "invalid:key")
|
|
|
|
assert.ErrorIs(err, storage.ErrDEKUnset)
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|