Merge pull request #1402 from chchliang/generictest

add testcase in generic_error_test.go
This commit is contained in:
Daniel, Dao Quang Minh 2017-04-18 11:42:24 +01:00 committed by GitHub
commit 9f1ef73ef9
1 changed files with 35 additions and 0 deletions

View File

@ -12,3 +12,38 @@ func TestErrorDetail(t *testing.T) {
t.Fatal(derr)
}
}
func TestErrorWithCode(t *testing.T) {
err := newGenericError(fmt.Errorf("test error"), SystemError)
if code := err.Code(); code != SystemError {
t.Fatalf("expected err code %q but %q", SystemError, code)
}
}
func TestErrorWithError(t *testing.T) {
cc := []struct {
errmsg string
cause string
}{
{
errmsg: "test error",
},
{
errmsg: "test error",
cause: "test",
},
}
for _, v := range cc {
err := newSystemErrorWithCause(fmt.Errorf(v.errmsg), v.cause)
msg := err.Error()
if v.cause == "" && msg != v.errmsg {
t.Fatalf("expected err(%q) equal errmsg(%q)", msg, v.errmsg)
}
if v.cause != "" && msg == v.errmsg {
t.Fatalf("unexpected err(%q) equal errmsg(%q)", msg, v.errmsg)
}
}
}