get CORSO_M365_TEST_UNLICENSED_USER from env

This commit is contained in:
neha-Gupta1 2023-05-17 11:10:48 +05:30
parent e359ce2b74
commit 586149a197
4 changed files with 31 additions and 11 deletions

View File

@ -226,7 +226,7 @@ func runBackups(
err = bo.Run(ictx) err = bo.Run(ictx)
if err != nil { if err != nil {
if strings.Contains(err.Error(), graph.ErrServiceNotEnabled.Error()) { if errors.Is(err, graph.ErrServiceNotEnabled) {
logger.Ctx(ctx).Debugf("Service not enabled for creating backup for %s", bo.ResourceOwner.Name()) logger.Ctx(ctx).Debugf("Service not enabled for creating backup for %s", bo.ResourceOwner.Name())
Infof(ictx, "%v\n", err) Infof(ictx, "%v\n", err)

View File

@ -173,7 +173,7 @@ func runExchangeBackupCategoryTest(suite *BackupExchangeE2ESuite, category strin
assert.Contains(t, result, suite.m365UserID) assert.Contains(t, result, suite.m365UserID)
} }
func (suite *BackupExchangeE2ESuite) TestExchangeBackupCmd_ServiceNotEnables_email() { func (suite *BackupExchangeE2ESuite) TestExchangeBackupCmd_ServiceNotEnabled_email() {
runExchangeBackupServiceNotEnabledTest(suite, "email") runExchangeBackupServiceNotEnabledTest(suite, "email")
} }
@ -193,7 +193,7 @@ func runExchangeBackupServiceNotEnabledTest(suite *BackupExchangeE2ESuite, categ
cmd, ctx := buildExchangeBackupCmd( cmd, ctx := buildExchangeBackupCmd(
ctx, ctx,
suite.cfgFP, suite.cfgFP,
fmt.Sprintf("testevents@10rqc2.onmicrosoft.com,%s", suite.m365UserID), fmt.Sprintf("%s,%s", tester.UnlicensedM365UserID(suite.T()), suite.m365UserID),
category, category,
&recorder) &recorder)
err := cmd.ExecuteContext(ctx) err := cmd.ExecuteContext(ctx)

View File

@ -31,18 +31,20 @@ const (
TestCfgLoadTestUserID = "loadtestm365userid" TestCfgLoadTestUserID = "loadtestm365userid"
TestCfgLoadTestOrgUsers = "loadtestm365orgusers" TestCfgLoadTestOrgUsers = "loadtestm365orgusers"
TestCfgAccountProvider = "account_provider" TestCfgAccountProvider = "account_provider"
TestCfgUnlicensedUserID = "unlicensedm365userid"
) )
// test specific env vars // test specific env vars
const ( const (
EnvCorsoM365TestSiteID = "CORSO_M365_TEST_SITE_ID" EnvCorsoM365TestSiteID = "CORSO_M365_TEST_SITE_ID"
EnvCorsoM365TestSiteURL = "CORSO_M365_TEST_SITE_URL" EnvCorsoM365TestSiteURL = "CORSO_M365_TEST_SITE_URL"
EnvCorsoM365TestUserID = "CORSO_M365_TEST_USER_ID" EnvCorsoM365TestUserID = "CORSO_M365_TEST_USER_ID"
EnvCorsoSecondaryM365TestUserID = "CORSO_SECONDARY_M365_TEST_USER_ID" EnvCorsoSecondaryM365TestUserID = "CORSO_SECONDARY_M365_TEST_USER_ID"
EnvCorsoTertiaryM365TestUserID = "CORSO_TERTIARY_M365_TEST_USER_ID" EnvCorsoTertiaryM365TestUserID = "CORSO_TERTIARY_M365_TEST_USER_ID"
EnvCorsoM365LoadTestUserID = "CORSO_M365_LOAD_TEST_USER_ID" EnvCorsoM365LoadTestUserID = "CORSO_M365_LOAD_TEST_USER_ID"
EnvCorsoM365LoadTestOrgUsers = "CORSO_M365_LOAD_TEST_ORG_USERS" EnvCorsoM365LoadTestOrgUsers = "CORSO_M365_LOAD_TEST_ORG_USERS"
EnvCorsoTestConfigFilePath = "CORSO_TEST_CONFIG_FILE" EnvCorsoTestConfigFilePath = "CORSO_TEST_CONFIG_FILE"
EnvCorsoUnlicensedM365TestUserID = "CORSO_M365_TEST_UNLICENSED_USER"
) )
// global to hold the test config results. // global to hold the test config results.
@ -152,6 +154,12 @@ func readTestConfig() (map[string]string, error) {
os.Getenv(EnvCorsoM365TestSiteURL), os.Getenv(EnvCorsoM365TestSiteURL),
vpr.GetString(TestCfgSiteURL), vpr.GetString(TestCfgSiteURL),
"https://10rqc2.sharepoint.com/sites/CorsoCI") "https://10rqc2.sharepoint.com/sites/CorsoCI")
fallbackTo(
testEnv,
TestCfgUnlicensedUserID,
os.Getenv(EnvCorsoUnlicensedM365TestUserID),
vpr.GetString(TestCfgUnlicensedUserID),
"testevents@10rqc2.onmicrosoft.com")
testEnv[EnvCorsoTestConfigFilePath] = os.Getenv(EnvCorsoTestConfigFilePath) testEnv[EnvCorsoTestConfigFilePath] = os.Getenv(EnvCorsoTestConfigFilePath)
testConfig = testEnv testConfig = testEnv

View File

@ -197,3 +197,15 @@ func GetM365SiteID(ctx context.Context) string {
return strings.ToLower(cfg[TestCfgSiteID]) return strings.ToLower(cfg[TestCfgSiteID])
} }
// UnlicensedM365UserID returns an userID string representing the m365UserID
// described by either the env var CORSO_M365_TEST_UNLICENSED_USER, 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 UnlicensedM365UserID(t *testing.T) string {
cfg, err := readTestConfig()
require.NoError(t, err, "retrieving unlicensed m365 user id from test configuration", clues.ToCore(err))
return strings.ToLower(cfg[TestCfgSecondaryUserID])
}