refact(e2e): Create functions for commonly used operations

Many tests had duplicate code to create the base level domain objects in a boundary environment. This commit refactors that code to use functions for these commonly used operations.
This commit is contained in:
Michael Li committed 2022-10-19 10:46:57 -04:00
1 parent 051d337b21
commit 618eca19f5
7 files changed
+258 -451

No files matched your search

@@ -13,7 +13,6 @@ import (
"github.com/hashicorp/boundary/api/hostcatalogs"
"github.com/hashicorp/boundary/api/hosts"
"github.com/hashicorp/boundary/api/hostsets"
"github.com/hashicorp/boundary/api/targets"
"github.com/hashicorp/boundary/testing/internal/e2e"
"github.com/hashicorp/boundary/testing/internal/e2e/boundary"
"github.com/kelseyhightower/envconfig"
@@ -52,8 +51,6 @@ func TestCreateAwsDynamicHostCatalogCli(t *testing.T) {
require.NoError(t, err)
boundary.AuthenticateCli(t)
// Create an org and project
newOrgId := boundary.CreateNewOrgCli(t)
newProjectId := boundary.CreateNewProjectCli(t, newOrgId)
@@ -183,7 +180,6 @@ func TestCreateAwsDynamicHostCatalogCli(t *testing.T) {
assert.Equal(t, expectedHostSetCount2, actualHostSetCount2, "Numbers of hosts in host set did not match expected amount")
// Get list of all hosts from host catalog
// Retry is needed here since it can take a few tries before hosts start appearing
t.Logf("Looking for items in the host catalog...")
var actualHostCatalogCount int
err = backoff.RetryNotify(
@@ -221,25 +217,8 @@ func TestCreateAwsDynamicHostCatalogCli(t *testing.T) {
assert.Equal(t, expectedHostCatalogCount, actualHostCatalogCount, "Numbers of hosts in host catalog did not match expected amount")
// Create target
output = e2e.RunCommand("boundary", "targets", "create", "tcp",
"-scope-id", newProjectId,
"-default-port", c.TargetPort,
"-name", "e2e Automated Test Target",
"-format", "json",
)
require.NoError(t, output.Err, string(output.Stderr))
var newTargetResult targets.TargetCreateResult
err = json.Unmarshal(output.Stdout, &newTargetResult)
require.NoError(t, err)
newTargetId := newTargetResult.Item.Id
t.Logf("Created Target: %s", newTargetId)
// Add host set to target
output = e2e.RunCommand("boundary", "targets", "add-host-sources",
"-id", newTargetId,
"-host-source", newHostSetId1,
)
require.NoError(t, output.Err, string(output.Stderr))
newTargetId := boundary.CreateNewTargetCli(t, newProjectId, c.TargetPort)
boundary.AddHostSourceToTargetCli(t, newTargetId, newHostSetId1)
// Connect to target
output = e2e.RunCommand("boundary", "connect",
@@ -278,12 +257,10 @@ func TestCreateAwsDynamicHostCatalogApi(t *testing.T) {
c, err := loadConfig()
require.NoError(t, err)
// Create boundary api client
client, err := boundary.NewApiClient()
require.NoError(t, err)
ctx := context.Background()
// Create an org and project
newOrgId := boundary.CreateNewOrgApi(t, ctx, client)
newProjectId := boundary.CreateNewProjectApi(t, ctx, client, newOrgId)