[#878] Merge remote-tracking branch 'remotes/upstream/develop' into 878-activity...
[akkoma] / test / tasks / robots_txt_test.exs
1 defmodule Mix.Tasks.Pleroma.RobotsTxtTest do
2 use ExUnit.Case, async: true
3 alias Mix.Tasks.Pleroma.RobotsTxt
4
5 test "creates new dir" do
6 path = "test/fixtures/new_dir/"
7 file_path = path <> "robots.txt"
8
9 static_dir = Pleroma.Config.get([:instance, :static_dir])
10 Pleroma.Config.put([:instance, :static_dir], path)
11
12 on_exit(fn ->
13 Pleroma.Config.put([:instance, :static_dir], static_dir)
14 {:ok, ["test/fixtures/new_dir/", "test/fixtures/new_dir/robots.txt"]} = File.rm_rf(path)
15 end)
16
17 RobotsTxt.run(["disallow_all"])
18
19 assert File.exists?(file_path)
20 {:ok, file} = File.read(file_path)
21
22 assert file == "User-Agent: *\nDisallow: /\n"
23 end
24
25 test "to existance folder" do
26 path = "test/fixtures/"
27 file_path = path <> "robots.txt"
28 static_dir = Pleroma.Config.get([:instance, :static_dir])
29 Pleroma.Config.put([:instance, :static_dir], path)
30
31 on_exit(fn ->
32 Pleroma.Config.put([:instance, :static_dir], static_dir)
33 :ok = File.rm(file_path)
34 end)
35
36 RobotsTxt.run(["disallow_all"])
37
38 assert File.exists?(file_path)
39 {:ok, file} = File.read(file_path)
40
41 assert file == "User-Agent: *\nDisallow: /\n"
42 end
43 end