refact(e2e): Remove use of AwsHostSetCount env

Instead of passing in the number of hosts created for a host set, we can just use the length of the IP addresses to determine that value.
This commit is contained in:
Michael Li committed 2022-10-12 09:49:08 -04:00
1 parent 5365b29007
commit 719200612d
4 files changed
+32 -25

No files matched your search

+1 -2
View File
@@ -179,10 +179,9 @@ scenario "e2e_host_aws" {
aws_access_key_id = step.iam_setup.access_key_id
aws_secret_access_key = step.iam_setup.secret_access_key
aws_host_set_filter1 = step.create_tag1_inputs.tag_string
aws_host_set_count1 = 2
aws_host_set_ips1 = step.create_targets_with_tag1.target_ips
aws_host_set_filter2 = step.create_tag2_inputs.tag_string
aws_host_set_count2 = 1
aws_host_set_ips2 = step.create_targets_with_tag2.target_ips
}
}
+6 -6
View File
@@ -83,16 +83,17 @@ variable "aws_host_set_filter2" {
type = string
default = ""
}
variable "aws_host_set_count2" {
description = "Number of hosts in aws_host_set_filter2"
type = number
default = 0
variable "aws_host_set_ips2" {
description = "List of IP addresses in aws_host_set_filter2"
type = list(string)
default = [""]
}
locals {
aws_ssh_private_key_path = abspath(var.aws_ssh_private_key_path)
vault_addr = var.vault_addr != "" ? "http://${var.vault_addr}:8200" : ""
aws_host_set_ips1 = jsonencode(var.aws_host_set_ips1)
aws_host_set_ips2 = jsonencode(var.aws_host_set_ips2)
}
resource "enos_local_exec" "run_e2e_test" {
@@ -109,10 +110,9 @@ resource "enos_local_exec" "run_e2e_test" {
E2E_AWS_ACCESS_KEY_ID = var.aws_access_key_id,
E2E_AWS_SECRET_ACCESS_KEY = var.aws_secret_access_key,
E2E_AWS_HOST_SET_FILTER1 = var.aws_host_set_filter1,
E2E_AWS_HOST_SET_COUNT1 = var.aws_host_set_count1,
E2E_AWS_HOST_SET_IPS1 = local.aws_host_set_ips1,
E2E_AWS_HOST_SET_FILTER2 = var.aws_host_set_filter2,
E2E_AWS_HOST_SET_COUNT2 = var.aws_host_set_count2
E2E_AWS_HOST_SET_IPS2 = local.aws_host_set_ips2
}
inline = ["PATH=\"${var.local_boundary_dir}:$PATH\" go test -v ${var.test_package}"]
+1 -2
View File
@@ -49,10 +49,9 @@ export E2E_SSH_USER= # e.g. ubuntu
export E2E_AWS_ACCESS_KEY_ID=
export E2E_AWS_SECRET_ACCESS_KEY=
export E2E_AWS_HOST_SET_FILTER1= # e.g. "tag:testtag=true"
export E2E_AWS_HOST_SET_COUNT1= # e.g. 2
export E2E_AWS_HOST_SET_IPS1= # e.g. "[\"1.2.3.4\", \"2.3.4.5\"]"
export E2E_AWS_HOST_SET_FILTER2= # e.g. "tag:testtagtwo=test"
export E2E_AWS_HOST_SET_COUNT2= # e.g. 1
export E2E_AWS_HOST_SET_IPS2= # e.g. "[\"1.2.3.4\"]
export E2E_SSH_KEY_PATH= # e.g. /Users/username/key.pem
export E2E_SSH_USER= # e.g. ubuntu
@@ -5,7 +5,6 @@ import (
"encoding/json"
"errors"
"fmt"
"strconv"
"strings"
"testing"
"time"
@@ -25,13 +24,12 @@ import (
type config struct {
AwsAccessKeyId string `envconfig:"E2E_AWS_ACCESS_KEY_ID" required:"true"`
AwsSecretAccessKey string `envconfig:"E2E_AWS_SECRET_ACCESS_KEY" required:"true"`
AwsHostSetFilter1 string `envconfig:"E2E_AWS_HOST_SET_FILTER1" required:"true"`
AwsHostSetCount1 string `envconfig:"E2E_AWS_HOST_SET_COUNT1" required:"true"`
AwsHostSetIps1 string `envconfig:"E2E_AWS_HOST_SET_IPS1" required:"true"`
AwsHostSetFilter2 string `envconfig:"E2E_AWS_HOST_SET_FILTER2" required:"true"`
AwsHostSetCount2 string `envconfig:"E2E_AWS_HOST_SET_COUNT2" required:"true"`
TargetSshKeyPath string `envconfig:"E2E_SSH_KEY_PATH" required:"true"` // e.g. /Users/username/key.pem
TargetSshUser string `envconfig:"E2E_SSH_USER" required:"true"` // e.g. ubuntu
AwsHostSetFilter1 string `envconfig:"E2E_AWS_HOST_SET_FILTER1" required:"true"` // e.g. "tag:testtag=true"
AwsHostSetIps1 string `envconfig:"E2E_AWS_HOST_SET_IPS1" required:"true"` // e.g. "[\"1.2.3.4\", \"2.3.4.5\"]"
AwsHostSetFilter2 string `envconfig:"E2E_AWS_HOST_SET_FILTER2" required:"true"` // e.g. "tag:testtagtwo=test"
AwsHostSetIps2 string `envconfig:"E2E_AWS_HOST_SET_IPS2" required:"true"` // e.g. "[\"1.2.3.4\"]"
TargetSshKeyPath string `envconfig:"E2E_SSH_KEY_PATH" required:"true"` // e.g. "/Users/username/key.pem"
TargetSshUser string `envconfig:"E2E_SSH_USER" required:"true"` // e.g. "ubuntu"
TargetPort string `envconfig:"E2E_SSH_PORT" default:"22"`
}
@@ -45,6 +43,9 @@ func loadConfig() (*config, error) {
return &c, err
}
// TestCreateAwsDynamicHostCatalogCli uses the boundary cli to create a host catalog with the AWS
// plugin. The test sets up an AWS dynamic host catalog, creates some host sets, sets up a target to
// one of the host sets, and attempts to connect to the target.
func TestCreateAwsDynamicHostCatalogCli(t *testing.T) {
e2e.MaybeSkipTest(t)
c, err := loadConfig()
@@ -123,7 +124,10 @@ func TestCreateAwsDynamicHostCatalogCli(t *testing.T) {
},
)
require.NoError(t, err)
expectedHostSetCount1, err := strconv.Atoi(c.AwsHostSetCount1)
var targetIps1 []string
err = json.Unmarshal([]byte(c.AwsHostSetIps1), &targetIps1)
expectedHostSetCount1 := len(targetIps1)
require.NoError(t, err)
assert.Equal(t, expectedHostSetCount1, actualHostSetCount1, "Numbers of hosts in host set did not match expected amount")
@@ -174,7 +178,9 @@ func TestCreateAwsDynamicHostCatalogCli(t *testing.T) {
},
)
require.NoError(t, err)
expectedHostSetCount2, err := strconv.Atoi(c.AwsHostSetCount2)
var targetIps2 []string
err = json.Unmarshal([]byte(c.AwsHostSetIps2), &targetIps2)
expectedHostSetCount2 := len(targetIps2)
require.NoError(t, err)
assert.Equal(t, expectedHostSetCount2, actualHostSetCount2, "Numbers of hosts in host set did not match expected amount")
@@ -257,17 +263,18 @@ func TestCreateAwsDynamicHostCatalogCli(t *testing.T) {
t.Log("Successfully connected to the target")
// Check if connected host exists in the host set
var targetIps []string
err = json.Unmarshal([]byte(c.AwsHostSetIps1), &targetIps)
hostIpInList := false
for _, v := range targetIps {
for _, v := range targetIps1 {
if v == hostIp {
hostIpInList = true
}
}
require.True(t, hostIpInList, fmt.Sprintf("Connected host (%s) is not in expected list (%s)", hostIp, targetIps))
require.True(t, hostIpInList, fmt.Sprintf("Connected host (%s) is not in expected list (%s)", hostIp, targetIps1))
}
// TestCreateAwsDynamicHostCatalogApi uses the boundary go api to create a host catalog with the AWS
// plugin. The test sets up an AWS dynamic host catalog, creates a host set, and sets up a target to
// the host set.
func TestCreateAwsDynamicHostCatalogApi(t *testing.T) {
e2e.MaybeSkipTest(t)
c, err := loadConfig()
@@ -340,7 +347,9 @@ func TestCreateAwsDynamicHostCatalogApi(t *testing.T) {
)
require.NoError(t, err)
t.Log("Successfully found items in the host set")
expectedHostSetCount, err := strconv.Atoi(c.AwsHostSetCount1)
var targetIps []string
err = json.Unmarshal([]byte(c.AwsHostSetIps1), &targetIps)
expectedHostSetCount := len(targetIps)
require.NoError(t, err)
assert.Equal(t, expectedHostSetCount, actualHostSetCount, "Numbers of hosts in host set did not match expected amount")