Files
threshold/internal/target/testing.go
T
Johan Brandhorst-Satzkorn 7f9b294a7e refact(all): Use testing.TB for test helpers
Our test helper packages were not possible to use
with benchmarks. This refactor switches to testing.TB
to allow both tests and benchmarks to use the helpers.
2022-04-29 16:33:44 -04:00

37 lines
1.2 KiB
Go

package target
import (
"context"
"testing"
"github.com/hashicorp/boundary/internal/credential"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/target/store"
"github.com/stretchr/testify/require"
)
// TestNewCredentialLibrary creates a new in memory CredentialLibrary
// representing the relationship between targetId and credentialLibraryId with
// the given purpose.
func TestNewCredentialLibrary(targetId, credentialLibraryId string, purpose credential.Purpose) *CredentialLibrary {
return &CredentialLibrary{
CredentialLibrary: &store.CredentialLibrary{
TargetId: targetId,
CredentialLibraryId: credentialLibraryId,
CredentialPurpose: string(purpose),
},
}
}
// TestCredentialLibrary creates a CredentialLibrary for targetId and
// libraryId with the credential purpose of application.
func TestCredentialLibrary(t testing.TB, conn *db.DB, targetId, libraryId string) *CredentialLibrary {
t.Helper()
require := require.New(t)
rw := db.New(conn)
lib := TestNewCredentialLibrary(targetId, libraryId, credential.ApplicationPurpose)
err := rw.Create(context.Background(), lib)
require.NoError(err)
return lib
}