From 5e0f2b2661bb677032adad03f808b9ef3ad7c835 Mon Sep 17 00:00:00 2001 From: Stan Ryzhov <60649800+stasryzhov@users.noreply.github.com> Date: Wed, 14 Feb 2024 16:13:00 +0000 Subject: [PATCH 1/3] backport of commit 2a901e7df9ba685814d5c1379611c7008c44db26 --- testing/internal/e2e/boundary/session.go | 39 +++++++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/testing/internal/e2e/boundary/session.go b/testing/internal/e2e/boundary/session.go index c2b4dc5d34..595d13c072 100644 --- a/testing/internal/e2e/boundary/session.go +++ b/testing/internal/e2e/boundary/session.go @@ -17,9 +17,11 @@ import ( "github.com/stretchr/testify/require" ) -// WaitForSessionCli waits for a session to appear in the session list and returns the session -// information -func WaitForSessionCli(t testing.TB, ctx context.Context, projectId string) *sessions.Session { +// 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...) t.Log("Waiting for session to appear...") var session *sessions.Session err := backoff.RetryNotify( @@ -44,10 +46,11 @@ func WaitForSessionCli(t testing.TB, ctx context.Context, projectId string) *ses } t.Logf("Found %d session(s)", sessionCount) - if sessionCount != 1 { - return backoff.Permanent(errors.New("Only one session was expected to be found")) + if sessionCount != opts.WithExpectedSessionsCount { + return backoff.Permanent(fmt.Errorf("only %d session(s) expected", opts.WithExpectedSessionsCount)) } + // Get the most recent session session = sessionListResult.Items[0] t.Logf("Created Session: %s", session.Id) return nil @@ -98,3 +101,29 @@ func WaitForSessionStatusCli(t testing.TB, ctx context.Context, sessionId string ) require.NoError(t, err) } + +// getSessionOpts iterates the inbound SessionOption and returns a struct +func getSessionOpts(opt ...SessionOption) sessionOptions { + opts := sessionOptions{ + WithExpectedSessionsCount: 1, + } + for _, o := range opt { + o(&opts) + } + return opts +} + +// SessionOption represents how Options are passed as arguments +type SessionOption func(*sessionOptions) + +// scopeOptions is a struct representing available options for scopes +type sessionOptions struct { + WithExpectedSessionsCount int +} + +// WithExpectedSessionsCount provides an option to expect specified amount of sessions +func WithExpectedSessionsCount(count int) SessionOption { + return func(o *sessionOptions) { + o.WithExpectedSessionsCount = count + } +} From 4caa8f577840866e4537b2a9f7e03fc6652b2f8a Mon Sep 17 00:00:00 2001 From: Stan Ryzhov <60649800+stasryzhov@users.noreply.github.com> Date: Wed, 14 Feb 2024 18:02:20 +0000 Subject: [PATCH 2/3] backport of commit e29c809e8e8cce781a8d5a19fbc01e5eac3ce8bb --- testing/internal/e2e/boundary/session.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/internal/e2e/boundary/session.go b/testing/internal/e2e/boundary/session.go index 595d13c072..226642be4b 100644 --- a/testing/internal/e2e/boundary/session.go +++ b/testing/internal/e2e/boundary/session.go @@ -116,7 +116,7 @@ func getSessionOpts(opt ...SessionOption) sessionOptions { // SessionOption represents how Options are passed as arguments type SessionOption func(*sessionOptions) -// scopeOptions is a struct representing available options for scopes +// sessionOptions is a struct representing available options for sessions type sessionOptions struct { WithExpectedSessionsCount int } From 3bc4e36f509353787c16c7fe4b3b3219346ac6b6 Mon Sep 17 00:00:00 2001 From: Stan Ryzhov <60649800+stasryzhov@users.noreply.github.com> Date: Wed, 14 Feb 2024 18:02:27 +0000 Subject: [PATCH 3/3] backport of commit 42b6fb5c0b47167ac4be8da934ef1d7b5d5e0932 --- testing/internal/e2e/boundary/session.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/internal/e2e/boundary/session.go b/testing/internal/e2e/boundary/session.go index 226642be4b..ef62254c1b 100644 --- a/testing/internal/e2e/boundary/session.go +++ b/testing/internal/e2e/boundary/session.go @@ -47,7 +47,7 @@ func WaitForSessionCli(t testing.TB, ctx context.Context, projectId string, opt t.Logf("Found %d session(s)", sessionCount) if sessionCount != opts.WithExpectedSessionsCount { - return backoff.Permanent(fmt.Errorf("only %d session(s) expected", opts.WithExpectedSessionsCount)) + return backoff.Permanent(fmt.Errorf("Unexpected number of sessions. Expected: %d, Actual: %d", opts.WithExpectedSessionsCount, sessionCount)) } // Get the most recent session