2013-05-22 16:36:09 -04:00
|
|
|
package packer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"cgl.tideland.biz/asserts"
|
|
|
|
"errors"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMultiError_Impl(t *testing.T) {
|
|
|
|
var raw interface{}
|
|
|
|
raw = &MultiError{}
|
|
|
|
if _, ok := raw.(error); !ok {
|
|
|
|
t.Fatal("MultiError must implement error")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMultiErrorError(t *testing.T) {
|
|
|
|
assert := asserts.NewTestingAsserts(t, true)
|
|
|
|
|
|
|
|
expected := `2 error(s) occurred:
|
|
|
|
|
|
|
|
* foo
|
|
|
|
* bar`
|
|
|
|
|
|
|
|
errors := []error{
|
|
|
|
errors.New("foo"),
|
|
|
|
errors.New("bar"),
|
|
|
|
}
|
|
|
|
|
|
|
|
multi := &MultiError{errors}
|
|
|
|
assert.Equal(multi.Error(), expected, "should have proper error")
|
|
|
|
}
|
2013-07-19 18:14:50 -04:00
|
|
|
|
|
|
|
func TestMultiErrorAppend_MultiError(t *testing.T) {
|
|
|
|
original := &MultiError{
|
|
|
|
Errors: []error{errors.New("foo")},
|
|
|
|
}
|
|
|
|
|
|
|
|
result := MultiErrorAppend(original, errors.New("bar"))
|
|
|
|
if len(result.Errors) != 2 {
|
|
|
|
t.Fatalf("wrong len: %d", len(result.Errors))
|
|
|
|
}
|
2013-07-19 19:08:25 -04:00
|
|
|
|
|
|
|
original = &MultiError{}
|
|
|
|
result = MultiErrorAppend(original, errors.New("bar"))
|
|
|
|
if len(result.Errors) != 1 {
|
|
|
|
t.Fatalf("wrong len: %d", len(result.Errors))
|
|
|
|
}
|
2013-07-19 18:14:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestMultiErrorAppend_NonMultiError(t *testing.T) {
|
|
|
|
original := errors.New("foo")
|
|
|
|
result := MultiErrorAppend(original, errors.New("bar"))
|
|
|
|
if len(result.Errors) != 2 {
|
|
|
|
t.Fatalf("wrong len: %d", len(result.Errors))
|
|
|
|
}
|
|
|
|
}
|