refact(e2e): Modify CreateTargetApi to support different target types
This commit is contained in:
1 parent
d24ad6c2e2
commit
288f505482
6 files changed
+32
-17
No files matched your search
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user