Skip to content

Commit

Permalink
fix credo
Browse files Browse the repository at this point in the history
  • Loading branch information
KazuCocoa committed Nov 20, 2018
1 parent f617128 commit 472bfd4
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 28 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -11,4 +11,5 @@ sudo: false

script:
- MIX_ENV=test mix do compile --warnings-as-errors
- mix credo --strict
- mix test --cover
6 changes: 3 additions & 3 deletions lib/http_proxy/handle.ex
Expand Up @@ -14,11 +14,11 @@ defmodule HttpProxy.Handle do
alias Plug.Conn
alias Plug.Cowboy, as: PlugCowboy

alias HttpProxy.Play.Body, as: PlayBody
alias HttpProxy.Play.Data
alias HttpProxy.Record.Response, as: Record
alias HttpProxy.Play.Response, as: Play
alias HttpProxy.Play.Paths, as: PlayPaths
alias HttpProxy.Play.Body, as: PlayBody
alias HttpProxy.Play.Response, as: Play
alias HttpProxy.Record.Response, as: Record

alias JSX

Expand Down
6 changes: 2 additions & 4 deletions lib/http_proxy/play/data.ex
Expand Up @@ -4,8 +4,8 @@ defmodule HttpProxy.Play.Data do
The structure gets data via HttpProxy.Play.Response.play_responses.
"""

alias HttpProxy.Play.Response, as: HttpProxyResponse
alias HttpProxy.Agent, as: ProxyAgent
alias HttpProxy.Play.Response, as: HttpProxyResponse

@responses :play_responses

Expand Down Expand Up @@ -34,11 +34,9 @@ defmodule HttpProxy.Play.Data do
"response" => %{"body" => "<html>hello world 3</html>", "cookies" => %{},
"headers" => %{"Content-Type" => "text/html; charset=UTF-8",
"Server" => "GFE/2.0"}, "status_code" => 201}}
"""
@spec responses() :: binary
def responses(), do: response(ProxyAgent.get(@responses))
def responses, do: response(ProxyAgent.get(@responses))

defp response(nil) do
ProxyAgent.put(@responses, HttpProxyResponse.play_responses())
Expand Down
2 changes: 1 addition & 1 deletion lib/http_proxy/play/paths.ex
Expand Up @@ -4,8 +4,8 @@ defmodule HttpProxy.Play.Paths do
The structure gets paths as list via HttpProxy.Play.Response.play_paths.
"""

alias HttpProxy.Play.Response
alias HttpProxy.Agent, as: ProxyAgent
alias HttpProxy.Play.Response

@type path :: binary
@type paths :: [path]
Expand Down
6 changes: 3 additions & 3 deletions lib/http_proxy/play/response.ex
Expand Up @@ -18,14 +18,14 @@ defmodule HttpProxy.Play.Response do
MapSet.new()
)

alias HttpProxy.Utils.File, as: HttpProxyFile
alias HttpProxy.Play.Data
alias HttpProxy.Utils.File, as: HttpProxyFile

@spec play?() :: boolean
def play?(), do: Application.get_env(:http_proxy, :play, false)

@spec play_responses() :: [response_body] | []
def play_responses() do
def play_responses do
case play?() do
true ->
gen_response()
Expand All @@ -35,7 +35,7 @@ defmodule HttpProxy.Play.Response do
end
end

defp gen_response() do
defp gen_response do
HttpProxyFile.get_mapping_path()
|> HttpProxyFile.json_files!()
|> Enum.reduce([], fn path, acc ->
Expand Down
2 changes: 1 addition & 1 deletion lib/http_proxy/supervisor.ex
Expand Up @@ -4,8 +4,8 @@ defmodule HttpProxy.Supervisor do
"""

use Supervisor
alias HttpProxy.Handle
alias HttpProxy.Agent, as: ProxyAgent
alias HttpProxy.Handle

def start_link, do: Supervisor.start_link(__MODULE__, :ok, name: __MODULE__)

Expand Down
16 changes: 8 additions & 8 deletions lib/http_proxy/utils/file.ex
Expand Up @@ -47,7 +47,7 @@ defmodule HttpProxy.Utils.File do
"test/data/mappings"
"""
@spec get_export_path(integer | binary) :: String.t()
def get_export_path(), do: export_path() <> "/" <> mapping_files()
def get_export_path, do: export_path() <> "/" <> mapping_files()

def get_export_path(port) when is_integer(port),
do: export_path() <> "/" <> Integer.to_string(port) <> "/" <> mapping_files()
Expand All @@ -56,7 +56,7 @@ defmodule HttpProxy.Utils.File do
do: export_path() <> "/" <> port <> "/" <> mapping_files()

@spec get_export_binary_path(integer | binary) :: String.t()
def get_export_binary_path(), do: export_path() <> "/" <> response_files()
def get_export_binary_path, do: export_path() <> "/" <> response_files()

def get_export_binary_path(port) when is_integer(port),
do: export_path() <> "/" <> Integer.to_string(port) <> "/" <> response_files()
Expand All @@ -65,15 +65,15 @@ defmodule HttpProxy.Utils.File do
do: export_path() <> "/" <> port <> "/" <> response_files()

@spec get_response_path() :: String.t()
def get_response_path(), do: play_path() <> "/" <> response_files()
def get_response_path, do: play_path() <> "/" <> response_files()

@spec get_mapping_path() :: String.t()
def get_mapping_path(), do: play_path() <> "/" <> mapping_files()
def get_mapping_path, do: play_path() <> "/" <> mapping_files()

defp export_path(), do: Application.get_env(:http_proxy, :export_path, "default")
defp play_path(), do: Application.get_env(:http_proxy, :play_path, "default")
defp response_files(), do: %HttpProxyFile{}.response_files
defp mapping_files(), do: %HttpProxyFile{}.mapping_files
defp export_path, do: Application.get_env(:http_proxy, :export_path, "default")
defp play_path, do: Application.get_env(:http_proxy, :play_path, "default")
defp response_files, do: %HttpProxyFile{}.response_files
defp mapping_files, do: %HttpProxyFile{}.mapping_files

@doc ~S"""
Generate json file name with `:rand.uniform`
Expand Down
6 changes: 3 additions & 3 deletions test/http_proxy/http_test.exs
Expand Up @@ -4,8 +4,8 @@ defmodule HttpProxy.HttpTest do
use ExUnit.Parameterized
use Plug.Test

alias HttpProxy.TestHelper, as: TestHelper
alias HttpProxy.Handle, as: HttpProxyHandle
alias HttpProxy.TestHelper, as: TestHelper

test "files are created in record mode" do
File.rm_rf!(Application.get_env(:http_proxy, :export_path))
Expand Down Expand Up @@ -45,15 +45,15 @@ defmodule HttpProxy.HttpTest do
{:error, _} -> []
end

assert Enum.count(exported_files) == 0
assert exported_files == []

exported_body_files =
case File.ls("test/example/8080/__files") do
{:ok, files} -> files
{:error, _} -> []
end

assert Enum.count(exported_body_files) == 0
assert exported_body_files == []
end

test_with_params "play responses agains particular request", fn method, uri, expected_body ->
Expand Down
11 changes: 6 additions & 5 deletions test/http_proxy/play/response_test.exs
Expand Up @@ -2,9 +2,10 @@ defmodule HttpProxy.Play.ResponseTest do
use ExUnit.Case, async: true
use ExUnit.Parameterized

alias HttpProxy.Play.Response, as: Response
alias JSX

doctest HttpProxy.Play.Response
doctest Response

test "tewrong diff in request" do
json = ~s"""
Expand All @@ -25,7 +26,7 @@ defmodule HttpProxy.Play.ResponseTest do
"""

assert_raise ArgumentError, "Response jsons must include arrtibute: path_pattern path method ", fn ->
json |> JSX.decode! |> HttpProxy.Play.Response.validate
json |> JSX.decode! |> Response.validate
end
end

Expand All @@ -49,7 +50,7 @@ defmodule HttpProxy.Play.ResponseTest do
"""

assert_raise ArgumentError, "Response jsons must include arrtibute: body_file body ", fn ->
json |> JSX.decode! |> HttpProxy.Play.Response.validate
json |> JSX.decode! |> Response.validate
end
end

Expand All @@ -74,7 +75,7 @@ defmodule HttpProxy.Play.ResponseTest do
"""

assert_raise ArgumentError, "Response jsons must include arrtibute: path_pattern path ", fn ->
json |> JSX.decode! |> HttpProxy.Play.Response.validate
json |> JSX.decode! |> Response.validate
end
end

Expand All @@ -100,7 +101,7 @@ defmodule HttpProxy.Play.ResponseTest do
"""

assert_raise ArgumentError, "Response jsons must include arrtibute: body_file body ", fn ->
json |> JSX.decode! |> HttpProxy.Play.Response.validate
json |> JSX.decode! |> Response.validate
end
end
end

0 comments on commit 472bfd4

Please sign in to comment.