fix unit tests
This commit is contained in:
parent
f88cf05117
commit
5593352226
@ -69,7 +69,7 @@ func New(
|
||||
DetailsID: detailsID,
|
||||
Status: status,
|
||||
Selector: selector,
|
||||
Errors: errs.Data(),
|
||||
Errors: errs.Errors(),
|
||||
ReadWrites: rw,
|
||||
StartAndEndTime: se,
|
||||
Version: Version,
|
||||
@ -156,12 +156,12 @@ func (b Backup) errorCount() int {
|
||||
}
|
||||
|
||||
// future tracking
|
||||
if b.Errors.Err != nil || len(b.Errors.Errs) > 0 {
|
||||
if b.Errors.Err != nil {
|
||||
if b.Errors.Failure != nil || len(b.Errors.Recovered) > 0 {
|
||||
if b.Errors.Failure != nil {
|
||||
errCount++
|
||||
}
|
||||
|
||||
errCount += len(b.Errors.Errs)
|
||||
errCount += len(b.Errors.Recovered)
|
||||
}
|
||||
|
||||
return errCount
|
||||
|
||||
@ -42,7 +42,7 @@ func stubBackup(t time.Time) backup.Backup {
|
||||
Status: "status",
|
||||
Selector: sel.Selector,
|
||||
Errors: fault.Errors{
|
||||
Errs: []error{errors.New("read"), errors.New("write")},
|
||||
Recovered: []error{errors.New("read"), errors.New("write")},
|
||||
},
|
||||
Errs: stats.Errs{
|
||||
ReadErrors: errors.New("1"),
|
||||
|
||||
@ -32,12 +32,8 @@ type Bus struct {
|
||||
// controls, allowing the data to be persisted.
|
||||
type Errors struct {
|
||||
Failure error `json:"failure"`
|
||||
Recovered []error `json:"recovered"`
|
||||
Recovered []error `json:"-"`
|
||||
FailFast bool `json:"failFast"`
|
||||
|
||||
// legacy support
|
||||
Err error `json:"err"`
|
||||
Errs []error `json:"errs"`
|
||||
}
|
||||
|
||||
// New constructs a new error with default values in place.
|
||||
@ -63,9 +59,9 @@ func (e *Bus) Recovered() []error {
|
||||
return e.recoverable
|
||||
}
|
||||
|
||||
// Data returns the plain record of errors that were aggregated
|
||||
// Errors returns the plain record of errors that were aggregated
|
||||
// within a fult Bus.
|
||||
func (e *Bus) Data() Errors {
|
||||
func (e *Bus) Errors() Errors {
|
||||
return Errors{
|
||||
Failure: e.failure,
|
||||
Recovered: slices.Clone(e.recoverable),
|
||||
|
||||
@ -177,7 +177,7 @@ func (suite *FaultErrorsUnitSuite) TestAdd() {
|
||||
assert.Len(t, n.Recovered(), 2)
|
||||
}
|
||||
|
||||
func (suite *FaultErrorsUnitSuite) TestData() {
|
||||
func (suite *FaultErrorsUnitSuite) TestErrors() {
|
||||
t := suite.T()
|
||||
|
||||
// not fail-fast
|
||||
@ -188,9 +188,9 @@ func (suite *FaultErrorsUnitSuite) TestData() {
|
||||
n.AddRecoverable(errors.New("1"))
|
||||
n.AddRecoverable(errors.New("2"))
|
||||
|
||||
d := n.Data()
|
||||
assert.Equal(t, n.Failure(), d.Err)
|
||||
assert.ElementsMatch(t, n.Recovered(), d.Errs)
|
||||
d := n.Errors()
|
||||
assert.Equal(t, n.Failure(), d.Failure)
|
||||
assert.ElementsMatch(t, n.Recovered(), d.Recovered)
|
||||
assert.False(t, d.FailFast)
|
||||
|
||||
// fail-fast
|
||||
@ -201,9 +201,9 @@ func (suite *FaultErrorsUnitSuite) TestData() {
|
||||
n.AddRecoverable(errors.New("1"))
|
||||
n.AddRecoverable(errors.New("2"))
|
||||
|
||||
d = n.Data()
|
||||
assert.Equal(t, n.Failure(), d.Err)
|
||||
assert.ElementsMatch(t, n.Recovered(), d.Errs)
|
||||
d = n.Errors()
|
||||
assert.Equal(t, n.Failure(), d.Failure)
|
||||
assert.ElementsMatch(t, n.Recovered(), d.Recovered)
|
||||
assert.True(t, d.FailFast)
|
||||
}
|
||||
|
||||
@ -217,14 +217,10 @@ func (suite *FaultErrorsUnitSuite) TestMarshalUnmarshal() {
|
||||
n.AddRecoverable(errors.New("1"))
|
||||
n.AddRecoverable(errors.New("2"))
|
||||
|
||||
data := n.Data()
|
||||
|
||||
jsonStr, err := json.Marshal(data)
|
||||
bs, err := json.Marshal(n.Errors())
|
||||
require.NoError(t, err)
|
||||
|
||||
um := fault.Errors{}
|
||||
|
||||
err = json.Unmarshal(jsonStr, &um)
|
||||
err = json.Unmarshal(bs, &fault.Errors{})
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user