78a3f17b44f93d6c768ccfe9b4634d235694660f
[akkoma] / test / tasks / robots_txt_test.exs
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
5 defmodule Mix.Tasks.Pleroma.RobotsTxtTest do
6 use ExUnit.Case
7 alias Mix.Tasks.Pleroma.RobotsTxt
8
9 test "creates new dir" do
10 path = "test/fixtures/new_dir/"
11 file_path = path <> "robots.txt"
12
13 static_dir = Pleroma.Config.get([:instance, :static_dir])
14 Pleroma.Config.put([:instance, :static_dir], path)
15
16 on_exit(fn ->
17 Pleroma.Config.put([:instance, :static_dir], static_dir)
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 static_dir = Pleroma.Config.get([:instance, :static_dir])
33 Pleroma.Config.put([:instance, :static_dir], path)
34
35 on_exit(fn ->
36 Pleroma.Config.put([:instance, :static_dir], static_dir)
37 :ok = File.rm(file_path)
38 end)
39
40 RobotsTxt.run(["disallow_all"])
41
42 assert File.exists?(file_path)
43 {:ok, file} = File.read(file_path)
44
45 assert file == "User-Agent: *\nDisallow: /\n"
46 end
47 end