diff --git a/testing/internal/e2e/boundary/target.go b/testing/internal/e2e/boundary/target.go index 8a87ef5d91..87056cc81f 100644 --- a/testing/internal/e2e/boundary/target.go +++ b/testing/internal/e2e/boundary/target.go @@ -7,7 +7,6 @@ import ( "context" "encoding/json" "fmt" - "strconv" "testing" "github.com/hashicorp/boundary/api" @@ -17,24 +16,18 @@ import ( "github.com/hashicorp/go-secure-stdlib/base62" ) -// CreateTargetApi uses the Go api to create a new target in boundary +// CreateTargetApi uses the Go API to create a new target of the provided type +// in Boundary. Automatically sets a random target name. // Returns the id of the new target. -func CreateTargetApi(t testing.TB, ctx context.Context, client *api.Client, projectId string, defaultPort string) (string, error) { +func CreateTargetApi(t testing.TB, ctx context.Context, client *api.Client, projectId, targetType string, opts ...targets.Option) (string, error) { name, err := base62.Random(16) if err != nil { return "", err } + opts = append(opts, targets.WithName(fmt.Sprintf("e2e Target %s", name))) tClient := targets.NewClient(client) - targetPort, err := strconv.ParseInt(defaultPort, 10, 32) - if err != nil { - return "", err - } - - newTargetResult, err := tClient.Create(ctx, "tcp", projectId, - targets.WithName(fmt.Sprintf("e2e Target %s", name)), - targets.WithTcpTargetDefaultPort(uint32(targetPort)), - ) + newTargetResult, err := tClient.Create(ctx, targetType, projectId, opts...) if err != nil { return "", err } diff --git a/testing/internal/e2e/tests/base/credential_store_test.go b/testing/internal/e2e/tests/base/credential_store_test.go index caecd86fbb..70cf4fec8c 100644 --- a/testing/internal/e2e/tests/base/credential_store_test.go +++ b/testing/internal/e2e/tests/base/credential_store_test.go @@ -12,6 +12,7 @@ import ( "encoding/pem" "fmt" "os" + "strconv" "strings" "testing" "time" @@ -203,6 +204,9 @@ func TestApiStaticCredentialStore(t *testing.T) { require.NoError(t, err) ctx := context.Background() + targetPort, err := strconv.ParseUint(c.TargetPort, 10, 32) + require.NoError(t, err) + orgId, err := boundary.CreateOrgApi(t, ctx, client) require.NoError(t, err) t.Cleanup(func() { @@ -220,7 +224,7 @@ func TestApiStaticCredentialStore(t *testing.T) { require.NoError(t, err) err = boundary.AddHostToHostSetApi(t, ctx, client, hostSetId, hostId) require.NoError(t, err) - targetId, err := boundary.CreateTargetApi(t, ctx, client, projectId, c.TargetPort) + targetId, err := boundary.CreateTargetApi(t, ctx, client, projectId, "tcp", targets.WithTcpTargetDefaultPort(uint32(targetPort))) require.NoError(t, err) err = boundary.AddHostSourceToTargetApi(t, ctx, client, targetId, hostSetId) require.NoError(t, err) diff --git a/testing/internal/e2e/tests/base/paginate_session_test.go b/testing/internal/e2e/tests/base/paginate_session_test.go index a97922a53b..c56fe61fff 100644 --- a/testing/internal/e2e/tests/base/paginate_session_test.go +++ b/testing/internal/e2e/tests/base/paginate_session_test.go @@ -6,6 +6,7 @@ package base_test import ( "context" "encoding/json" + "strconv" "testing" "github.com/hashicorp/boundary/api/scopes" @@ -124,6 +125,9 @@ func TestApiPaginateSessions(t *testing.T) { require.NoError(t, err) }) + targetPort, err := strconv.ParseUint(c.TargetPort, 10, 32) + require.NoError(t, err) + projectId, err := boundary.CreateProjectApi(t, ctx, client, orgId) require.NoError(t, err) hostCatalogId, err := boundary.CreateHostCatalogApi(t, ctx, client, projectId) @@ -134,7 +138,7 @@ func TestApiPaginateSessions(t *testing.T) { require.NoError(t, err) err = boundary.AddHostToHostSetApi(t, ctx, client, hostSetId, hostId) require.NoError(t, err) - targetId, err := boundary.CreateTargetApi(t, ctx, client, projectId, c.TargetPort) + targetId, err := boundary.CreateTargetApi(t, ctx, client, projectId, "tcp", targets.WithTcpTargetDefaultPort(uint32(targetPort))) require.NoError(t, err) err = boundary.AddHostSourceToTargetApi(t, ctx, client, targetId, hostSetId) require.NoError(t, err) diff --git a/testing/internal/e2e/tests/base/session_cancel_group_test.go b/testing/internal/e2e/tests/base/session_cancel_group_test.go index 1986570162..b00ab305f1 100644 --- a/testing/internal/e2e/tests/base/session_cancel_group_test.go +++ b/testing/internal/e2e/tests/base/session_cancel_group_test.go @@ -7,6 +7,7 @@ import ( "context" "encoding/json" "net/http" + "strconv" "testing" "time" @@ -14,6 +15,7 @@ import ( "github.com/hashicorp/boundary/api/groups" "github.com/hashicorp/boundary/api/roles" "github.com/hashicorp/boundary/api/scopes" + "github.com/hashicorp/boundary/api/targets" "github.com/hashicorp/boundary/api/users" "github.com/hashicorp/boundary/internal/session" "github.com/hashicorp/boundary/testing/internal/e2e" @@ -180,6 +182,9 @@ func TestApiCreateGroup(t *testing.T) { require.NoError(t, err) ctx := context.Background() + targetPort, err := strconv.ParseUint(c.TargetPort, 10, 32) + require.NoError(t, err) + orgId, err := boundary.CreateOrgApi(t, ctx, client) require.NoError(t, err) t.Cleanup(func() { @@ -197,7 +202,7 @@ func TestApiCreateGroup(t *testing.T) { require.NoError(t, err) err = boundary.AddHostToHostSetApi(t, ctx, client, hostSetId, hostId) require.NoError(t, err) - targetId, err := boundary.CreateTargetApi(t, ctx, client, projectId, c.TargetPort) + targetId, err := boundary.CreateTargetApi(t, ctx, client, projectId, "tcp", targets.WithTcpTargetDefaultPort(uint32(targetPort))) require.NoError(t, err) err = boundary.AddHostSourceToTargetApi(t, ctx, client, targetId, hostSetId) require.NoError(t, err) diff --git a/testing/internal/e2e/tests/base/session_cancel_user_test.go b/testing/internal/e2e/tests/base/session_cancel_user_test.go index 880f61e299..e8e72d9780 100644 --- a/testing/internal/e2e/tests/base/session_cancel_user_test.go +++ b/testing/internal/e2e/tests/base/session_cancel_user_test.go @@ -7,12 +7,14 @@ import ( "context" "encoding/json" "net/http" + "strconv" "testing" "time" "github.com/hashicorp/boundary/api/accounts" "github.com/hashicorp/boundary/api/roles" "github.com/hashicorp/boundary/api/scopes" + "github.com/hashicorp/boundary/api/targets" "github.com/hashicorp/boundary/api/users" "github.com/hashicorp/boundary/internal/session" "github.com/hashicorp/boundary/testing/internal/e2e" @@ -173,6 +175,9 @@ func TestApiCreateUser(t *testing.T) { require.NoError(t, err) ctx := context.Background() + targetPort, err := strconv.ParseUint(c.TargetPort, 10, 32) + require.NoError(t, err) + orgId, err := boundary.CreateOrgApi(t, ctx, client) require.NoError(t, err) t.Cleanup(func() { @@ -190,7 +195,7 @@ func TestApiCreateUser(t *testing.T) { require.NoError(t, err) err = boundary.AddHostToHostSetApi(t, ctx, client, hostSetId, hostId) require.NoError(t, err) - targetId, err := boundary.CreateTargetApi(t, ctx, client, projectId, c.TargetPort) + targetId, err := boundary.CreateTargetApi(t, ctx, client, projectId, "tcp", targets.WithTcpTargetDefaultPort(uint32(targetPort))) require.NoError(t, err) err = boundary.AddHostSourceToTargetApi(t, ctx, client, targetId, hostSetId) require.NoError(t, err) diff --git a/testing/internal/e2e/tests/base_with_vault/credential_store_test.go b/testing/internal/e2e/tests/base_with_vault/credential_store_test.go index 645b1b87d9..6c25c8d376 100644 --- a/testing/internal/e2e/tests/base_with_vault/credential_store_test.go +++ b/testing/internal/e2e/tests/base_with_vault/credential_store_test.go @@ -8,6 +8,7 @@ import ( "encoding/json" "fmt" "os" + "strconv" "testing" "github.com/hashicorp/boundary/api/credentiallibraries" @@ -216,6 +217,9 @@ func TestApiVaultCredentialStore(t *testing.T) { require.NoError(t, err) ctx := context.Background() + targetPort, err := strconv.ParseUint(c.TargetPort, 10, 32) + require.NoError(t, err) + orgId, err := boundary.CreateOrgApi(t, ctx, client) require.NoError(t, err) t.Cleanup(func() { @@ -233,7 +237,7 @@ func TestApiVaultCredentialStore(t *testing.T) { require.NoError(t, err) err = boundary.AddHostToHostSetApi(t, ctx, client, hostSetId, hostId) require.NoError(t, err) - targetId, err := boundary.CreateTargetApi(t, ctx, client, projectId, c.TargetPort) + targetId, err := boundary.CreateTargetApi(t, ctx, client, projectId, "tcp", targets.WithTcpTargetDefaultPort(uint32(targetPort))) require.NoError(t, err) err = boundary.AddHostSourceToTargetApi(t, ctx, client, targetId, hostSetId) require.NoError(t, err)