Files
threshold/testing/internal/e2e/boundary/scope.go
T

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

82 lines
2.5 KiB
Go
Raw Normal View History

2022-09-16 11:45:55 -04:00
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"
)
2022-10-25 09:59:03 -04:00
// CreateNewOrgApi creates a new organization in boundary using the Go api.
2022-09-16 11:45:55 -04:00
// 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"))
2022-09-16 11:45:55 -04:00
require.NoError(t, err)
newOrgId := newOrgResult.Item.Id
t.Logf("Created Org Id: %s", newOrgId)
return newOrgId
2022-09-16 11:45:55 -04:00
}
2022-10-25 09:59:03 -04:00
// CreateNewProjectApi creates a new project in boundary using the Go api. The project will be created
// under the provided org id.
2022-09-16 11:45:55 -04:00
// 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
2022-09-16 11:45:55 -04:00
}
// 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",
),
)
2022-09-16 11:45:55 -04:00
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
2022-09-16 11:45:55 -04:00
}
// 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
}