Add HTTP /v1 MVC, TCP send path, groups with server-side member-avatar collage, object-storage upload, and friends/favorites around the architecture-v3 layout. Co-authored-by: Cursor <cursoragent@cursor.com>
40 lines
952 B
Go
40 lines
952 B
Go
package errs
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
func TestAppErrorIsAndWith(t *testing.T) {
|
|
err := ErrNotFound.WithMsg("user gone").WithInnerMsg("uid=9")
|
|
if !errors.Is(err, ErrNotFound) {
|
|
t.Fatal("Is by code")
|
|
}
|
|
if errors.Is(err, ErrUnauthorized) {
|
|
t.Fatal("different code")
|
|
}
|
|
if err.Msg != "user gone" || ErrNotFound.Msg == "user gone" {
|
|
t.Fatal("WithMsg must copy")
|
|
}
|
|
code, msg, inner := err.CodeMsg()
|
|
if code != "40401" || msg != "user gone" || inner != "uid=9" {
|
|
t.Fatalf("CodeMsg %s %s %s", code, msg, inner)
|
|
}
|
|
}
|
|
|
|
func TestFromRPCError(t *testing.T) {
|
|
if FromRPCError("s", nil) != nil {
|
|
t.Fatal("nil")
|
|
}
|
|
if got := FromRPCError("s", ErrBusy); !errors.Is(got, ErrBusy) {
|
|
t.Fatal("passthrough")
|
|
}
|
|
if got := FromRPCError("user", context.DeadlineExceeded); !errors.Is(got, ErrTimeout) {
|
|
t.Fatal("timeout")
|
|
}
|
|
if got := FromRPCError("user", errors.New("boom")); !errors.Is(got, ErrInner) {
|
|
t.Fatal("inner")
|
|
}
|
|
}
|