2019-04-10 11:57:41 +01:00
defmodule Pleroma.InstanceTest do
use ExUnit.Case , async : true
setup do
File . mkdir_p! ( tmp_path ( ) )
on_exit ( fn -> File . rm_rf ( tmp_path ( ) ) end )
:ok
end
defp tmp_path do
" /tmp/generated_files/ "
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 16:45:05 +01:00
" y " ,
" --db-configurable " ,
2019-04-10 11:57:41 +01:00
" y "
] )
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 \" "
2019-06-14 16:45:05 +01:00
assert generated_config =~ " dynamic_configuration: true "
2019-04-10 11:57:41 +01:00
assert File . read! ( tmp_path ( ) <> " setup.psql " ) == generated_setup_psql ( )
end
defp generated_setup_psql do
~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 )
end
end