c981ee9b9c947346d1e9e1e593ca7de861ed43be
[anni] / test / mix / pleroma_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Mix.PleromaTest do
6   use ExUnit.Case, async: true
7   import Mix.Pleroma
8
9   setup_all do
10     Mix.shell(Mix.Shell.Process)
11
12     on_exit(fn ->
13       Mix.shell(Mix.Shell.IO)
14     end)
15
16     :ok
17   end
18
19   describe "shell_prompt/1" do
20     test "input" do
21       send(self(), {:mix_shell_input, :prompt, "Yes"})
22
23       answer = shell_prompt("Do you want this?")
24       assert_received {:mix_shell, :prompt, [message]}
25       assert message =~ "Do you want this?"
26       assert answer == "Yes"
27     end
28
29     test "with defval" do
30       send(self(), {:mix_shell_input, :prompt, "\n"})
31
32       answer = shell_prompt("Do you want this?", "defval")
33
34       assert_received {:mix_shell, :prompt, [message]}
35       assert message =~ "Do you want this? [defval]"
36       assert answer == "defval"
37     end
38   end
39
40   describe "get_option/3" do
41     test "get from options" do
42       assert get_option([domain: "some-domain.com"], :domain, "Promt") == "some-domain.com"
43     end
44
45     test "get from prompt" do
46       send(self(), {:mix_shell_input, :prompt, "another-domain.com"})
47       assert get_option([], :domain, "Prompt") == "another-domain.com"
48     end
49   end
50 end