* refact: Changes required for gorm v2 * refact: Add db.DB wrapper and refact all test fixtures to use it Stop leaking the gorm abstraction within our unit tests. * refact: Migrate direct calls to pq to pgx driver The refactor will remove the remaining direct dependencies on the pq driver which has been deprecated in favor of the pgx driver. It includes the addition of common.SqlOpen which is a wrapper around sql.Open, which is needed to deal with the driver name changing from "postgres" to "pgx" but in our code base the dialect and driver are synonyms.
35 lines
1.0 KiB
Go
35 lines
1.0 KiB
Go
package authtoken
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/boundary/internal/auth/password"
|
|
"github.com/hashicorp/boundary/internal/db"
|
|
"github.com/hashicorp/boundary/internal/iam"
|
|
"github.com/hashicorp/boundary/internal/kms"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestAuthToken(t *testing.T, conn *db.DB, kms *kms.Kms, scopeId string, opt ...Option) *AuthToken {
|
|
t.Helper()
|
|
authMethod := password.TestAuthMethods(t, conn, scopeId, 1)[0]
|
|
// auth account is only used to join auth method to user.
|
|
// We don't do anything else with the auth account in the test setup.
|
|
acct := password.TestAccount(t, conn, authMethod.GetPublicId(), "name1")
|
|
|
|
ctx := context.Background()
|
|
rw := db.New(conn)
|
|
iamRepo, err := iam.NewRepository(rw, rw, kms)
|
|
require.NoError(t, err)
|
|
|
|
u := iam.TestUser(t, iamRepo, scopeId, iam.WithAccountIds(acct.PublicId))
|
|
|
|
repo, err := NewRepository(rw, rw, kms)
|
|
require.NoError(t, err)
|
|
|
|
at, err := repo.CreateAuthToken(ctx, u, acct.GetPublicId(), opt...)
|
|
require.NoError(t, err)
|
|
return at
|
|
}
|