Return original read closer if no extension factories are supplied (#3784)
<!-- PR description--> As title --- #### Does this PR need a docs update or release note? - [ ] ✅ Yes, it's included - [ ] 🕐 Yes, but in a later PR - [x] ⛔ No #### Type of change <!--- Please check the type of change your PR introduces: ---> - [ ] 🌻 Feature - [ ] 🐛 Bugfix - [ ] 🗺️ Documentation - [ ] 🤖 Supportability/Tests - [ ] 💻 CI/Deployment - [x] 🧹 Tech Debt/Cleanup #### Issue(s) <!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. --> * #<issue> #### Test Plan <!-- How will this be tested prior to merging.--> - [ ] 💪 Manual - [x] ⚡ Unit test - [x] 💚 E2E
This commit is contained in:
parent
3b9effdf93
commit
19d56b1e29
@ -539,29 +539,23 @@ func (oc *Collection) populateDriveItem(
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
itemData := rc
|
extRc, extData, err := extensions.AddItemExtensions(
|
||||||
|
ctx,
|
||||||
// Add per item extensions if available
|
rc,
|
||||||
if len(itemExtensionFactory) > 0 {
|
itemInfo,
|
||||||
extRc, extData, err := extensions.AddItemExtensions(
|
itemExtensionFactory)
|
||||||
ctx,
|
if err != nil {
|
||||||
rc,
|
err := clues.Wrap(err, "adding extensions").Label(fault.LabelForceNoBackupCreation)
|
||||||
itemInfo,
|
el.AddRecoverable(ctx, err)
|
||||||
itemExtensionFactory)
|
return nil, err
|
||||||
if err != nil {
|
|
||||||
err := clues.Wrap(err, "adding extensions").Label(fault.LabelForceNoBackupCreation)
|
|
||||||
el.AddRecoverable(ctx, err)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
itemData = extRc
|
|
||||||
itemInfo.Extension.Data = extData.Data
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
itemInfo.Extension.Data = extData.Data
|
||||||
|
|
||||||
// display/log the item download
|
// display/log the item download
|
||||||
progReader, _ := observe.ItemProgress(
|
progReader, _ := observe.ItemProgress(
|
||||||
ctx,
|
ctx,
|
||||||
itemData,
|
extRc,
|
||||||
observe.ItemBackupMsg,
|
observe.ItemBackupMsg,
|
||||||
clues.Hide(itemName+dataSuffix),
|
clues.Hide(itemName+dataSuffix),
|
||||||
itemSize)
|
itemSize)
|
||||||
|
|||||||
@ -936,7 +936,10 @@ func (suite *CollectionUnitTestSuite) TestItemExtensions() {
|
|||||||
mbh.GI = mock.GetsItem{Err: assert.AnError}
|
mbh.GI = mock.GetsItem{Err: assert.AnError}
|
||||||
mbh.GIP = mock.GetsItemPermission{Perm: models.NewPermissionCollectionResponse()}
|
mbh.GIP = mock.GetsItemPermission{Perm: models.NewPermissionCollectionResponse()}
|
||||||
mbh.GetResps = []*http.Response{
|
mbh.GetResps = []*http.Response{
|
||||||
{StatusCode: http.StatusOK, Body: io.NopCloser(strings.NewReader(string(test.payload)))},
|
{
|
||||||
|
StatusCode: http.StatusOK,
|
||||||
|
Body: io.NopCloser(strings.NewReader(string(test.payload))),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
mbh.GetErrs = []error{
|
mbh.GetErrs = []error{
|
||||||
nil,
|
nil,
|
||||||
|
|||||||
@ -21,7 +21,8 @@ type CreateItemExtensioner interface {
|
|||||||
|
|
||||||
// AddItemExtensions wraps provided readcloser with extensions
|
// AddItemExtensions wraps provided readcloser with extensions
|
||||||
// supplied via factory, with the first extension in slice being
|
// supplied via factory, with the first extension in slice being
|
||||||
// the innermost one.
|
// the innermost one. If no extensions are provided, the original
|
||||||
|
// readcloser is returned.
|
||||||
func AddItemExtensions(
|
func AddItemExtensions(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
rc io.ReadCloser,
|
rc io.ReadCloser,
|
||||||
@ -32,12 +33,14 @@ func AddItemExtensions(
|
|||||||
return nil, nil, clues.New("nil readcloser")
|
return nil, nil, clues.New("nil readcloser")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If no extensions were supplied, return the original readcloser
|
||||||
if len(factories) == 0 {
|
if len(factories) == 0 {
|
||||||
return nil, nil, clues.New("no extensions supplied")
|
return rc, &details.ExtensionData{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx = clues.Add(ctx, "num_extensions", len(factories))
|
ctx = clues.Add(ctx, "num_extensions", len(factories))
|
||||||
|
|
||||||
|
// Create extension data store to be passed to extensions
|
||||||
extData := &details.ExtensionData{
|
extData := &details.ExtensionData{
|
||||||
Data: make(map[string]any),
|
Data: make(map[string]any),
|
||||||
}
|
}
|
||||||
|
|||||||
@ -85,7 +85,7 @@ func (suite *ExtensionsUnitSuite) TestAddItemExtensions() {
|
|||||||
extData *details.ExtensionData,
|
extData *details.ExtensionData,
|
||||||
err error,
|
err error,
|
||||||
) bool {
|
) bool {
|
||||||
return err != nil && extRc == nil && extData == nil
|
return err == nil && extRc == testRc && extData != nil && extData.Data == nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user