2019-07-10 05:13:23 +00:00
# Pleroma: A lightweight social networking server
2023-01-01 11:11:47 +00:00
# Copyright © 2017-2023 Pleroma Authors <https://pleroma.social/>
2019-07-10 05:13:23 +00:00
# SPDX-License-Identifier: AGPL-3.0-only
2020-06-20 16:09:04 +00:00
defmodule Mix.Tasks.Pleroma.InstanceTest do
2020-12-21 11:59:11 +00:00
# Modifies the Application Environment, has to stay synchronous.
use Pleroma.DataCase
2019-04-10 10:57:41 +00:00
setup do
File . mkdir_p! ( tmp_path ( ) )
2019-09-25 10:13:35 +00:00
on_exit ( fn ->
File . rm_rf ( tmp_path ( ) )
2019-09-25 17:47:22 +00:00
static_dir = Pleroma.Config . get ( [ :instance , :static_dir ] , " test/instance_static/ " )
2019-09-25 10:13:35 +00:00
if File . exists? ( static_dir ) do
File . rm_rf ( Path . join ( static_dir , " robots.txt " ) )
end
end )
2020-12-21 11:59:11 +00:00
# Is being modified by the mix task.
clear_config ( [ :instance , :static_dir ] )
2019-04-10 10:57:41 +00:00
:ok
end
2020-12-21 11:21:40 +00:00
@uuid Ecto.UUID . generate ( )
2019-04-10 10:57:41 +00:00
defp tmp_path do
2020-12-21 11:21:40 +00:00
" /tmp/generated_files/ #{ @uuid } / "
2019-04-10 10:57:41 +00:00
end
test " running gen " do
mix_task = fn ->
Mix.Tasks.Pleroma.Instance . run ( [
" gen " ,
" --output " ,
tmp_path ( ) <> " generated_config.exs " ,
" --output-psql " ,
tmp_path ( ) <> " setup.psql " ,
" --domain " ,
" test.pleroma.social " ,
" --instance-name " ,
" Pleroma " ,
" --admin-email " ,
" admin@example.com " ,
" --notify-email " ,
" notify@example.com " ,
" --dbhost " ,
" dbhost " ,
" --dbname " ,
" dbname " ,
" --dbuser " ,
" dbuser " ,
" --dbpass " ,
" dbpass " ,
" --indexable " ,
2019-06-14 15:45:05 +00:00
" y " ,
" --db-configurable " ,
2019-07-09 19:57:41 +00:00
" y " ,
" --rum " ,
" y " ,
" --listen-port " ,
" 4000 " ,
" --listen-ip " ,
" 127.0.0.1 " ,
" --uploads-dir " ,
" test/uploads " ,
" --static-dir " ,
2020-10-12 16:18:39 +00:00
" ./test/../test/instance/static/ " ,
2022-02-20 12:46:29 +00:00
" --strip-uploads-location " ,
2020-10-12 16:18:39 +00:00
" y " ,
2022-02-20 11:59:42 +00:00
" --read-uploads-description " ,
2022-02-14 12:14:25 +00:00
" y " ,
2020-10-12 16:18:39 +00:00
" --dedupe-uploads " ,
" n " ,
" --anonymize-uploads " ,
2020-11-07 19:09:28 +00:00
" n "
2019-04-10 10:57:41 +00:00
] )
end
ExUnit.CaptureIO . capture_io ( fn ->
mix_task . ( )
end )
generated_config = File . read! ( tmp_path ( ) <> " generated_config.exs " )
assert generated_config =~ " host: \" test.pleroma.social \" "
assert generated_config =~ " name: \" Pleroma \" "
assert generated_config =~ " email: \" admin@example.com \" "
assert generated_config =~ " notify_email: \" notify@example.com \" "
assert generated_config =~ " hostname: \" dbhost \" "
assert generated_config =~ " database: \" dbname \" "
assert generated_config =~ " username: \" dbuser \" "
assert generated_config =~ " password: \" dbpass \" "
2020-01-10 16:34:19 +00:00
assert generated_config =~ " configurable_from_database: true "
2019-07-09 19:57:41 +00:00
assert generated_config =~ " http: [ip: {127, 0, 0, 1}, port: 4000] "
2022-02-14 12:14:25 +00:00
assert generated_config =~
2022-02-20 12:46:29 +00:00
" filters: [Pleroma.Upload.Filter.Exiftool.StripLocation, Pleroma.Upload.Filter.Exiftool.ReadDescription] "
2022-02-14 12:14:25 +00:00
2019-04-10 10:57:41 +00:00
assert File . read! ( tmp_path ( ) <> " setup.psql " ) == generated_setup_psql ( )
2020-05-20 18:16:40 +00:00
assert File . exists? ( Path . expand ( " ./test/instance/static/robots.txt " ) )
2019-04-10 10:57:41 +00:00
end
defp generated_setup_psql do
2019-07-09 19:57:41 +00:00
~s( CREATE USER dbuser WITH ENCRYPTED PASSWORD 'dbpass'; \n CREATE DATABASE dbname OWNER dbuser; \n \\ c dbname; \n --Extensions made by ecto.migrate that need superuser access \n CREATE EXTENSION IF NOT EXISTS citext; \n CREATE EXTENSION IF NOT EXISTS pg_trgm; \n CREATE EXTENSION IF NOT EXISTS \" uuid-ossp \" ; \n CREATE EXTENSION IF NOT EXISTS rum; \n )
2019-04-10 10:57:41 +00:00
end
end