Convert tests to all use clear_config instead of Pleroma.Config.put
[akkoma] / test / mix / tasks / pleroma / robots_txt_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Mix.Tasks.Pleroma.RobotsTxtTest do
6 use ExUnit.Case
7 use Pleroma.Tests.Helpers
8 alias Mix.Tasks.Pleroma.RobotsTxt
9
10 setup do: clear_config([:instance, :static_dir])
11
12 test "creates new dir" do
13 path = "test/fixtures/new_dir/"
14 file_path = path <> "robots.txt"
15 clear_config([:instance, :static_dir], path)
16
17 on_exit(fn ->
18 {:ok, ["test/fixtures/new_dir/", "test/fixtures/new_dir/robots.txt"]} = File.rm_rf(path)
19 end)
20
21 RobotsTxt.run(["disallow_all"])
22
23 assert File.exists?(file_path)
24 {:ok, file} = File.read(file_path)
25
26 assert file == "User-Agent: *\nDisallow: /\n"
27 end
28
29 test "to existance folder" do
30 path = "test/fixtures/"
31 file_path = path <> "robots.txt"
32 clear_config([:instance, :static_dir], path)
33
34 on_exit(fn ->
35 :ok = File.rm(file_path)
36 end)
37
38 RobotsTxt.run(["disallow_all"])
39
40 assert File.exists?(file_path)
41 {:ok, file} = File.read(file_path)
42
43 assert file == "User-Agent: *\nDisallow: /\n"
44 end
45 end