(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func TestIsNeedUserAuthorizationError(t *testing.T) { |
| 13 | t.Run("nil error", func(t *testing.T) { |
| 14 | if IsNeedUserAuthorizationError(nil) { |
| 15 | t.Fatal("expected nil error not to match") |
| 16 | } |
| 17 | }) |
| 18 | |
| 19 | t.Run("direct auth error", func(t *testing.T) { |
| 20 | if !IsNeedUserAuthorizationError(&NeedAuthorizationError{UserOpenId: "u_1"}) { |
| 21 | t.Fatal("expected direct NeedAuthorizationError to match") |
| 22 | } |
| 23 | }) |
| 24 | |
| 25 | t.Run("typed missing-UAT error carries sentinel in cause", func(t *testing.T) { |
| 26 | // The typed constructor preserves the legacy sentinel in the Cause |
| 27 | // chain, so errors.As traverses into it. |
| 28 | if !IsNeedUserAuthorizationError(NewNeedUserAuthorizationError("u_1")) { |
| 29 | t.Fatal("expected typed missing-UAT error to match via its cause chain") |
| 30 | } |
| 31 | }) |
| 32 | |
| 33 | t.Run("other error", func(t *testing.T) { |
| 34 | err := errs.NewNetworkError(errs.SubtypeNetworkTransport, "API call failed: timeout") |
| 35 | if IsNeedUserAuthorizationError(err) { |
| 36 | t.Fatal("expected unrelated error not to match") |
| 37 | } |
| 38 | }) |
| 39 | } |
nothing calls this directly
no test coverage detected