Files
threshold/internal/kms/testing.go
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

39 lines
1.2 KiB
Go
Raw Normal View History

2020-08-19 16:47:18 -04:00
package kms
import (
"context"
"fmt"
2020-08-19 16:47:18 -04:00
"testing"
"github.com/hashicorp/boundary/internal/db"
wrapping "github.com/hashicorp/go-kms-wrapping/v2"
2020-08-19 16:47:18 -04:00
"github.com/stretchr/testify/require"
)
// TestKms creates a kms for testing.
func TestKms(t testing.TB, conn *db.DB, rootWrapper wrapping.Wrapper) *Kms {
2020-08-19 16:47:18 -04:00
t.Helper()
require := require.New(t)
rw := db.New(conn)
kms, err := New(context.Background(), rw, rw)
2020-08-19 16:47:18 -04:00
require.NoError(err)
err = kms.AddExternalWrappers(context.Background(), WithRootWrapper(rootWrapper))
2020-08-19 16:47:18 -04:00
require.NoError(err)
_, err = kms.underlying.GetExternalRootWrapper()
require.NoError(err)
return kms
}
// TestKmsDeleteKeyPurpose allows you to delete a KeyPurpose for testing.
func TestKmsDeleteKeyPurpose(t testing.TB, conn *db.DB, purpose KeyPurpose) {
db.TestDeleteWhere(t, conn, func() interface{} { i := dataKey{}; return &i }(), fmt.Sprintf("purpose='%s'", purpose.String()))
}
// TestKmsDeleteAllKeys allows you to delete all the keys for testing.
func TestKmsDeleteAllKeys(t testing.TB, conn *db.DB) {
db.TestDeleteWhere(t, conn, func() interface{} { i := rootKey{}; return &i }(), "1=1")
}
type dataKey struct{}
func (*dataKey) TableName() string { return "kms_data_key" }