From b8202d89d94981059d99b2391c7964485a580bdf Mon Sep 17 00:00:00 2001 From: Monis Khan Date: Wed, 16 Feb 2022 09:20:28 -0500 Subject: [PATCH] Enforce naming convention for browser based tests This allows us to target browser based tests with the regex: go test -v -race -count 1 -timeout 0 ./test/integration -run '/_Browser' New tests that call browsertest.Open will automatically be forced to follow this convention. Signed-off-by: Monis Khan --- test/integration/cli_test.go | 2 +- .../concierge_credentialrequest_test.go | 4 +-- test/integration/e2e_test.go | 4 +-- test/integration/formposthtml_test.go | 2 +- test/integration/supervisor_login_test.go | 2 +- test/testlib/browsertest/browsertest.go | 28 ++++++++++++++++++- 6 files changed, 34 insertions(+), 8 deletions(-) diff --git a/test/integration/cli_test.go b/test/integration/cli_test.go index 263c9154..605f590a 100644 --- a/test/integration/cli_test.go +++ b/test/integration/cli_test.go @@ -170,7 +170,7 @@ func deserializeWhoAmIRequest(t *testing.T, data string, apiGroupSuffix string) return obj.(*identityv1alpha1.WhoAmIRequest) } -func TestCLILoginOIDC(t *testing.T) { +func TestCLILoginOIDC_Browser(t *testing.T) { env := testlib.IntegrationEnv(t) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) diff --git a/test/integration/concierge_credentialrequest_test.go b/test/integration/concierge_credentialrequest_test.go index d403a8d0..2bd657ad 100644 --- a/test/integration/concierge_credentialrequest_test.go +++ b/test/integration/concierge_credentialrequest_test.go @@ -45,10 +45,10 @@ func TestUnsuccessfulCredentialRequest_Parallel(t *testing.T) { require.Equal(t, "authentication failed", *response.Status.Message) } -// TestSuccessfulCredentialRequest cannot run in parallel because runPinnipedLoginOIDC uses a fixed port +// TestSuccessfulCredentialRequest_Browser cannot run in parallel because runPinnipedLoginOIDC uses a fixed port // for its localhost listener via --listen-port=env.CLIUpstreamOIDC.CallbackURL.Port() per oidcLoginCommand. // Since ports are global to the process, tests using oidcLoginCommand must be run serially. -func TestSuccessfulCredentialRequest(t *testing.T) { +func TestSuccessfulCredentialRequest_Browser(t *testing.T) { env := testlib.IntegrationEnv(t).WithCapability(testlib.ClusterSigningKeyIsAvailable) ctx, cancel := context.WithTimeout(context.Background(), 6*time.Minute) diff --git a/test/integration/e2e_test.go b/test/integration/e2e_test.go index 2af62cc2..decfc14b 100644 --- a/test/integration/e2e_test.go +++ b/test/integration/e2e_test.go @@ -47,8 +47,8 @@ import ( "go.pinniped.dev/test/testlib/browsertest" ) -// TestE2EFullIntegration tests a full integration scenario that combines the supervisor, concierge, and CLI. -func TestE2EFullIntegration(t *testing.T) { // nolint:gocyclo +// TestE2EFullIntegration_Browser tests a full integration scenario that combines the supervisor, concierge, and CLI. +func TestE2EFullIntegration_Browser(t *testing.T) { // nolint:gocyclo env := testlib.IntegrationEnv(t) ctx, cancelFunc := context.WithTimeout(context.Background(), 10*time.Minute) diff --git a/test/integration/formposthtml_test.go b/test/integration/formposthtml_test.go index d891488e..7bbadee9 100644 --- a/test/integration/formposthtml_test.go +++ b/test/integration/formposthtml_test.go @@ -25,7 +25,7 @@ import ( ) // safe to run in parallel with serial tests since it only interacts with a test local server, see main_test.go. -func TestFormPostHTML_Parallel(t *testing.T) { +func TestFormPostHTML_Browser_Parallel(t *testing.T) { _ = testlib.IntegrationEnv(t) // Run a mock callback handler, simulating the one running in the CLI. diff --git a/test/integration/supervisor_login_test.go b/test/integration/supervisor_login_test.go index 1fec0989..d8c9d31c 100644 --- a/test/integration/supervisor_login_test.go +++ b/test/integration/supervisor_login_test.go @@ -47,7 +47,7 @@ import ( ) // nolint:gocyclo -func TestSupervisorLogin(t *testing.T) { +func TestSupervisorLogin_Browser(t *testing.T) { env := testlib.IntegrationEnv(t) tests := []struct { diff --git a/test/testlib/browsertest/browsertest.go b/test/testlib/browsertest/browsertest.go index c94850d2..d6686ea6 100644 --- a/test/testlib/browsertest/browsertest.go +++ b/test/testlib/browsertest/browsertest.go @@ -6,6 +6,7 @@ package browsertest import ( "regexp" + "strings" "testing" "time" @@ -20,10 +21,16 @@ const ( operationPollingInterval = 100 * time.Millisecond ) -// Open a webdriver-driven browser and returns an *agouti.Page to control it. The browser will be automatically +// Open a webdriver-driven browser and returns an *agouti.Page to control it. The browser will be automatically // closed at the end of the current test. It is configured for test purposes with the correct HTTP proxy and // in a mode that ignore certificate errors. func Open(t *testing.T) *agouti.Page { + t.Helper() + + // make it trivial to run all browser based tests via: + // go test -v -race -count 1 -timeout 0 ./test/integration -run '/_Browser' + require.Contains(t, rootTestName(t), "_Browser", "browser based tests must contain the string _Browser in their name") + t.Logf("opening browser driver") env := testlib.IntegrationEnv(t) caps := agouti.NewCapabilities() @@ -58,6 +65,25 @@ func Open(t *testing.T) *agouti.Page { return page } +func rootTestName(t *testing.T) string { + switch names := strings.SplitN(t.Name(), "/", 3); len(names) { + case 0: + panic("impossible") + + case 1: + return names[0] + + case 2, 3: + if strings.HasPrefix(names[0], "TestIntegration") { + return names[1] + } + return names[0] + + default: + panic("impossible") + } +} + // WaitForVisibleElements expects the page to contain all the the elements specified by the selectors. It waits for this // to occur and times out, failing the test, if they never appear. func WaitForVisibleElements(t *testing.T, page *agouti.Page, selectors ...string) {