Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.6KB

  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. defmodule Pleroma.InstanceTest do
  5. use ExUnit.Case, async: true
  6. setup do
  7. File.mkdir_p!(tmp_path())
  8. on_exit(fn ->
  9. File.rm_rf(tmp_path())
  10. static_dir = Pleroma.Config.get([:instance, :static_dir], "test/instance_static/")
  11. if File.exists?(static_dir) do
  12. File.rm_rf(Path.join(static_dir, "robots.txt"))
  13. end
  14. end)
  15. :ok
  16. end
  17. defp tmp_path do
  18. "/tmp/generated_files/"
  19. end
  20. test "running gen" do
  21. mix_task = fn ->
  22. Mix.Tasks.Pleroma.Instance.run([
  23. "gen",
  24. "--output",
  25. tmp_path() <> "generated_config.exs",
  26. "--output-psql",
  27. tmp_path() <> "setup.psql",
  28. "--domain",
  29. "test.pleroma.social",
  30. "--instance-name",
  31. "Pleroma",
  32. "--admin-email",
  33. "admin@example.com",
  34. "--notify-email",
  35. "notify@example.com",
  36. "--dbhost",
  37. "dbhost",
  38. "--dbname",
  39. "dbname",
  40. "--dbuser",
  41. "dbuser",
  42. "--dbpass",
  43. "dbpass",
  44. "--indexable",
  45. "y",
  46. "--db-configurable",
  47. "y",
  48. "--rum",
  49. "y",
  50. "--listen-port",
  51. "4000",
  52. "--listen-ip",
  53. "127.0.0.1",
  54. "--uploads-dir",
  55. "test/uploads",
  56. "--static-dir",
  57. "instance/static/"
  58. ])
  59. end
  60. ExUnit.CaptureIO.capture_io(fn ->
  61. mix_task.()
  62. end)
  63. generated_config = File.read!(tmp_path() <> "generated_config.exs")
  64. assert generated_config =~ "host: \"test.pleroma.social\""
  65. assert generated_config =~ "name: \"Pleroma\""
  66. assert generated_config =~ "email: \"admin@example.com\""
  67. assert generated_config =~ "notify_email: \"notify@example.com\""
  68. assert generated_config =~ "hostname: \"dbhost\""
  69. assert generated_config =~ "database: \"dbname\""
  70. assert generated_config =~ "username: \"dbuser\""
  71. assert generated_config =~ "password: \"dbpass\""
  72. assert generated_config =~ "dynamic_configuration: true"
  73. assert generated_config =~ "http: [ip: {127, 0, 0, 1}, port: 4000]"
  74. assert File.read!(tmp_path() <> "setup.psql") == generated_setup_psql()
  75. end
  76. defp generated_setup_psql do
  77. ~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)
  78. end
  79. end