Something went wrong. Try again.
A command-line interface for tangled, the decentralized Git collaboration platform built on the AT Protocol. eric-wien.tngl.io/tng-cli
cli git atproto tangled
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172package api
import ( "errors" "testing" "time")
func TestAPIError_Error(t *testing.T) { tests := []struct { name string err *APIError want string }{ { name: "with message", err: &APIError{StatusCode: 403, ErrorType: "AuthRequired", Message: "token expired"}, want: "AuthRequired: token expired (HTTP 403)", }, { name: "without message", err: &APIError{StatusCode: 500, ErrorType: "InternalServerError"}, want: "InternalServerError (HTTP 500)", }, }
for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := tt.err.Error(); got != tt.want { t.Errorf("Error() = %q, want %q", got, tt.want) } }) }}
func TestAPIError_StatusChecks(t *testing.T) { e404 := &APIError{StatusCode: 404} e403 := &APIError{StatusCode: 403} e401 := &APIError{StatusCode: 401} e500 := &APIError{StatusCode: 500}
if !e404.IsNotFound() { t.Error("404 should be not found") } if e500.IsNotFound() { t.Error("500 should not be not found") } if !e403.IsForbidden() { t.Error("403 should be forbidden") } if !e401.IsUnauthorized() { t.Error("401 should be unauthorized") }}
func TestRateLimitError(t *testing.T) { inner := &APIError{StatusCode: 429, ErrorType: "RateLimited"} rl := &RateLimitError{RetryAfter: 30 * time.Second, Inner: inner}
if rl.Error() != "rate limited: retry after 30s" { t.Errorf("Error() = %q", rl.Error()) }
var apiErr *APIError if !errors.As(rl, &apiErr) { t.Error("RateLimitError should unwrap to APIError") } if apiErr.StatusCode != 429 { t.Errorf("unwrapped status = %d, want 429", apiErr.StatusCode) }}