logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

instance_test.exs (2825B)


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