diff options
author | rinpatch <rinpatch@sdf.org> | 2020-12-01 19:45:25 +0300 |
---|---|---|
committer | rinpatch <rinpatch@sdf.org> | 2020-12-01 19:45:25 +0300 |
commit | fc9ebe5073a8ddb6633dc7d3b084307f0c17bcba (patch) | |
tree | 5a5b65954813ad75879c843475a29e19a4dc02b8 /test | |
parent | 5a5ff508aa47d5cf64f7be5938a9561e856854dd (diff) | |
download | pleroma-fc9ebe5073a8ddb6633dc7d3b084307f0c17bcba.tar.gz |
Search tests: Use on_exit for restoring `persistent_term` state
Otherwise if the assertion failed, the code below which resets the
state would never be reached
Diffstat (limited to 'test')
-rw-r--r-- | test/pleroma/activity/search_test.exs | 3 | ||||
-rw-r--r-- | test/pleroma/web/mastodon_api/controllers/search_controller_test.exs | 3 |
2 files changed, 2 insertions, 4 deletions
diff --git a/test/pleroma/activity/search_test.exs b/test/pleroma/activity/search_test.exs index 988949154..fc910e725 100644 --- a/test/pleroma/activity/search_test.exs +++ b/test/pleroma/activity/search_test.exs @@ -21,6 +21,7 @@ defmodule Pleroma.Activity.SearchTest do test "using plainto_tsquery on postgres < 11" do old_version = :persistent_term.get({Pleroma.Repo, :postgres_version}) :persistent_term.put({Pleroma.Repo, :postgres_version}, 10.0) + on_exit(fn -> :persistent_term.put({Pleroma.Repo, :postgres_version}, old_version) end) user = insert(:user) {:ok, post} = CommonAPI.post(user, %{status: "it's wednesday my dudes"}) @@ -30,8 +31,6 @@ defmodule Pleroma.Activity.SearchTest do assert [result] = Search.search(nil, "wednesday -dudes") assert result.id == post.id - - :persistent_term.put({Pleroma.Repo, :postgres_version}, old_version) end test "using websearch_to_tsquery" do diff --git a/test/pleroma/web/mastodon_api/controllers/search_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/search_controller_test.exs index 2f0bce450..1045ab265 100644 --- a/test/pleroma/web/mastodon_api/controllers/search_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/search_controller_test.exs @@ -281,6 +281,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do test "search fetches remote statuses and prefers them over other results", %{conn: conn} do old_version = :persistent_term.get({Pleroma.Repo, :postgres_version}) :persistent_term.put({Pleroma.Repo, :postgres_version}, 10.0) + on_exit(fn -> :persistent_term.put({Pleroma.Repo, :postgres_version}, old_version) end) capture_log(fn -> {:ok, %{id: activity_id}} = @@ -298,8 +299,6 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do %{"id" => ^activity_id} ] = results["statuses"] end) - - :persistent_term.put({Pleroma.Repo, :postgres_version}, old_version) end test "search doesn't show statuses that it shouldn't", %{conn: conn} do |