Skip to content

Commit

Permalink
add testcase in generic_error_test.go
Browse files Browse the repository at this point in the history
Signed-off-by: chchliang <[email protected]>
  • Loading branch information
chchliang committed Apr 18, 2017
1 parent 13a8c5d commit a23d7c2
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions libcontainer/generic_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}
}

0 comments on commit a23d7c2

Please sign in to comment.