Files
threshold/testing/internal/e2e/boundary/user.go
T
Michael LiandJohan Brandhorst-Satzkorn 45171a3f56 refact(e2e): Changes to support an automated migration test (#2676)
* refact(e2e): Move cleanup steps into each test

The migration test needed to create some resources, but doesn't care about cleaning up because the test would take care of spinning down the docker container that it's using. To maintain flexibility going forward, we'll establish that tests are responsible for cleaning up (rather than the methods they use)

* refact(e2e): Use new env var for skip check

Currently, the e2e tests use the E2E_PASSWORD_AUTH_METHOD_ID environment variable to determine if the test should be skipped. However, the new migration test does not require a pre-existing boundary cluster and would not have this environment variable. As a result, we needed an alternative way to check if an e2e test should be skipped when running tests in ci.

* refact(e2e): Create more common boundary methods

* fix(e2e): Set to string value

Co-authored-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
2022-12-06 15:59:17 -05:00

60 lines
1.6 KiB
Go

package boundary
import (
"context"
"encoding/json"
"testing"
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/users"
"github.com/hashicorp/boundary/testing/internal/e2e"
"github.com/stretchr/testify/require"
)
// CreateNewUserCli creates a new user using the Go api.
// Returns the id of the new user
func CreateNewUserApi(t testing.TB, ctx context.Context, client *api.Client, scopeId string) string {
uClient := users.NewClient(client)
newUserResult, err := uClient.Create(ctx, scopeId)
require.NoError(t, err)
newUserId := newUserResult.Item.Id
t.Logf("Created User: %s", newUserId)
return newUserId
}
// CreateNewUserCli creates a new user using the cli.
// Returns the id of the new user
func CreateNewUserCli(t testing.TB, ctx context.Context, scopeId string) string {
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"users", "create",
"-scope-id", scopeId,
"-name", "e2e User",
"-description", "e2e User",
"-format", "json",
),
)
require.NoError(t, output.Err, string(output.Stderr))
var newUserResult users.UserCreateResult
err := json.Unmarshal(output.Stdout, &newUserResult)
require.NoError(t, err)
newUserId := newUserResult.Item.Id
t.Logf("Created User: %s", newUserId)
return newUserId
}
// SetAccountToUserCli sets an account to a the specified user using the cli.
func SetAccountToUserCli(t testing.TB, ctx context.Context, userId string, accountId string) {
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"users", "set-accounts",
"-id", userId,
"-account", accountId,
),
)
require.NoError(t, output.Err, string(output.Stderr))
}