test case for service not enabled

This commit is contained in:
neha-Gupta1 2023-05-16 19:40:45 +05:30
parent d8d9201eb8
commit c6b91654d6
2 changed files with 40 additions and 5 deletions

View File

@ -226,6 +226,13 @@ func runBackups(
err = bo.Run(ictx) err = bo.Run(ictx)
if err != nil { if err != nil {
if strings.Contains(err.Error(), graph.ErrServiceNotEnabled.Error()) {
logger.Ctx(ctx).Debugf("Service not enabled for creating backup for %s", bo.ResourceOwner.Name())
Infof(ictx, "%v\n", err)
continue
}
errs = append(errs, clues.Wrap(err, owner).WithClues(ictx)) errs = append(errs, clues.Wrap(err, owner).WithClues(ictx))
Errf(ictx, "%v\n", err) Errf(ictx, "%v\n", err)
@ -254,11 +261,6 @@ func runBackups(
sb := fmt.Sprintf("%d of %d backups failed:\n", len(errs), len(selectorSet)) sb := fmt.Sprintf("%d of %d backups failed:\n", len(errs), len(selectorSet))
for i, e := range errs { for i, e := range errs {
if strings.Contains(e.Error(), graph.ErrServiceNotEnabled.Error()) {
logger.Ctx(ctx).Debugf("Service not enabled for creating backup %d of %d", i+1, len(selectorSet))
continue
}
logger.CtxErr(ctx, e).Errorf("Backup %d of %d failed", i+1, len(selectorSet)) logger.CtxErr(ctx, e).Errorf("Backup %d of %d failed", i+1, len(selectorSet))
sb += "∙ " + e.Error() + "\n" sb += "∙ " + e.Error() + "\n"
} }

View File

@ -173,6 +173,39 @@ func runExchangeBackupCategoryTest(suite *BackupExchangeE2ESuite, category strin
assert.Contains(t, result, suite.m365UserID) assert.Contains(t, result, suite.m365UserID)
} }
func (suite *BackupExchangeE2ESuite) TestExchangeBackupCmd_ServiceNotEnables_email() {
runExchangeBackupServiceNotEnabledTest(suite, "email")
}
func runExchangeBackupServiceNotEnabledTest(suite *BackupExchangeE2ESuite, category string) {
recorder := strings.Builder{}
recorder.Reset()
t := suite.T()
ctx, flush := tester.NewContext()
ctx = config.SetViper(ctx, suite.vpr)
defer flush()
// run the command
cmd, ctx := buildExchangeBackupCmd(
ctx,
suite.cfgFP,
fmt.Sprintf("testevents@10rqc2.onmicrosoft.com,%s", suite.m365UserID),
category,
&recorder)
err := cmd.ExecuteContext(ctx)
require.NoError(t, err, clues.ToCore(err))
result := recorder.String()
t.Log("backup results", result)
// as an offhand check: the result should contain the m365 user id
assert.Contains(t, result, suite.m365UserID)
}
func (suite *BackupExchangeE2ESuite) TestExchangeBackupCmd_userNotFound_email() { func (suite *BackupExchangeE2ESuite) TestExchangeBackupCmd_userNotFound_email() {
runExchangeBackupUserNotFoundTest(suite, "email") runExchangeBackupUserNotFoundTest(suite, "email")
} }