Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Req.Test fails to handle plug result if into: :self #440

Closed
mruoss opened this issue Dec 3, 2024 · 2 comments
Closed

Req.Test fails to handle plug result if into: :self #440

mruoss opened this issue Dec 3, 2024 · 2 comments

Comments

@mruoss
Copy link

mruoss commented Dec 3, 2024

I try to run the following code:

Req.Test.stub(:foo, fn conn -> Req.Test.text(conn, "okay") end)
Req.get!(base_url: "http://www.example.com", into: :self, plug: {Req.Test, :foo})

This raises the following exception:

** (Protocol.UndefinedError) protocol Collectable not implemented for :self of type Atom. This protocol is implemented for the following type(s): BitString, File.Stream, HashDict, HashSet, IO.Stream, List, Map, MapSet, Mix.Shell, Req.Utils.CollectWithHash
    (elixir 1.17.2) lib/collectable.ex:1: Collectable.impl_for!/1
    (elixir 1.17.2) lib/collectable.ex:92: Collectable.into/1
    (req 0.5.8) lib/req/steps.ex:1046: Req.Steps.handle_plug_result/2
    (req 0.5.8) lib/req/request.ex:1106: Req.Request.run_request/1
    (req 0.5.8) lib/req/request.ex:1050: Req.Request.run/1
    (req 0.5.8) lib/req.ex:1106: Req.request!/2
    #cell:pxciqv2ibo257vwc:3: (file)

Looking at the case stmt in lib/req/steps.ex:1001, :self is really missing. Was this done on purpose?

@wojtekmach
Copy link
Owner

wojtekmach commented Dec 3, 2024

Thank you for the report, fixed on main. Note due to limitations of Plug.Test even if response has multiple chunks (e.g. calling Plug.Conn.chunk/2 multiple times), we'd receive just one {:data, body} message with the entire response body. I hope to maybe improve that aspect in the future (elixir-plug/plug#1160).

@mruoss
Copy link
Author

mruoss commented Dec 3, 2024

This is good enough for me. Thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants