diff --git a/libcontainer/generic_error_test.go b/libcontainer/generic_error_test.go index 292d2a36..8fbdd4d3 100644 --- a/libcontainer/generic_error_test.go +++ b/libcontainer/generic_error_test.go @@ -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) + } + + } +}