diff --git a/src/internal/m365/controller.go b/src/internal/m365/controller.go index 86444f059..6bcd5e27b 100644 --- a/src/internal/m365/controller.go +++ b/src/internal/m365/controller.go @@ -20,6 +20,8 @@ import ( "github.com/alcionai/corso/src/pkg/services/m365/api" ) +var ErrNoResourceLookup = clues.New("missing resource lookup client") + // must comply with BackupProducer and RestoreConsumer var ( _ inject.BackupProducer = &Controller{} @@ -290,6 +292,10 @@ func (ctrl *Controller) PopulateProtectedResourceIDAndName( resourceID string, // input value, can be either id or name ins idname.Cacher, ) (idname.Provider, error) { + if ctrl.ownerLookup == nil { + return nil, clues.Stack(ErrNoResourceLookup).WithClues(ctx) + } + pr, err := ctrl.ownerLookup.GetResourceIDAndNameFrom(ctx, resourceID, ins) if err != nil { return nil, clues.Wrap(err, "identifying resource owner") diff --git a/src/internal/m365/controller_test.go b/src/internal/m365/controller_test.go index 7f9e52ea5..2ae60d2ac 100644 --- a/src/internal/m365/controller_test.go +++ b/src/internal/m365/controller_test.go @@ -254,6 +254,18 @@ func (suite *ControllerUnitSuite) TestPopulateOwnerIDAndNamesFrom() { } } +func (suite *ControllerUnitSuite) TestPopulateOwnerIDAndNamesFrom_nilCheck() { + t := suite.T() + + ctx, flush := tester.NewContext(t) + defer flush() + + ctrl := &Controller{ownerLookup: nil} + + _, err := ctrl.PopulateProtectedResourceIDAndName(ctx, "", nil) + require.ErrorIs(t, err, ErrNoResourceLookup, clues.ToCore(err)) +} + func (suite *ControllerUnitSuite) TestController_Wait() { t := suite.T()