nil pointer protection in populateResource (#4489)
#### Does this PR need a docs update or release note? - [x] ⛔ No #### Type of change - [x] 🐛 Bugfix #### Test Plan - [x] ⚡ Unit test - [x] 💚 E2E
This commit is contained in:
parent
7b6484663b
commit
aa287131cf
@ -20,6 +20,8 @@ import (
|
|||||||
"github.com/alcionai/corso/src/pkg/services/m365/api"
|
"github.com/alcionai/corso/src/pkg/services/m365/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var ErrNoResourceLookup = clues.New("missing resource lookup client")
|
||||||
|
|
||||||
// must comply with BackupProducer and RestoreConsumer
|
// must comply with BackupProducer and RestoreConsumer
|
||||||
var (
|
var (
|
||||||
_ inject.BackupProducer = &Controller{}
|
_ inject.BackupProducer = &Controller{}
|
||||||
@ -290,6 +292,10 @@ func (ctrl *Controller) PopulateProtectedResourceIDAndName(
|
|||||||
resourceID string, // input value, can be either id or name
|
resourceID string, // input value, can be either id or name
|
||||||
ins idname.Cacher,
|
ins idname.Cacher,
|
||||||
) (idname.Provider, error) {
|
) (idname.Provider, error) {
|
||||||
|
if ctrl.ownerLookup == nil {
|
||||||
|
return nil, clues.Stack(ErrNoResourceLookup).WithClues(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
pr, err := ctrl.ownerLookup.GetResourceIDAndNameFrom(ctx, resourceID, ins)
|
pr, err := ctrl.ownerLookup.GetResourceIDAndNameFrom(ctx, resourceID, ins)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, clues.Wrap(err, "identifying resource owner")
|
return nil, clues.Wrap(err, "identifying resource owner")
|
||||||
|
|||||||
@ -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() {
|
func (suite *ControllerUnitSuite) TestController_Wait() {
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user