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

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

86 lines
2.7 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"
)
// 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 Automated Test Org"))
require.NoError(t, err)
t.Cleanup(func() {
_, err := scopeClient.Delete(ctx, newOrgResult.Item.Id)
require.NoError(t, err)
})
return newOrgResult.Item.Id
}
// 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 Automated Test Project"))
require.NoError(t, err)
t.Cleanup(func() {
_, err := scopeClient.Delete(ctx, newProjResult.Item.Id)
require.NoError(t, err)
})
return newProjResult.Item.Id
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) string {
output := e2e.RunCommand("boundary", "scopes", "create",
"-name", "e2e Automated Test Org",
"-scope-id", "global",
2022-09-16 11:45:55 -04:00
"-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)
t.Cleanup(func() {
output := e2e.RunCommand("boundary", "scopes", "delete", "-id", newOrgResult.Item.Id)
2022-09-16 11:45:55 -04:00
require.NoError(t, output.Err, string(output.Stderr))
})
return newOrgResult.Item.Id
}
// 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, orgId string) string {
output := e2e.RunCommand("boundary", "scopes", "create",
"-name", "e2e Automated Test 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)
t.Cleanup(func() {
output := e2e.RunCommand("boundary", "scopes", "delete", "-id", newProjResult.Item.Id)
require.NoError(t, output.Err, string(output.Stderr))
})
return newProjResult.Item.Id
}