Skip to content

Commit

Permalink
test cover == 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongwencool committed Dec 9, 2016
1 parent 54b2481 commit 6ad326e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 8 additions & 0 deletions test/maxwell/conn_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ defmodule ConnTest do
assert put_query_string(%Conn{state: :unsent}, "name", "foo") == %Conn{state: :unsent, query_string: %{"name" => "foo"}}
assert put_query_string(%Conn{state: :unsent}, %{"name" => "foo", "passwd" => "123"})
== %Conn{state: :unsent, query_string: %{"name" => "foo", "passwd" => "123"}}

assert_raise AlreadySentError, "the request was already sent", fn ->
put_query_string(%Conn{state: :sent}, %{"name" => "foo"})
end
assert_raise AlreadySentError, "the request was already sent", fn ->
put_query_string(%Conn{state: :sent}, "name", "foo")
end
Expand All @@ -34,6 +38,10 @@ defmodule ConnTest do
== %Conn{state: :unsent, req_headers: %{"cache-control" => "no-cache"}}
assert put_req_header(%Conn{state: :unsent}, %{"cache-control" => "no-cache", "ETag" => "rFjdsDtv2qxk7K1CwG4VMlF836E="})
== %Conn{state: :unsent, req_headers: %{"cache-control" => "no-cache", "ETag" => "rFjdsDtv2qxk7K1CwG4VMlF836E="}}

assert_raise AlreadySentError, "the request was already sent", fn ->
put_req_header(%Conn{state: :sent}, %{"cache-control" => "no-cache"})
end
assert_raise AlreadySentError, "the request was already sent", fn ->
put_req_header(%Conn{state: :sent}, "cache-control", "no-cache")
end
Expand Down
10 changes: 8 additions & 2 deletions test/maxwell/middleware/json_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ defmodule JsonTest do
{:ok,
%{conn| status: 200, resp_headers: %{"Content-Type" => "text/html"}, resp_body: "{\"value\": 124}"}};
"/not_found_404" ->
{:ok, %{conn|status: 404, resp_body: "404 Not Found"}};
{:ok, %{conn| status: 404, resp_body: "404 Not Found"}}
"/redirection_301" ->
{:ok, %{conn|status: 301, resp_body: "301 Moved Permanently"}};
{:ok, %{conn| status: 301, resp_body: "301 Moved Permanently"}}
"/error" ->
{:error, "hahahaha"}
_ ->
{:ok, %{conn| status: 200}}
end
end
end
Expand Down Expand Up @@ -82,6 +84,10 @@ defmodule JsonTest do
assert body == %{"baz" => "bar"}
end

test "do not encode tuple body" do
assert Conn.put_req_body({:key, :vaule}) |> Client.post!|> Conn.get_status == 200
end

test "/use-defined-content-type" do
body =
"/use-defined-content-type"
Expand Down

0 comments on commit 6ad326e

Please sign in to comment.