-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #159 from nappex/cli
Add test to invoke onigumo from CLI
- Loading branch information
Showing
5 changed files
with
65 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
defmodule OnigumoCLITest do | ||
use ExUnit.Case | ||
import Mox | ||
|
||
@urls [ | ||
"http://onigumo.local/hello.html", | ||
"http://onigumo.local/bye.html" | ||
] | ||
|
||
describe("Onigumo.CLI.main/1") do | ||
@tag :tmp_dir | ||
test("run Onigumo.CLI.main", %{tmp_dir: tmp_dir}) do | ||
expect(HTTPoisonMock, :start, fn -> nil end) | ||
expect(HTTPoisonMock, :get!, length(@urls), &HttpSupport.response/1) | ||
|
||
input_path_env = Application.get_env(:onigumo, :input_path) | ||
input_path_tmp = Path.join(tmp_dir, input_path_env) | ||
input_file_content = InputSupport.url_list(@urls) | ||
File.write!(input_path_tmp, input_file_content) | ||
File.cd(tmp_dir) | ||
Onigumo.CLI.main(["Downloader"]) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
defmodule HttpSupport do | ||
def response(url) do | ||
%HTTPoison.Response{ | ||
status_code: 200, | ||
body: body(url) | ||
} | ||
end | ||
|
||
def body(url) do | ||
"Body from: #{url}\n" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
defmodule InputSupport do | ||
def url_list(urls) do | ||
Enum.map(urls, &(&1 <> "\n")) | ||
|> Enum.join() | ||
end | ||
end |