test(e2e): Add "update host set filter" check (#3482)
This commit is contained in:
1 parent
1482f33845
commit
cce722c773
2 files changed
+64
-8
No files matched your search
@@ -7,6 +7,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -185,7 +186,7 @@ func CreateNewAwsHostSetCli(t testing.TB, ctx context.Context, hostCatalogId str
|
||||
return newHostSetId
|
||||
}
|
||||
|
||||
// WaitForHostsInHostSetCli uses the cli to check if there are hosts in a host set. It will check a
|
||||
// WaitForHostsInHostSetCli uses the cli to check if there are any hosts in a host set. It will check a
|
||||
// few times before returning a result. The method will fail if there are 0 hosts found.
|
||||
func WaitForHostsInHostSetCli(t testing.TB, ctx context.Context, hostSetId string) int {
|
||||
t.Logf("Looking for items in the host set...")
|
||||
@@ -214,7 +215,7 @@ func WaitForHostsInHostSetCli(t testing.TB, ctx context.Context, hostSetId strin
|
||||
return errors.New("No items are appearing in the host set")
|
||||
}
|
||||
|
||||
t.Logf("Found %d hosts", actualHostSetCount)
|
||||
t.Logf("Found %d host(s)", actualHostSetCount)
|
||||
return nil
|
||||
},
|
||||
backoff.WithMaxRetries(backoff.NewConstantBackOff(3*time.Second), 5),
|
||||
@@ -226,3 +227,48 @@ func WaitForHostsInHostSetCli(t testing.TB, ctx context.Context, hostSetId strin
|
||||
|
||||
return actualHostSetCount
|
||||
}
|
||||
|
||||
// WaitForNumberOfHostsInHostSetCli uses the cli to check if the number of hosts
|
||||
// in a host set match the expected. The method will throw an error if it does
|
||||
// not match after some retries.
|
||||
func WaitForNumberOfHostsInHostSetCli(t testing.TB, ctx context.Context, hostSetId string, expectedHostCount int) {
|
||||
t.Logf("Looking for items in the host set...")
|
||||
var actualHostSetCount int
|
||||
err := backoff.RetryNotify(
|
||||
func() error {
|
||||
output := e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs(
|
||||
"host-sets", "read",
|
||||
"-id", hostSetId,
|
||||
"-format", "json",
|
||||
),
|
||||
)
|
||||
if output.Err != nil {
|
||||
return backoff.Permanent(errors.New(string(output.Stderr)))
|
||||
}
|
||||
|
||||
var hostSetsReadResult hostsets.HostSetReadResult
|
||||
err := json.Unmarshal(output.Stdout, &hostSetsReadResult)
|
||||
if err != nil {
|
||||
return backoff.Permanent(err)
|
||||
}
|
||||
|
||||
actualHostSetCount = len(hostSetsReadResult.Item.HostIds)
|
||||
if actualHostSetCount != expectedHostCount {
|
||||
return errors.New(
|
||||
fmt.Sprintf("Number of hosts in host set do not match expected. EXPECTED: %d, ACTUAL: %d",
|
||||
expectedHostCount,
|
||||
actualHostSetCount,
|
||||
))
|
||||
}
|
||||
|
||||
t.Logf("Found %d host(s)", actualHostSetCount)
|
||||
return nil
|
||||
},
|
||||
backoff.WithMaxRetries(backoff.NewConstantBackOff(3*time.Second), 5),
|
||||
func(err error, td time.Duration) {
|
||||
t.Logf("%s. Retrying...", err.Error())
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
@@ -45,21 +45,31 @@ func TestCliCreateAwsDynamicHostCatalogWithHostSet(t *testing.T) {
|
||||
|
||||
// Set up a host set
|
||||
newHostSetId1 := boundary.CreateNewAwsHostSetCli(t, ctx, newHostCatalogId, c.AwsHostSetFilter1)
|
||||
actualHostSetCount1 := boundary.WaitForHostsInHostSetCli(t, ctx, newHostSetId1)
|
||||
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")
|
||||
boundary.WaitForNumberOfHostsInHostSetCli(t, ctx, newHostSetId1, expectedHostSetCount1)
|
||||
|
||||
// Set up another host set
|
||||
newHostSetId2 := boundary.CreateNewAwsHostSetCli(t, ctx, newHostCatalogId, c.AwsHostSetFilter2)
|
||||
actualHostSetCount2 := boundary.WaitForHostsInHostSetCli(t, ctx, newHostSetId2)
|
||||
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")
|
||||
expectedHostSetCount2 := len(targetIps2)
|
||||
boundary.WaitForNumberOfHostsInHostSetCli(t, ctx, newHostSetId2, expectedHostSetCount2)
|
||||
|
||||
// Update host set with a different filter
|
||||
t.Log("Updating host set 2 with host set 1's filter...")
|
||||
output := e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs(
|
||||
"host-sets", "update", "plugin",
|
||||
"-id", newHostSetId2,
|
||||
"-attr", fmt.Sprintf("filters=%s", c.AwsHostSetFilter1),
|
||||
),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
boundary.WaitForNumberOfHostsInHostSetCli(t, ctx, newHostSetId2, expectedHostSetCount1)
|
||||
|
||||
// Get list of all hosts from host catalog
|
||||
t.Logf("Looking for items in the host catalog...")
|
||||
@@ -102,7 +112,7 @@ func TestCliCreateAwsDynamicHostCatalogWithHostSet(t *testing.T) {
|
||||
boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId1)
|
||||
|
||||
// Connect to target
|
||||
output := e2e.RunCommand(ctx, "boundary",
|
||||
output = e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs(
|
||||
"connect",
|
||||
"-target-id", newTargetId,
|
||||
|
||||
Reference in new issue
Block a user