Files
threshold/testing/internal/e2e/boundary/scope.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

83 lines
2.5 KiB
Go

package boundary
import (
"context"
"encoding/json"
"testing"
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/scopes"
"github.com/hashicorp/boundary/testing/internal/e2e"
"github.com/stretchr/testify/require"
)
// CreateNewOrgApi creates a new organization in boundary using the Go api.
// Returns the id of the new org.
func CreateNewOrgApi(t testing.TB, ctx context.Context, client *api.Client) string {
scopeClient := scopes.NewClient(client)
newOrgResult, err := scopeClient.Create(ctx, "global", scopes.WithName("e2e Org"))
require.NoError(t, err)
newOrgId := newOrgResult.Item.Id
t.Logf("Created Org Id: %s", newOrgId)
return newOrgId
}
// CreateNewProjectApi creates a new project in boundary using the Go api. The project will be created
// under the provided org id.
// Returns the id of the new project.
func CreateNewProjectApi(t testing.TB, ctx context.Context, client *api.Client, orgId string) string {
scopeClient := scopes.NewClient(client)
newProjResult, err := scopeClient.Create(ctx, orgId, scopes.WithName("e2e Project"))
require.NoError(t, err)
newProjectId := newProjResult.Item.Id
t.Logf("Created Project Id: %s", newProjectId)
return newProjectId
}
// CreateNewOrgCli creates a new organization in boundary using the cli.
// Returns the id of the new org.
func CreateNewOrgCli(t testing.TB, ctx context.Context) string {
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"scopes", "create",
"-name", "e2e Org",
"-scope-id", "global",
"-format", "json",
),
)
require.NoError(t, output.Err, string(output.Stderr))
var newOrgResult scopes.ScopeCreateResult
err := json.Unmarshal(output.Stdout, &newOrgResult)
require.NoError(t, err)
newOrgId := newOrgResult.Item.Id
t.Logf("Created Org Id: %s", newOrgId)
return newOrgId
}
// CreateNewProjectCli creates a new project in boundary using the cli. The project will be created
// under the provided org id.
// Returns the id of the new project.
func CreateNewProjectCli(t testing.TB, ctx context.Context, orgId string) string {
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"scopes", "create",
"-name", "e2e Project",
"-scope-id", orgId,
"-format", "json",
),
)
require.NoError(t, output.Err, string(output.Stderr))
var newProjResult scopes.ScopeCreateResult
err := json.Unmarshal(output.Stdout, &newProjResult)
require.NoError(t, err)
newProjectId := newProjResult.Item.Id
t.Logf("Created Project Id: %s", newProjectId)
return newProjectId
}