automatically log when we add a recoverable error or a skipped item to fault. This log will include a stack trace of the call from the location of the logged recoverable. Clues does not have a method for pulling a stack trace out of an error yet; that can be added at a future date. --- #### Does this PR need a docs update or release note? - [x] ⛔ No #### Type of change - [x] 🤖 Supportability/Tests #### Test Plan - [x] ⚡ Unit test - [x] 💚 E2E
105 lines
2.3 KiB
Go
105 lines
2.3 KiB
Go
package operations
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
"github.com/alcionai/corso/src/internal/tester"
|
|
"github.com/alcionai/corso/src/pkg/control"
|
|
"github.com/alcionai/corso/src/pkg/fault"
|
|
)
|
|
|
|
type HelpersUnitSuite struct {
|
|
tester.Suite
|
|
}
|
|
|
|
func TestHelpersUnitSuite(t *testing.T) {
|
|
suite.Run(t, &HelpersUnitSuite{Suite: tester.NewUnitSuite(t)})
|
|
}
|
|
|
|
func (suite *HelpersUnitSuite) TestFinalizeErrorHandling() {
|
|
table := []struct {
|
|
name string
|
|
errs func(context.Context) *fault.Bus
|
|
opts control.Options
|
|
expectErr assert.ErrorAssertionFunc
|
|
}{
|
|
{
|
|
name: "no errors",
|
|
errs: func(ctx context.Context) *fault.Bus {
|
|
return fault.New(false)
|
|
},
|
|
opts: control.Options{
|
|
FailureHandling: control.FailAfterRecovery,
|
|
},
|
|
expectErr: assert.NoError,
|
|
},
|
|
{
|
|
name: "already failed",
|
|
errs: func(ctx context.Context) *fault.Bus {
|
|
fn := fault.New(false)
|
|
fn.Fail(assert.AnError)
|
|
return fn
|
|
},
|
|
opts: control.Options{
|
|
FailureHandling: control.FailAfterRecovery,
|
|
},
|
|
expectErr: assert.Error,
|
|
},
|
|
{
|
|
name: "best effort",
|
|
errs: func(ctx context.Context) *fault.Bus {
|
|
fn := fault.New(false)
|
|
fn.AddRecoverable(ctx, assert.AnError)
|
|
return fn
|
|
},
|
|
opts: control.Options{
|
|
FailureHandling: control.BestEffort,
|
|
},
|
|
expectErr: assert.NoError,
|
|
},
|
|
{
|
|
name: "recoverable errors produce hard fail",
|
|
errs: func(ctx context.Context) *fault.Bus {
|
|
fn := fault.New(false)
|
|
fn.AddRecoverable(ctx, assert.AnError)
|
|
return fn
|
|
},
|
|
opts: control.Options{
|
|
FailureHandling: control.FailAfterRecovery,
|
|
},
|
|
expectErr: assert.Error,
|
|
},
|
|
{
|
|
name: "multiple recoverable errors produce hard fail",
|
|
errs: func(ctx context.Context) *fault.Bus {
|
|
fn := fault.New(false)
|
|
fn.AddRecoverable(ctx, assert.AnError)
|
|
fn.AddRecoverable(ctx, assert.AnError)
|
|
fn.AddRecoverable(ctx, assert.AnError)
|
|
return fn
|
|
},
|
|
opts: control.Options{
|
|
FailureHandling: control.FailAfterRecovery,
|
|
},
|
|
expectErr: assert.Error,
|
|
},
|
|
}
|
|
for _, test := range table {
|
|
suite.Run(test.name, func() {
|
|
t := suite.T()
|
|
|
|
ctx, flush := tester.NewContext(t)
|
|
defer flush()
|
|
|
|
errs := test.errs(ctx)
|
|
|
|
finalizeErrorHandling(ctx, test.opts, errs, "test")
|
|
test.expectErr(t, errs.Failure())
|
|
})
|
|
}
|
|
}
|