goadb/internal/errors/error_test.go
Zach Klippenstein 701ea3a245 Moved error definitions to an internal package, deleted the confusing util package.
Public API for error querying and formatting lives in top-level package.
2016-05-22 10:49:34 -07:00

45 lines
989 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package errors
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
func TestErrorWithCauseChain(t *testing.T) {
err := &Err{
Message: "err1",
Code: AssertionError,
Cause: &Err{
Message: "err2",
Code: AssertionError,
Cause: errors.New("err3"),
},
}
expected := `AssertionError: err1
caused by AssertionError: err2
caused by err3`
assert.Equal(t, expected, ErrorWithCauseChain(err))
assert.Equal(t, "<err=nil>", ErrorWithCauseChain(nil))
}
func TestCombineErrors(t *testing.T) {
assert.NoError(t, CombineErrs("hello", AdbError))
assert.NoError(t, CombineErrs("hello", AdbError, nil, nil))
err1 := errors.New("lulz")
err2 := errors.New("fail")
err := CombineErrs("hello", AdbError, nil, err1, nil)
assert.EqualError(t, err, "lulz")
err = CombineErrs("hello", AdbError, err1, err2)
assert.EqualError(t, err, "AdbError: hello")
assert.Equal(t, `AdbError: hello
caused by 2 errors: [lulz fail]`, ErrorWithCauseChain(err))
}