From 4800904b049a20a3e87e1471cc8ffeda49dd7532 Mon Sep 17 00:00:00 2001 From: ashmrtn Date: Tue, 18 Oct 2022 11:19:53 -0700 Subject: [PATCH] Add secondary test user (#1186) ## Description Wire up code to fetch secondary user from config/env and also provide it to tests. ## Type of change - [x] :sunflower: Feature - [ ] :bug: Bugfix - [ ] :world_map: Documentation - [ ] :robot: Test - [x] :computer: CI/Deployment - [ ] :hamster: Trivial/Minor ## Issue(s) * closes #1185 merge after to ensure automatic cleanup: * #1193 ## Test Plan - [x] :muscle: Manual - [ ] :zap: Unit test - [ ] :green_heart: E2E --- src/internal/tester/config.go | 13 +++++++++++-- src/internal/tester/users.go | 12 ++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/internal/tester/config.go b/src/internal/tester/config.go index d46eb50bb..852bbc054 100644 --- a/src/internal/tester/config.go +++ b/src/internal/tester/config.go @@ -22,13 +22,15 @@ const ( // M365 config TestCfgAzureTenantID = "azure_tenantid" TestCfgUserID = "m365userid" + TestCfgSecondaryUserID = "secondarym365userid" TestCfgAccountProvider = "account_provider" ) // test specific env vars const ( - EnvCorsoM365TestUserID = "CORSO_M356_TEST_USER_ID" - EnvCorsoTestConfigFilePath = "CORSO_TEST_CONFIG_FILE" + EnvCorsoM365TestUserID = "CORSO_M356_TEST_USER_ID" + EnvCorsoSecondaryM365TestUserID = "CORSO_SECONDARY_M356_TEST_USER_ID" + EnvCorsoTestConfigFilePath = "CORSO_TEST_CONFIG_FILE" ) // global to hold the test config results. @@ -108,6 +110,13 @@ func readTestConfig() (map[string]string, error) { vpr.GetString(TestCfgUserID), "lidiah@8qzvrj.onmicrosoft.com", ) + fallbackTo( + testEnv, + TestCfgSecondaryUserID, + os.Getenv(EnvCorsoSecondaryM365TestUserID), + vpr.GetString(TestCfgSecondaryUserID), + "lynner@8qzvrj.onmicrosoft.com", + ) testEnv[EnvCorsoTestConfigFilePath] = os.Getenv(EnvCorsoTestConfigFilePath) testConfig = testEnv diff --git a/src/internal/tester/users.go b/src/internal/tester/users.go index eb764e1a1..3fe2850df 100644 --- a/src/internal/tester/users.go +++ b/src/internal/tester/users.go @@ -16,3 +16,15 @@ func M365UserID(t *testing.T) string { return cfg[TestCfgUserID] } + +// SecondaryM365UserID returns an userID string representing the m365UserID +// described by either the env var CORSO_SECONDARY_M356_TEST_USER_ID, the +// corso_test.toml config file or the default value (in that order of priority). +// The default is a last-attempt fallback that will only work on alcion's +// testing org. +func SecondaryM365UserID(t *testing.T) string { + cfg, err := readTestConfig() + require.NoError(t, err, "retrieving secondary m365 user id from test configuration") + + return cfg[TestCfgSecondaryUserID] +}