@@ -9,7 +9,9 @@ type AtomicError struct {
|
|||||||
|
|
||||||
// Set sets the error.
|
// Set sets the error.
|
||||||
func (ae *AtomicError) Set(err error) {
|
func (ae *AtomicError) Set(err error) {
|
||||||
ae.err.Store(err)
|
if err != nil {
|
||||||
|
ae.err.Store(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load returns the error.
|
// Load returns the error.
|
||||||
|
|||||||
@@ -17,6 +17,15 @@ func TestAtomicError(t *testing.T) {
|
|||||||
assert.Equal(t, errDummy, err.Load())
|
assert.Equal(t, errDummy, err.Load())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAtomicErrorSetNil(t *testing.T) {
|
||||||
|
var (
|
||||||
|
errNil error
|
||||||
|
err AtomicError
|
||||||
|
)
|
||||||
|
err.Set(errNil)
|
||||||
|
assert.Equal(t, errNil, err.Load())
|
||||||
|
}
|
||||||
|
|
||||||
func TestAtomicErrorNil(t *testing.T) {
|
func TestAtomicErrorNil(t *testing.T) {
|
||||||
var err AtomicError
|
var err AtomicError
|
||||||
assert.Nil(t, err.Load())
|
assert.Nil(t, err.Load())
|
||||||
|
|||||||
Reference in New Issue
Block a user