Go boilerplate library for building atproto apps
atproto
go
1package atp
2
3import (
4 "errors"
5 "fmt"
6 "testing"
7)
8
9func TestWrapPDSError(t *testing.T) {
10 tests := []struct {
11 name string
12 input error
13 wantNil bool
14 wantExpired bool
15 }{
16 {"nil input", nil, true, false},
17 {"non-expired error", fmt.Errorf("some network error"), false, false},
18 {"invalid_grant", fmt.Errorf("token request: invalid_grant"), false, true},
19 {"failed refresh", fmt.Errorf("failed to refresh OAuth tokens"), false, true},
20 {"token expired", fmt.Errorf("token is expired"), false, true},
21 }
22 for _, tc := range tests {
23 t.Run(tc.name, func(t *testing.T) {
24 err := WrapPDSError(tc.input)
25 if tc.wantNil {
26 if err != nil {
27 t.Fatalf("expected nil, got %v", err)
28 }
29 return
30 }
31 if tc.wantExpired && !errors.Is(err, ErrSessionExpired) {
32 t.Fatalf("expected ErrSessionExpired, got %v", err)
33 }
34 if !tc.wantExpired && errors.Is(err, ErrSessionExpired) {
35 t.Fatal("should not wrap non-expired error as ErrSessionExpired")
36 }
37 })
38 }
39}