Something went wrong. Try again.
Go boilerplate library for building atproto apps
atproto go
Something went wrong. Try again.
atp errors_test.go
1.0 kB · 39 lines
Go
at jetstream-v2
12345678910111213141516171819202122232425262728293031323334353637383940package atp
import ( "errors" "fmt" "testing")
func TestWrapPDSError(t *testing.T) { tests := []struct { name string input error wantNil bool wantExpired bool }{ {"nil input", nil, true, false}, {"non-expired error", fmt.Errorf("some network error"), false, false}, {"invalid_grant", fmt.Errorf("token request: invalid_grant"), false, true}, {"failed refresh", fmt.Errorf("failed to refresh OAuth tokens"), false, true}, {"token expired", fmt.Errorf("token is expired"), false, true}, } for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { err := WrapPDSError(tc.input) if tc.wantNil { if err != nil { t.Fatalf("expected nil, got %v", err) } return } if tc.wantExpired && !errors.Is(err, ErrSessionExpired) { t.Fatalf("expected ErrSessionExpired, got %v", err) } if !tc.wantExpired && errors.Is(err, ErrSessionExpired) { t.Fatal("should not wrap non-expired error as ErrSessionExpired") } }) }}