ce: refact(e2e): Update WaitForSessionCli to accept e2e options

(cherry picked from commit ab3b5fb361e6f2f854f24306979565a28664fc0a)
This commit is contained in:
Tony committed 2025-11-18 14:36:08 -05:00
1 parent d3b2e7402b
commit 94c32d2173
20 files changed
+33 -24

No files matched your search

+12 -3
View File
@@ -20,19 +20,28 @@ import (
// WaitForSessionCli waits for sessions to appear in the session list and returns the most recent session
// information. If the WithExpectedSessionsCount option is provided, expects to find specified amount of sessions
// or only 1 otherwise.
func WaitForSessionCli(t testing.TB, ctx context.Context, projectId string, opt ...SessionOption) *sessions.Session {
opts := getSessionOpts(opt...)
func WaitForSessionCli(t testing.TB, ctx context.Context, projectId string, sessionOpts []SessionOption, e2eOpts ...e2e.Option) *sessions.Session {
opts := getSessionOpts(sessionOpts...)
var options []e2e.Option
options = append(options,
e2e.WithArgs("sessions", "list", "-scope-id", projectId, "-include-terminated", "-format", "json"),
)
options = append(options, e2eOpts...)
t.Log("Waiting for session to appear...")
var session *sessions.Session
err := backoff.RetryNotify(
func() error {
// List sessions
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("sessions", "list", "-scope-id", projectId, "-include-terminated", "-format", "json"),
options...,
)
if output.Err != nil {
return backoff.Permanent(errors.New(string(output.Stderr)))
}
var sessionListResult sessions.SessionListResult
err := json.Unmarshal(output.Stdout, &sessionListResult)
if err != nil {
@@ -156,7 +156,7 @@ func TestCliCreateAwsDynamicHostCatalogWithHostSet(t *testing.T) {
}()
t.Cleanup(cancel)
s := boundary.WaitForSessionCli(t, ctx, projectId)
s := boundary.WaitForSessionCli(t, ctx, projectId, nil)
boundary.WaitForSessionStatusCli(t, ctx, s.Id, session.StatusActive.String())
output = e2e.RunCommand(ctx, "boundary",
@@ -70,7 +70,7 @@ func TestCliBytesUpDownEmpty(t *testing.T) {
}()
t.Cleanup(cancel)
session := boundary.WaitForSessionCli(t, ctx, projectId)
session := boundary.WaitForSessionCli(t, ctx, projectId, nil)
assert.Equal(t, targetId, session.TargetId)
// Wait until bytes up and down is greater than 0
@@ -73,7 +73,7 @@ func TestCliBytesUpDownTransferData(t *testing.T) {
)
}()
t.Cleanup(cancel)
s := boundary.WaitForSessionCli(t, ctx, projectId)
s := boundary.WaitForSessionCli(t, ctx, projectId, nil)
boundary.WaitForSessionStatusCli(t, ctx, s.Id, session.StatusActive.String())
assert.Equal(t, targetId, s.TargetId)
@@ -68,7 +68,7 @@ func TestCliSessionCancelAdmin(t *testing.T) {
)
}()
t.Cleanup(cancel)
s := boundary.WaitForSessionCli(t, ctx, projectId)
s := boundary.WaitForSessionCli(t, ctx, projectId, nil)
boundary.WaitForSessionStatusCli(t, ctx, s.Id, session.StatusActive.String())
assert.Equal(t, targetId, s.TargetId)
assert.Equal(t, hostId, s.HostId)
@@ -145,7 +145,7 @@ func TestCliSessionCancelGroup(t *testing.T) {
)
}()
t.Cleanup(cancel)
s := boundary.WaitForSessionCli(t, ctx, projectId)
s := boundary.WaitForSessionCli(t, ctx, projectId, nil)
boundary.WaitForSessionStatusCli(t, ctx, s.Id, session.StatusActive.String())
assert.Equal(t, targetId, s.TargetId)
assert.Equal(t, hostId, s.HostId)
@@ -138,7 +138,7 @@ func TestCliSessionCancelUser(t *testing.T) {
)
}()
t.Cleanup(cancel)
s := boundary.WaitForSessionCli(t, ctx, projectId)
s := boundary.WaitForSessionCli(t, ctx, projectId, nil)
boundary.WaitForSessionStatusCli(t, ctx, s.Id, session.StatusActive.String())
assert.Equal(t, targetId, s.TargetId)
assert.Equal(t, hostId, s.HostId)
@@ -101,7 +101,7 @@ func TestCliSessionEndWhenHostSetIsDeleted(t *testing.T) {
)
}()
t.Cleanup(cancel)
s := boundary.WaitForSessionCli(t, ctx, projectId)
s := boundary.WaitForSessionCli(t, ctx, projectId, nil)
boundary.WaitForSessionStatusCli(t, ctx, s.Id, session.StatusActive.String())
assert.Equal(t, targetId, s.TargetId)
assert.Equal(t, hostId, s.HostId)
@@ -101,7 +101,7 @@ func TestCliSessionEndWhenHostIsDeleted(t *testing.T) {
)
}()
t.Cleanup(cancel)
s := boundary.WaitForSessionCli(t, ctx, projectId)
s := boundary.WaitForSessionCli(t, ctx, projectId, nil)
boundary.WaitForSessionStatusCli(t, ctx, s.Id, session.StatusActive.String())
assert.Equal(t, targetId, s.TargetId)
assert.Equal(t, hostId, s.HostId)
@@ -92,7 +92,7 @@ func TestCliSessionEndWhenProjectIsDeleted(t *testing.T) {
)
}()
t.Cleanup(cancel)
s := boundary.WaitForSessionCli(t, ctx, projectId)
s := boundary.WaitForSessionCli(t, ctx, projectId, nil)
boundary.WaitForSessionStatusCli(t, ctx, s.Id, session.StatusActive.String())
assert.Equal(t, targetId, s.TargetId)
@@ -101,7 +101,7 @@ func TestCliSessionEndWhenTargetIsDeleted(t *testing.T) {
)
}()
t.Cleanup(cancel)
s := boundary.WaitForSessionCli(t, ctx, projectId)
s := boundary.WaitForSessionCli(t, ctx, projectId, nil)
boundary.WaitForSessionStatusCli(t, ctx, s.Id, session.StatusActive.String())
assert.Equal(t, targetId, s.TargetId)
assert.Equal(t, hostId, s.HostId)
@@ -106,7 +106,7 @@ func TestCliSessionEndWhenUserIsDeleted(t *testing.T) {
)
}()
t.Cleanup(cancel)
s := boundary.WaitForSessionCli(t, ctx, projectId)
s := boundary.WaitForSessionCli(t, ctx, projectId, nil)
boundary.WaitForSessionStatusCli(t, ctx, s.Id, session.StatusActive.String())
assert.Equal(t, targetId, s.TargetId)
assert.Equal(t, hostId, s.HostId)
@@ -67,7 +67,7 @@ func TestCliTcpTargetConnectTargetWithConnectionLimits(t *testing.T) {
}()
t.Cleanup(cancel)
boundary.WaitForSessionCli(t, ctx, projectId)
boundary.WaitForSessionCli(t, ctx, projectId, nil)
// Start connections. Expect an error once the limit is reached
for i := 0; i <= sessionConnectionLimit; i++ {
@@ -75,7 +75,7 @@ func TestCliTcpTargetConnectExecLongLastingScript(t *testing.T) {
)
}()
t.Cleanup(cancel)
boundary.WaitForSessionCli(t, ctx, projectId)
boundary.WaitForSessionCli(t, ctx, projectId, nil)
t.Log("Copying script to host...")
output := e2e.RunCommand(ctx, "scp",
@@ -55,7 +55,7 @@ func TestCliTcpTargetConnectGoSsh(t *testing.T) {
}()
t.Cleanup(cancel)
boundary.WaitForSessionCli(t, ctx, projectId)
boundary.WaitForSessionCli(t, ctx, projectId, nil)
// Connect to the target using the go experimental ssh library
privateKeyRaw, err := os.ReadFile(c.TargetSshKeyPath)
@@ -79,7 +79,7 @@ Server: netcat-can-you-believe-it
_, _ = io.Copy(io.Discard, f) // Not checking error here since it will return an error on session close
}()
s := boundary.WaitForSessionCli(t, ctx, projectId)
s := boundary.WaitForSessionCli(t, ctx, projectId, nil)
boundary.WaitForSessionStatusCli(t, ctx, s.Id, session.StatusActive.String())
// Create http target and connect to it
@@ -57,7 +57,7 @@ func TestCliTcpTargetConnectListenPort(t *testing.T) {
}()
t.Cleanup(cancel)
s := boundary.WaitForSessionCli(t, ctx, projectId)
s := boundary.WaitForSessionCli(t, ctx, projectId, nil)
boundary.WaitForSessionStatusCli(t, ctx, s.Id, session.StatusPending.String())
t.Logf("Successfully connected to target with listen port %s", ListenPort)
@@ -118,7 +118,7 @@ func TestCliTcpTargetConnectDefaultClientPort(t *testing.T) {
}()
t.Cleanup(cancel)
s := boundary.WaitForSessionCli(t, ctx, projectId)
s := boundary.WaitForSessionCli(t, ctx, projectId, nil)
boundary.WaitForSessionStatusCli(t, ctx, s.Id, session.StatusPending.String())
t.Logf("Successfully connected to target with client port %d", DefaultClientPort)
@@ -65,7 +65,7 @@ func TestCliTcpTargetConnectTargetWithLocalhost(t *testing.T) {
}()
t.Cleanup(cancel)
boundary.WaitForSessionCli(t, ctx, projectId)
boundary.WaitForSessionCli(t, ctx, projectId, nil)
// Connect to target and print host's IP address
output := e2e.RunCommand(ctx, "ssh",
@@ -64,7 +64,7 @@ func TestCliTcpTargetConnectTargetAndScp(t *testing.T) {
}()
t.Cleanup(cancel)
boundary.WaitForSessionCli(t, ctx, projectId)
boundary.WaitForSessionCli(t, ctx, projectId, nil)
// Create file to scp
testDir := t.TempDir()
@@ -71,7 +71,7 @@ func TestCliTcpTargetConnectTargetWithSessionMaxSecondsTearDown(t *testing.T) {
)
}()
t.Cleanup(cancel)
s := boundary.WaitForSessionCli(t, ctx, projectId)
s := boundary.WaitForSessionCli(t, ctx, projectId, nil)
boundary.WaitForSessionStatusCli(t, ctx, s.Id, session.StatusActive.String())
// Check that session was closed once time limit is reached
@@ -140,7 +140,7 @@ func TestCliTcpTargetConnectTargetWithSessionMaxSecondsRejectNew(t *testing.T) {
)
}()
t.Cleanup(cancel)
boundary.WaitForSessionCli(t, ctx, projectId)
boundary.WaitForSessionCli(t, ctx, projectId, nil)
// Start connections. Expect an error once the time limit is reached
t.Log("Creating connections...")