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
|
||||
}
|
||||
|
||||
itemData := rc
|
||||
|
||||
// Add per item extensions if available
|
||||
if len(itemExtensionFactory) > 0 {
|
||||
extRc, extData, err := extensions.AddItemExtensions(
|
||||
ctx,
|
||||
rc,
|
||||
itemInfo,
|
||||
itemExtensionFactory)
|
||||
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
|
||||
extRc, extData, err := extensions.AddItemExtensions(
|
||||
ctx,
|
||||
rc,
|
||||
itemInfo,
|
||||
itemExtensionFactory)
|
||||
if err != nil {
|
||||
err := clues.Wrap(err, "adding extensions").Label(fault.LabelForceNoBackupCreation)
|
||||
el.AddRecoverable(ctx, err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
itemInfo.Extension.Data = extData.Data
|
||||
|
||||
// display/log the item download
|
||||
progReader, _ := observe.ItemProgress(
|
||||
ctx,
|
||||
itemData,
|
||||
extRc,
|
||||
observe.ItemBackupMsg,
|
||||
clues.Hide(itemName+dataSuffix),
|
||||
itemSize)
|
||||
|
||||
@ -936,7 +936,10 @@ func (suite *CollectionUnitTestSuite) TestItemExtensions() {
|
||||
mbh.GI = mock.GetsItem{Err: assert.AnError}
|
||||
mbh.GIP = mock.GetsItemPermission{Perm: models.NewPermissionCollectionResponse()}
|
||||
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{
|
||||
nil,
|
||||
|
||||
@ -21,7 +21,8 @@ type CreateItemExtensioner interface {
|
||||
|
||||
// AddItemExtensions wraps provided readcloser with extensions
|
||||
// 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(
|
||||
ctx context.Context,
|
||||
rc io.ReadCloser,
|
||||
@ -32,12 +33,14 @@ func AddItemExtensions(
|
||||
return nil, nil, clues.New("nil readcloser")
|
||||
}
|
||||
|
||||
// If no extensions were supplied, return the original readcloser
|
||||
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))
|
||||
|
||||
// Create extension data store to be passed to extensions
|
||||
extData := &details.ExtensionData{
|
||||
Data: make(map[string]any),
|
||||
}
|
||||
|
||||
@ -85,7 +85,7 @@ func (suite *ExtensionsUnitSuite) TestAddItemExtensions() {
|
||||
extData *details.ExtensionData,
|
||||
err error,
|
||||
) 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