61f5833fc4962bd1562e237ef6fdc14b86bff6db
[akkoma] / test / tasks / instance_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.InstanceTest do
6 use ExUnit.Case
7
8 setup do
9 static_dir = Pleroma.Config.get([:instance, :static_dir])
10 File.mkdir_p!(tmp_path())
11
12 on_exit(fn ->
13 File.rm_rf(tmp_path())
14 static_dir = Pleroma.Config.get([:instance, :static_dir], "test/instance_static/")
15
16 if File.exists?(static_dir) do
17 File.rm_rf(Path.join(static_dir, "robots.txt"))
18 end
19
20 Pleroma.Config.put([:instance, :static_dir], static_dir)
21 end)
22
23 :ok
24 end
25
26 defp tmp_path do
27 "/tmp/generated_files/"
28 end
29
30 test "running gen" do
31 mix_task = fn ->
32 Mix.Tasks.Pleroma.Instance.run([
33 "gen",
34 "--output",
35 tmp_path() <> "generated_config.exs",
36 "--output-psql",
37 tmp_path() <> "setup.psql",
38 "--domain",
39 "test.pleroma.social",
40 "--instance-name",
41 "Pleroma",
42 "--admin-email",
43 "admin@example.com",
44 "--notify-email",
45 "notify@example.com",
46 "--dbhost",
47 "dbhost",
48 "--dbname",
49 "dbname",
50 "--dbuser",
51 "dbuser",
52 "--dbpass",
53 "dbpass",
54 "--indexable",
55 "y",
56 "--db-configurable",
57 "y",
58 "--rum",
59 "y",
60 "--listen-port",
61 "4000",
62 "--listen-ip",
63 "127.0.0.1",
64 "--uploads-dir",
65 "test/uploads",
66 "--static-dir",
67 "instance/static/"
68 ])
69 end
70
71 ExUnit.CaptureIO.capture_io(fn ->
72 mix_task.()
73 end)
74
75 generated_config = File.read!(tmp_path() <> "generated_config.exs")
76 assert generated_config =~ "host: \"test.pleroma.social\""
77 assert generated_config =~ "name: \"Pleroma\""
78 assert generated_config =~ "email: \"admin@example.com\""
79 assert generated_config =~ "notify_email: \"notify@example.com\""
80 assert generated_config =~ "hostname: \"dbhost\""
81 assert generated_config =~ "database: \"dbname\""
82 assert generated_config =~ "username: \"dbuser\""
83 assert generated_config =~ "password: \"dbpass\""
84 assert generated_config =~ "configurable_from_database: true"
85 assert generated_config =~ "http: [ip: {127, 0, 0, 1}, port: 4000]"
86 assert File.read!(tmp_path() <> "setup.psql") == generated_setup_psql()
87 end
88
89 defp generated_setup_psql do
90 ~s(CREATE USER dbuser WITH ENCRYPTED PASSWORD 'dbpass';\nCREATE DATABASE dbname OWNER dbuser;\n\\c dbname;\n--Extensions made by ecto.migrate that need superuser access\nCREATE EXTENSION IF NOT EXISTS citext;\nCREATE EXTENSION IF NOT EXISTS pg_trgm;\nCREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";\nCREATE EXTENSION IF NOT EXISTS rum;\n)
91 end
92 end