deprecate adder interface for only fault.Errors (#2378)
## Does this PR need a docs update or release note? - [x] ⛔ No ## Type of change - [x] 🧹 Tech Debt/Cleanup ## Issue(s) * #1970 ## Test Plan - [x] ⚡ Unit test - [x] 💚 E2E
This commit is contained in:
parent
34d822eb3b
commit
f33dbc6351
@ -135,13 +135,17 @@ func produceManifestsAndMetadata(
|
|||||||
// of manifests, that each manifest's Reason (owner, service, category) is only
|
// of manifests, that each manifest's Reason (owner, service, category) is only
|
||||||
// included once. If a reason is duplicated by any two manifests, an error is
|
// included once. If a reason is duplicated by any two manifests, an error is
|
||||||
// returned.
|
// returned.
|
||||||
func verifyDistinctBases(ctx context.Context, mans []*kopia.ManifestEntry, errs fault.Adder) error {
|
func verifyDistinctBases(ctx context.Context, mans []*kopia.ManifestEntry, errs *fault.Errors) error {
|
||||||
var (
|
var (
|
||||||
failed bool
|
failed bool
|
||||||
reasons = map[string]manifest.ID{}
|
reasons = map[string]manifest.ID{}
|
||||||
)
|
)
|
||||||
|
|
||||||
for _, man := range mans {
|
for _, man := range mans {
|
||||||
|
if errs.Failed() {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
// Incomplete snapshots are used only for kopia-assisted incrementals. The
|
// Incomplete snapshots are used only for kopia-assisted incrementals. The
|
||||||
// fact that we need this check here makes it seem like this should live in
|
// fact that we need this check here makes it seem like this should live in
|
||||||
// the kopia code. However, keeping it here allows for better debugging as
|
// the kopia code. However, keeping it here allows for better debugging as
|
||||||
@ -173,7 +177,7 @@ func verifyDistinctBases(ctx context.Context, mans []*kopia.ManifestEntry, errs
|
|||||||
return clues.New("multiple base snapshots qualify").WithClues(ctx)
|
return clues.New("multiple base snapshots qualify").WithClues(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return errs.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
// collectMetadata retrieves all metadata files associated with the manifest.
|
// collectMetadata retrieves all metadata files associated with the manifest.
|
||||||
|
|||||||
@ -15,7 +15,6 @@ import (
|
|||||||
"github.com/alcionai/corso/src/internal/tester"
|
"github.com/alcionai/corso/src/internal/tester"
|
||||||
"github.com/alcionai/corso/src/pkg/backup"
|
"github.com/alcionai/corso/src/pkg/backup"
|
||||||
"github.com/alcionai/corso/src/pkg/fault"
|
"github.com/alcionai/corso/src/pkg/fault"
|
||||||
"github.com/alcionai/corso/src/pkg/fault/mock"
|
|
||||||
"github.com/alcionai/corso/src/pkg/path"
|
"github.com/alcionai/corso/src/pkg/path"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -392,7 +391,7 @@ func (suite *OperationsManifestsUnitSuite) TestVerifyDistinctBases() {
|
|||||||
ctx, flush := tester.NewContext()
|
ctx, flush := tester.NewContext()
|
||||||
defer flush()
|
defer flush()
|
||||||
|
|
||||||
err := verifyDistinctBases(ctx, test.mans, mock.NewAdder())
|
err := verifyDistinctBases(ctx, test.mans, fault.New(true))
|
||||||
test.expect(t, err)
|
test.expect(t, err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -834,7 +833,7 @@ func (suite *BackupManifestSuite) TestBackupOperation_VerifyDistinctBases() {
|
|||||||
ctx, flush := tester.NewContext()
|
ctx, flush := tester.NewContext()
|
||||||
defer flush()
|
defer flush()
|
||||||
|
|
||||||
test.errCheck(t, verifyDistinctBases(ctx, test.input, mock.NewAdder()))
|
test.errCheck(t, verifyDistinctBases(ctx, test.input, fault.New(true)))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -102,11 +102,6 @@ func (e *Errors) setErr(err error) *Errors {
|
|||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
type Adder interface {
|
|
||||||
Add(err error) *Errors
|
|
||||||
Failed() bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add appends the error to the slice of recoverable and
|
// Add appends the error to the slice of recoverable and
|
||||||
// iterated errors (ie: errors.errs). If failFast is true,
|
// iterated errors (ie: errors.errs). If failFast is true,
|
||||||
// the first Added error will get copied to errors.err,
|
// the first Added error will get copied to errors.err,
|
||||||
|
|||||||
@ -1,22 +0,0 @@
|
|||||||
package mock
|
|
||||||
|
|
||||||
import "github.com/alcionai/corso/src/pkg/fault"
|
|
||||||
|
|
||||||
// Adder mocks an adder interface for testing.
|
|
||||||
type Adder struct {
|
|
||||||
FailFast bool
|
|
||||||
Errs []error
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewAdder() *Adder {
|
|
||||||
return &Adder{Errs: []error{}}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ma *Adder) Add(err error) *fault.Errors {
|
|
||||||
ma.Errs = append(ma.Errs, err)
|
|
||||||
return fault.New(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ma *Adder) Failed() bool {
|
|
||||||
return ma.FailFast && len(ma.Errs) > 0
|
|
||||||
}
|
|
||||||
@ -708,7 +708,7 @@ func (s ExchangeScope) setDefaults() {
|
|||||||
func (s exchange) Reduce(
|
func (s exchange) Reduce(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
deets *details.Details,
|
deets *details.Details,
|
||||||
errs fault.Adder,
|
errs *fault.Errors,
|
||||||
) *details.Details {
|
) *details.Details {
|
||||||
return reduce[ExchangeScope](
|
return reduce[ExchangeScope](
|
||||||
ctx,
|
ctx,
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import (
|
|||||||
"github.com/alcionai/corso/src/internal/common"
|
"github.com/alcionai/corso/src/internal/common"
|
||||||
"github.com/alcionai/corso/src/internal/tester"
|
"github.com/alcionai/corso/src/internal/tester"
|
||||||
"github.com/alcionai/corso/src/pkg/backup/details"
|
"github.com/alcionai/corso/src/pkg/backup/details"
|
||||||
"github.com/alcionai/corso/src/pkg/fault/mock"
|
"github.com/alcionai/corso/src/pkg/fault"
|
||||||
"github.com/alcionai/corso/src/pkg/filters"
|
"github.com/alcionai/corso/src/pkg/filters"
|
||||||
"github.com/alcionai/corso/src/pkg/path"
|
"github.com/alcionai/corso/src/pkg/path"
|
||||||
)
|
)
|
||||||
@ -1030,13 +1030,10 @@ func (suite *ExchangeSelectorSuite) TestExchangeRestore_Reduce() {
|
|||||||
ctx, flush := tester.NewContext()
|
ctx, flush := tester.NewContext()
|
||||||
defer flush()
|
defer flush()
|
||||||
|
|
||||||
errs := mock.NewAdder()
|
|
||||||
|
|
||||||
sel := test.makeSelector()
|
sel := test.makeSelector()
|
||||||
results := sel.Reduce(ctx, test.deets, errs)
|
results := sel.Reduce(ctx, test.deets, fault.New(true))
|
||||||
paths := results.Paths()
|
paths := results.Paths()
|
||||||
assert.Equal(t, test.expect, paths)
|
assert.Equal(t, test.expect, paths)
|
||||||
assert.Empty(t, errs.Errs)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -487,7 +487,7 @@ func (s OneDriveScope) DiscreteCopy(user string) OneDriveScope {
|
|||||||
func (s oneDrive) Reduce(
|
func (s oneDrive) Reduce(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
deets *details.Details,
|
deets *details.Details,
|
||||||
errs fault.Adder,
|
errs *fault.Errors,
|
||||||
) *details.Details {
|
) *details.Details {
|
||||||
return reduce[OneDriveScope](
|
return reduce[OneDriveScope](
|
||||||
ctx,
|
ctx,
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import (
|
|||||||
"github.com/alcionai/corso/src/internal/common"
|
"github.com/alcionai/corso/src/internal/common"
|
||||||
"github.com/alcionai/corso/src/internal/tester"
|
"github.com/alcionai/corso/src/internal/tester"
|
||||||
"github.com/alcionai/corso/src/pkg/backup/details"
|
"github.com/alcionai/corso/src/pkg/backup/details"
|
||||||
"github.com/alcionai/corso/src/pkg/fault/mock"
|
"github.com/alcionai/corso/src/pkg/fault"
|
||||||
"github.com/alcionai/corso/src/pkg/path"
|
"github.com/alcionai/corso/src/pkg/path"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -242,13 +242,10 @@ func (suite *OneDriveSelectorSuite) TestOneDriveRestore_Reduce() {
|
|||||||
ctx, flush := tester.NewContext()
|
ctx, flush := tester.NewContext()
|
||||||
defer flush()
|
defer flush()
|
||||||
|
|
||||||
errs := mock.NewAdder()
|
|
||||||
|
|
||||||
sel := test.makeSelector()
|
sel := test.makeSelector()
|
||||||
results := sel.Reduce(ctx, test.deets, errs)
|
results := sel.Reduce(ctx, test.deets, fault.New(true))
|
||||||
paths := results.Paths()
|
paths := results.Paths()
|
||||||
assert.Equal(t, test.expect, paths)
|
assert.Equal(t, test.expect, paths)
|
||||||
assert.Empty(t, errs.Errs)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -287,7 +287,7 @@ func reduce[T scopeT, C categoryT](
|
|||||||
deets *details.Details,
|
deets *details.Details,
|
||||||
s Selector,
|
s Selector,
|
||||||
dataCategories map[path.CategoryType]C,
|
dataCategories map[path.CategoryType]C,
|
||||||
errs fault.Adder,
|
errs *fault.Errors,
|
||||||
) *details.Details {
|
) *details.Details {
|
||||||
ctx, end := D.Span(ctx, "selectors:reduce")
|
ctx, end := D.Span(ctx, "selectors:reduce")
|
||||||
defer end()
|
defer end()
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
"github.com/alcionai/corso/src/internal/tester"
|
"github.com/alcionai/corso/src/internal/tester"
|
||||||
"github.com/alcionai/corso/src/pkg/backup/details"
|
"github.com/alcionai/corso/src/pkg/backup/details"
|
||||||
"github.com/alcionai/corso/src/pkg/fault/mock"
|
"github.com/alcionai/corso/src/pkg/fault"
|
||||||
"github.com/alcionai/corso/src/pkg/filters"
|
"github.com/alcionai/corso/src/pkg/filters"
|
||||||
"github.com/alcionai/corso/src/pkg/path"
|
"github.com/alcionai/corso/src/pkg/path"
|
||||||
)
|
)
|
||||||
@ -274,7 +274,7 @@ func (suite *SelectorScopesSuite) TestReduce() {
|
|||||||
ctx, flush := tester.NewContext()
|
ctx, flush := tester.NewContext()
|
||||||
defer flush()
|
defer flush()
|
||||||
|
|
||||||
errs := mock.NewAdder()
|
errs := fault.New(true)
|
||||||
|
|
||||||
ds := deets()
|
ds := deets()
|
||||||
result := reduce[mockScope](
|
result := reduce[mockScope](
|
||||||
@ -284,7 +284,7 @@ func (suite *SelectorScopesSuite) TestReduce() {
|
|||||||
dataCats,
|
dataCats,
|
||||||
errs)
|
errs)
|
||||||
require.NotNil(t, result)
|
require.NotNil(t, result)
|
||||||
require.Empty(t, errs.Errs, "iteration errors")
|
require.Empty(t, errs.Errs(), "recoverable errors")
|
||||||
assert.Len(t, result.Entries, test.expectLen)
|
assert.Len(t, result.Entries, test.expectLen)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -70,7 +70,7 @@ var (
|
|||||||
const All = "All"
|
const All = "All"
|
||||||
|
|
||||||
type Reducer interface {
|
type Reducer interface {
|
||||||
Reduce(context.Context, *details.Details, fault.Adder) *details.Details
|
Reduce(context.Context, *details.Details, *fault.Errors) *details.Details
|
||||||
}
|
}
|
||||||
|
|
||||||
// selectorResourceOwners aggregates all discrete path category types described
|
// selectorResourceOwners aggregates all discrete path category types described
|
||||||
@ -240,7 +240,7 @@ func (s Selector) PathService() path.ServiceType {
|
|||||||
func (s Selector) Reduce(
|
func (s Selector) Reduce(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
deets *details.Details,
|
deets *details.Details,
|
||||||
errs fault.Adder,
|
errs *fault.Errors,
|
||||||
) (*details.Details, error) {
|
) (*details.Details, error) {
|
||||||
r, err := selectorAsIface[Reducer](s)
|
r, err := selectorAsIface[Reducer](s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import (
|
|||||||
"github.com/alcionai/corso/src/internal/common"
|
"github.com/alcionai/corso/src/internal/common"
|
||||||
"github.com/alcionai/corso/src/internal/tester"
|
"github.com/alcionai/corso/src/internal/tester"
|
||||||
"github.com/alcionai/corso/src/pkg/backup/details"
|
"github.com/alcionai/corso/src/pkg/backup/details"
|
||||||
"github.com/alcionai/corso/src/pkg/fault/mock"
|
"github.com/alcionai/corso/src/pkg/fault"
|
||||||
"github.com/alcionai/corso/src/pkg/selectors"
|
"github.com/alcionai/corso/src/pkg/selectors"
|
||||||
"github.com/alcionai/corso/src/pkg/selectors/testdata"
|
"github.com/alcionai/corso/src/pkg/selectors/testdata"
|
||||||
)
|
)
|
||||||
@ -265,11 +265,8 @@ func (suite *SelectorReduceSuite) TestReduce() {
|
|||||||
|
|
||||||
for _, test := range table {
|
for _, test := range table {
|
||||||
suite.T().Run(test.name, func(t *testing.T) {
|
suite.T().Run(test.name, func(t *testing.T) {
|
||||||
errs := mock.NewAdder()
|
output := test.selFunc().Reduce(ctx, allDetails, fault.New(true))
|
||||||
|
|
||||||
output := test.selFunc().Reduce(ctx, allDetails, errs)
|
|
||||||
assert.ElementsMatch(t, test.expected, output.Entries)
|
assert.ElementsMatch(t, test.expected, output.Entries)
|
||||||
assert.Empty(t, errs.Errs)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -559,7 +559,7 @@ func (s SharePointScope) DiscreteCopy(site string) SharePointScope {
|
|||||||
func (s sharePoint) Reduce(
|
func (s sharePoint) Reduce(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
deets *details.Details,
|
deets *details.Details,
|
||||||
errs fault.Adder,
|
errs *fault.Errors,
|
||||||
) *details.Details {
|
) *details.Details {
|
||||||
return reduce[SharePointScope](
|
return reduce[SharePointScope](
|
||||||
ctx,
|
ctx,
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
"github.com/alcionai/corso/src/internal/tester"
|
"github.com/alcionai/corso/src/internal/tester"
|
||||||
"github.com/alcionai/corso/src/pkg/backup/details"
|
"github.com/alcionai/corso/src/pkg/backup/details"
|
||||||
"github.com/alcionai/corso/src/pkg/fault/mock"
|
"github.com/alcionai/corso/src/pkg/fault"
|
||||||
"github.com/alcionai/corso/src/pkg/path"
|
"github.com/alcionai/corso/src/pkg/path"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -306,13 +306,10 @@ func (suite *SharePointSelectorSuite) TestSharePointRestore_Reduce() {
|
|||||||
ctx, flush := tester.NewContext()
|
ctx, flush := tester.NewContext()
|
||||||
defer flush()
|
defer flush()
|
||||||
|
|
||||||
errs := mock.NewAdder()
|
|
||||||
|
|
||||||
sel := test.makeSelector()
|
sel := test.makeSelector()
|
||||||
results := sel.Reduce(ctx, test.deets, errs)
|
results := sel.Reduce(ctx, test.deets, fault.New(true))
|
||||||
paths := results.Paths()
|
paths := results.Paths()
|
||||||
assert.Equal(t, test.expect, paths)
|
assert.Equal(t, test.expect, paths)
|
||||||
assert.Empty(t, errs.Errs)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user