2014-07-03 19:14:17 +02:00
|
|
|
package multierror
|
2014-07-03 06:00:06 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2014-07-03 19:14:17 +02:00
|
|
|
func TestError_Impl(t *testing.T) {
|
2014-07-03 06:00:06 +02:00
|
|
|
var raw interface{}
|
2014-07-03 19:14:17 +02:00
|
|
|
raw = &Error{}
|
2014-07-03 06:00:06 +02:00
|
|
|
if _, ok := raw.(error); !ok {
|
2014-07-03 19:14:17 +02:00
|
|
|
t.Fatal("Error must implement error")
|
2014-07-03 06:00:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-03 19:14:17 +02:00
|
|
|
func TestErrorError(t *testing.T) {
|
2014-07-03 06:00:06 +02:00
|
|
|
expected := `2 error(s) occurred:
|
|
|
|
|
|
|
|
* foo
|
|
|
|
* bar`
|
|
|
|
|
|
|
|
errors := []error{
|
|
|
|
errors.New("foo"),
|
|
|
|
errors.New("bar"),
|
|
|
|
}
|
|
|
|
|
2014-07-03 19:14:17 +02:00
|
|
|
multi := &Error{errors}
|
2014-07-03 06:00:06 +02:00
|
|
|
if multi.Error() != expected {
|
|
|
|
t.Fatalf("bad: %s", multi.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-03 19:14:17 +02:00
|
|
|
func TestErrorAppend_Error(t *testing.T) {
|
|
|
|
original := &Error{
|
2014-07-03 06:00:06 +02:00
|
|
|
Errors: []error{errors.New("foo")},
|
|
|
|
}
|
|
|
|
|
2014-07-03 19:14:17 +02:00
|
|
|
result := ErrorAppend(original, errors.New("bar"))
|
2014-07-03 06:00:06 +02:00
|
|
|
if len(result.Errors) != 2 {
|
|
|
|
t.Fatalf("wrong len: %d", len(result.Errors))
|
|
|
|
}
|
|
|
|
|
2014-07-03 19:14:17 +02:00
|
|
|
original = &Error{}
|
|
|
|
result = ErrorAppend(original, errors.New("bar"))
|
2014-07-03 06:00:06 +02:00
|
|
|
if len(result.Errors) != 1 {
|
|
|
|
t.Fatalf("wrong len: %d", len(result.Errors))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-03 19:14:17 +02:00
|
|
|
func TestErrorAppend_NonError(t *testing.T) {
|
2014-07-03 06:00:06 +02:00
|
|
|
original := errors.New("foo")
|
2014-07-03 19:14:17 +02:00
|
|
|
result := ErrorAppend(original, errors.New("bar"))
|
2014-07-03 06:00:06 +02:00
|
|
|
if len(result.Errors) != 2 {
|
|
|
|
t.Fatalf("wrong len: %d", len(result.Errors))
|
|
|
|
}
|
|
|
|
}
|