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

fix: dialyzer typespec issue with partial env #727

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions lib/tesla/test.ex
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ defmodule Tesla.Test do
@spec html(%Tesla.Env{}, binary) :: %Tesla.Env{}
def html(%Tesla.Env{} = env, body) when is_binary(body) do
env
|> Tesla.put_body(body)
|> Tesla.put_headers([{"content-type", "text/html; charset=utf-8"}])
|> put_body(body)
|> put_headers([{"content-type", "text/html; charset=utf-8"}])
end

@doc """
Expand All @@ -91,8 +91,8 @@ defmodule Tesla.Test do
body = encode!(body, "application/json")

env
|> Tesla.put_body(body)
|> Tesla.put_headers([{"content-type", "application/json; charset=utf-8"}])
|> put_body(body)
|> put_headers([{"content-type", "application/json; charset=utf-8"}])
end

@doc """
Expand All @@ -108,8 +108,8 @@ defmodule Tesla.Test do
@spec text(%Tesla.Env{}, binary) :: %Tesla.Env{}
def text(%Tesla.Env{} = env, body) when is_binary(body) do
env
|> Tesla.put_body(body)
|> Tesla.put_headers([{"content-type", "text/plain; charset=utf-8"}])
|> put_body(body)
|> put_headers([{"content-type", "text/plain; charset=utf-8"}])
end

@doc """
Expand Down Expand Up @@ -271,4 +271,16 @@ defmodule Tesla.Test do
adapter
end
end

defp put_body(%Tesla.Env{} = env, body) do
%{env | body: body}
end

defp put_headers(%Tesla.Env{headers: nil} = env, headers) when is_list(headers) do
%{env | headers: headers}
end

defp put_headers(%Tesla.Env{} = env, headers) when is_list(headers) do
%{env | headers: env.headers ++ headers}
end
end
Loading