Replace RunTaskByKey with RunTask in Inspector

This commit is contained in:
Ken Hibino
2021-05-16 07:32:47 -07:00
parent 7eee841d63
commit 976d39676e
4 changed files with 186 additions and 34 deletions

View File

@@ -26,7 +26,7 @@ type Error struct {
Err error
}
func (e *Error) Error() string {
func (e *Error) DebugString() string {
var b strings.Builder
if e.Op != "" {
b.WriteString(string(e.Op))
@@ -46,6 +46,20 @@ func (e *Error) Error() string {
return b.String()
}
func (e *Error) Error() string {
var b strings.Builder
if e.Code != Unspecified {
b.WriteString(e.Code.String())
}
if e.Err != nil {
if b.Len() > 0 {
b.WriteString(": ")
}
b.WriteString(e.Err.Error())
}
return b.String()
}
func (e *Error) Unwrap() error {
return e.Err
}

View File

@@ -6,7 +6,9 @@ package errors
import "testing"
func TestErrorString(t *testing.T) {
func TestErrorDebugString(t *testing.T) {
// DebugString should include Op since its meant to be used by
// maintainers/contributors of the asynq package.
tests := []struct {
desc string
err error
@@ -24,6 +26,33 @@ func TestErrorString(t *testing.T) {
},
}
for _, tc := range tests {
if got := tc.err.(*Error).DebugString(); got != tc.want {
t.Errorf("%s: got=%q, want=%q", tc.desc, got, tc.want)
}
}
}
func TestErrorString(t *testing.T) {
// String method should omit Op since op is an internal detail
// and we don't want to provide it to users of the package.
tests := []struct {
desc string
err error
want string
}{
{
desc: "With Op, Code, and string",
err: E(Op("rdb.DeleteTask"), NotFound, "cannot find task with id=123"),
want: "NOT_FOUND: cannot find task with id=123",
},
{
desc: "With Op, Code and error",
err: E(Op("rdb.DeleteTask"), NotFound, &TaskNotFoundError{Queue: "default", ID: "123"}),
want: `NOT_FOUND: cannot find task with id=123 in queue "default"`,
},
}
for _, tc := range tests {
if got := tc.err.Error(); got != tc.want {
t.Errorf("%s: got=%q, want=%q", tc.desc, got, tc.want)