Skip to content

Commit

Permalink
refact(e2e): Add err to helper methods (#4581)
Browse files Browse the repository at this point in the history
* refact(e2e): Add err to CreateOrgApi

* refact(e2e): Add err to CreateProjectApi

* refact(e2e): Add err to CreateOrgCli

* refact(e2e): Add err to CreateProjectCli

* refact(e2e): Add err to CreateHostCatalogApi

* refact(e2e): Add err to CreateHostSetApi

* refact(e2e): Add err to CreateHostApi

* refact(e2e): Add err to AddHostToHostSetApi

* refact(e2e): Add err to CreateHostCatalogCli

* refact(e2e): Add err to CreateHostSetCli

* refact(e2e): Add err to CreateHostCli

* refact(e2e): Add err to AddHostToHostSetCli

* refact(e2e): Add err to CreateAwsHostCatalogCli

* refact(e2e): Add err to CreateAwsHostSetCli

* refact(e2e): Add err to CreateTargetApi

* refact(e2e): Add err to AddHostSourceToTargetApi

* refact(e2e): Add err to CreateTargetCli

* refact(e2e): Add err to AddHostSourceToTargetCli

* refact(e2e): Add err to SetHostSourceToTargetCli

* refact(e2e): Add err to RemoveHostSourceFromTargetCli

* refact(e2e): Add err to AddBrokeredCredentialSourceToTargetCli

* refact(e2e): Add err to RemoveBrokeredCredentialSourceFromTargetCli

* refact(e2e): Add err to CreateUserApi

* refact(e2e): Add err to CreateUserCli

* refact(e2e): Add err to SetAccountToUserCli

* refact(e2e): Add err to CreateRoleApi

* refact(e2e): Add err to CreateRoleCli

* refact(e2e): Add err to AddGrantToRoleCli

* refact(e2e): Add err to AddPrincipalToRoleCli

* refact(e2e): Add err to CreateManagedGroupApi

* refact(e2e): Add err to CreateGroupApi

* refact(e2e): Add err to CreateGroupCli

* refact(e2e): Add err to AddUserToGroup

* refact(e2e): Add err to CreateCredentialStoreStaticApi

* refact(e2e): Add err to CreateCredentialStoreVaultApi

* refact(e2e): Add err to CreateCredentialStoreVaultCli

* refact(e2e): Add err to CreateCredentialStoreStaticCli

* refact(e2e): Add err to CreateVaultGenericCredentialLibraryCli

* refact(e2e): Add err to CreateStaticCredentialPrivateKeyCli

* refact(e2e): Add err to CreateStaticCredentialPasswordCli

* refact(e2e): Add err to CreateStaticCredentialJsonCli

* refact(e2e): Add err to CreateStaticCredentialPasswordApi

* refact(e2e): Add err to CreateAuthMethodApi

* refact(e2e): Add err to CreateOidcAuthMethodApi

* refact(e2e): Add err to CreateAccountApi

* refact(e2e): Add err to CreateAccountCli
  • Loading branch information
moduli authored Apr 3, 2024
1 parent d4e314c commit 51d33f3
Show file tree
Hide file tree
Showing 64 changed files with 2,112 additions and 1,221 deletions.
54 changes: 37 additions & 17 deletions testing/internal/e2e/boundary/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package boundary
import (
"context"
"encoding/json"
"fmt"
"testing"

"github.com/hashicorp/boundary/api"
Expand All @@ -15,26 +16,41 @@ import (
"github.com/stretchr/testify/require"
)

// CreateNewAccountApi creates a new account using the Go api.
// CreateAccountApi creates a new account using the Go api.
// Returns the id of the new account as well as the password that was generated
func CreateNewAccountApi(t testing.TB, ctx context.Context, client *api.Client, authMethodId string, loginName string) (accountId string, password string) {
func CreateAccountApi(t testing.TB, ctx context.Context, client *api.Client, authMethodId string, loginName string) (string, string, error) {
name, err := base62.Random(16)
if err != nil {
return "", "", err
}

aClient := accounts.NewClient(client)
password, err := base62.Random(16)
require.NoError(t, err)
newAccountResult, err := aClient.Create(ctx, authMethodId,
if err != nil {
return "", "", err
}
createAccountResult, err := aClient.Create(ctx, authMethodId,
accounts.WithPasswordAccountLoginName(loginName),
accounts.WithPasswordAccountPassword(password),
accounts.WithName(fmt.Sprintf("e2e Account %s", name)),
)
require.NoError(t, err)
if err != nil {
return "", "", err
}

accountId = newAccountResult.Item.Id
accountId := createAccountResult.Item.Id
t.Logf("Create Account: %s", accountId)
return
return accountId, password, nil
}

// CreateNewAccountCli creates a new account using the cli.
// CreateAccountCli creates a new account using the cli.
// Returns the id of the new account as well as the password that was generated
func CreateNewAccountCli(t testing.TB, ctx context.Context, authMethodId string, loginName string) (string, string) {
func CreateAccountCli(t testing.TB, ctx context.Context, authMethodId string, loginName string) (string, string, error) {
name, err := base62.Random(16)
if err != nil {
return "", "", err
}

password, err := base62.Random(16)
require.NoError(t, err)
output := e2e.RunCommand(ctx, "boundary",
Expand All @@ -43,19 +59,23 @@ func CreateNewAccountCli(t testing.TB, ctx context.Context, authMethodId string,
"-auth-method-id", authMethodId,
"-login-name", loginName,
"-password", "env://E2E_TEST_ACCOUNT_PASSWORD",
"-name", "e2e Account "+loginName,
"-name", fmt.Sprintf("e2e Account %s", name),
"-description", "e2e",
"-format", "json",
),
e2e.WithEnv("E2E_TEST_ACCOUNT_PASSWORD", password),
)
require.NoError(t, output.Err, string(output.Stderr))
if output.Err != nil {
return "", "", fmt.Errorf("%w: %s", output.Err, string(output.Stderr))
}

var newAccountResult accounts.AccountCreateResult
err = json.Unmarshal(output.Stdout, &newAccountResult)
require.NoError(t, err)
var createAccountResult accounts.AccountCreateResult
err = json.Unmarshal(output.Stdout, &createAccountResult)
if err != nil {
return "", "", err
}

newAccountId := newAccountResult.Item.Id
t.Logf("Created Account: %s", newAccountId)
return newAccountId, password
accountId := createAccountResult.Item.Id
t.Logf("Created Account: %s", accountId)
return accountId, password, nil
}
42 changes: 31 additions & 11 deletions testing/internal/e2e/boundary/authmethod.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,57 @@ package boundary

import (
"context"
"fmt"
"testing"

"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/authmethods"
"github.com/stretchr/testify/require"
"github.com/hashicorp/go-secure-stdlib/base62"
)

// CreateNewAuthMethodApi creates a new password auth method using the Go api.
// CreateAuthMethodApi creates a new password auth method using the Go api.
// Returns the id of the new auth method
func CreateNewAuthMethodApi(t testing.TB, ctx context.Context, client *api.Client, scopeId string) string {
func CreateAuthMethodApi(t testing.TB, ctx context.Context, client *api.Client, scopeId string) (string, error) {
name, err := base62.Random(16)
if err != nil {
return "", err
}

aClient := authmethods.NewClient(client)
newAMResult, err := aClient.Create(ctx, "password", scopeId)
require.NoError(t, err)
createAuthMethodResult, err := aClient.Create(
ctx,
"password",
scopeId,
authmethods.WithName(fmt.Sprintf("e2e Auth Method %s", name)))
if err != nil {
return "", err
}

authMethodId := newAMResult.Item.Id
authMethodId := createAuthMethodResult.Item.Id
t.Logf("Created Auth Method: %s", authMethodId)
return authMethodId
return authMethodId, nil
}

// CreateNewOidcAuthMethodApi creates a new oidc auth method using the Go api.
// CreateOidcAuthMethodApi creates a new oidc auth method using the Go api.
// Returns the id of the new auth method
func CreateNewOidcAuthMethodApi(t testing.TB, ctx context.Context, client *api.Client, scopeId string) string {
func CreateOidcAuthMethodApi(t testing.TB, ctx context.Context, client *api.Client, scopeId string) (string, error) {
name, err := base62.Random(16)
if err != nil {
return "", err
}

aClient := authmethods.NewClient(client)
newAMResult, err := aClient.Create(ctx, "oidc", scopeId,
authmethods.WithOidcAuthMethodApiUrlPrefix("https://some_url_prefix"),
authmethods.WithOidcAuthMethodClientId("some_client_id"),
authmethods.WithOidcAuthMethodClientSecret("some_client_secret"),
authmethods.WithName(fmt.Sprintf("e2e Auth Method %s", name)),
)
require.NoError(t, err)
if err != nil {
return "", err
}

authMethodId := newAMResult.Item.Id
t.Logf("Created Auth Method: %s", authMethodId)
return authMethodId
return authMethodId, nil
}
Loading

0 comments on commit 51d33f3

Please sign in to comment.