1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Mix.Tasks.Pleroma.InstanceTest do
6 # Modifies the Application Environment, has to stay synchronous.
10 File.mkdir_p!(tmp_path())
13 File.rm_rf(tmp_path())
14 static_dir = Pleroma.Config.get([:instance, :static_dir], "test/instance_static/")
16 if File.exists?(static_dir) do
17 File.rm_rf(Path.join(static_dir, "robots.txt"))
21 # Is being modified by the mix task.
22 clear_config([:instance, :static_dir])
27 @uuid Ecto.UUID.generate()
29 "/tmp/generated_files/#{@uuid}/"
34 Mix.Tasks.Pleroma.Instance.run([
37 tmp_path() <> "generated_config.exs",
39 tmp_path() <> "setup.psql",
41 "test.pleroma.social",
69 "./test/../test/instance/static/",
70 "--strip-uploads-location",
72 "--read-uploads-description",
76 "--anonymize-uploads",
81 ExUnit.CaptureIO.capture_io(fn ->
85 generated_config = File.read!(tmp_path() <> "generated_config.exs")
86 assert generated_config =~ "host: \"test.pleroma.social\""
87 assert generated_config =~ "name: \"Pleroma\""
88 assert generated_config =~ "email: \"admin@example.com\""
89 assert generated_config =~ "notify_email: \"notify@example.com\""
90 assert generated_config =~ "hostname: \"dbhost\""
91 assert generated_config =~ "database: \"dbname\""
92 assert generated_config =~ "username: \"dbuser\""
93 assert generated_config =~ "password: \"dbpass\""
94 assert generated_config =~ "configurable_from_database: true"
95 assert generated_config =~ "http: [ip: {127, 0, 0, 1}, port: 4000]"
97 assert generated_config =~
98 "filters: [Pleroma.Upload.Filter.Exiftool.StripLocation, Pleroma.Upload.Filter.Exiftool.ReadDescription]"
100 assert File.read!(tmp_path() <> "setup.psql") == generated_setup_psql()
101 assert File.exists?(Path.expand("./test/instance/static/robots.txt"))
104 defp generated_setup_psql do
105 ~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)