From 96031e8d1f7a45ab7063c85ffee7c536e29e72ba Mon Sep 17 00:00:00 2001 From: Glutexo Date: Sat, 4 Nov 2023 20:34:52 +0100 Subject: [PATCH 1/2] Change component name to lowercase Capitalized component names were only a remnant of camel-cased elixir modules. Now, with component names being separate, there is no need to follow this convention. Lower-case arguments are the easiest way to interact with an application. --- lib/cli.ex | 2 +- test/onigumo_cli_test.exs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/cli.ex b/lib/cli.ex index 1e2553a..e9d0c8e 100644 --- a/lib/cli.ex +++ b/lib/cli.ex @@ -1,6 +1,6 @@ defmodule Onigumo.CLI do @components %{ - :Downloader => Onigumo.Downloader + :downloader => Onigumo.Downloader } def main(argv) do diff --git a/test/onigumo_cli_test.exs b/test/onigumo_cli_test.exs index 9a54cd9..55d4f44 100644 --- a/test/onigumo_cli_test.exs +++ b/test/onigumo_cli_test.exs @@ -9,7 +9,7 @@ defmodule OnigumoCLITest do describe("Onigumo.CLI.main/1") do @tag :tmp_dir - test("run CLI with 'Downloader' argument", %{tmp_dir: tmp_dir}) do + test("run CLI with 'downloader' argument", %{tmp_dir: tmp_dir}) do expect(HTTPoisonMock, :start, fn -> nil end) expect(HTTPoisonMock, :get!, length(@urls), &HttpSupport.response/1) @@ -18,7 +18,7 @@ defmodule OnigumoCLITest do input_file_content = InputSupport.url_list(@urls) File.write!(input_path_tmp, input_file_content) File.cd(tmp_dir) - Onigumo.CLI.main(["Downloader"]) + Onigumo.CLI.main(["downloader"]) end test("run CLI with invalid argument") do From 643c10c797f255fa4f32846d1cd1725b75ff1092 Mon Sep 17 00:00:00 2001 From: Glutexo Date: Sat, 4 Nov 2023 20:55:08 +0100 Subject: [PATCH 2/2] Parametrize invalid argument test Added more tests for an invalid component argument: * Downloader with a capital D to test that the component namae is case-sensitive and lowercase. * uploader to test a completely unknown component, but in a valid (lowercase) format. --- test/onigumo_cli_test.exs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/onigumo_cli_test.exs b/test/onigumo_cli_test.exs index 55d4f44..a8a193a 100644 --- a/test/onigumo_cli_test.exs +++ b/test/onigumo_cli_test.exs @@ -7,6 +7,11 @@ defmodule OnigumoCLITest do "http://onigumo.local/bye.html" ] + @invalid_arguments [ + "Downloader", + "uploader" + ] + describe("Onigumo.CLI.main/1") do @tag :tmp_dir test("run CLI with 'downloader' argument", %{tmp_dir: tmp_dir}) do @@ -21,8 +26,10 @@ defmodule OnigumoCLITest do Onigumo.CLI.main(["downloader"]) end - test("run CLI with invalid argument") do - assert_raise(MatchError, fn -> Onigumo.CLI.main(["Uploader"]) end) + for argument <- @invalid_arguments do + test("run CLI with invalid argument #{inspect(argument)}") do + assert_raise(MatchError, fn -> Onigumo.CLI.main([unquote(argument)]) end) + end end test("run CLI with no arguments") do