From 4ba913d64157909c63cbeab38b6036a5e4beee53 Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Fri, 8 May 2020 18:51:16 +0300 Subject: [PATCH 1/8] {:error, :enoent} s3 fix s3 tests were executed before temp file was uploaded --- test/uploaders/s3_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/uploaders/s3_test.exs b/test/uploaders/s3_test.exs index 6950ccb25..d949c90a5 100644 --- a/test/uploaders/s3_test.exs +++ b/test/uploaders/s3_test.exs @@ -58,7 +58,7 @@ defmodule Pleroma.Uploaders.S3Test do name: "image-tet.jpg", content_type: "image/jpg", path: "test_folder/image-tet.jpg", - tempfile: Path.absname("test/fixtures/image_tmp.jpg") + tempfile: Path.absname("test/instance_static/add/shortcode.png") } [file_upload: file_upload] From 712055612f2696b2677f830be154e18f2396223d Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Mon, 11 May 2020 15:07:05 +0300 Subject: [PATCH 2/8] don't run tests which change env in async --- test/http/request_builder_test.exs | 14 ++--- .../admin_api/admin_api_controller_test.exs | 51 +++++++++---------- 2 files changed, 29 insertions(+), 36 deletions(-) diff --git a/test/http/request_builder_test.exs b/test/http/request_builder_test.exs index f11528c3f..fab909905 100644 --- a/test/http/request_builder_test.exs +++ b/test/http/request_builder_test.exs @@ -3,23 +3,19 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.HTTP.RequestBuilderTest do - use ExUnit.Case, async: true + use ExUnit.Case use Pleroma.Tests.Helpers - alias Pleroma.Config alias Pleroma.HTTP.Request alias Pleroma.HTTP.RequestBuilder describe "headers/2" do - setup do: clear_config([:http, :send_user_agent]) - setup do: clear_config([:http, :user_agent]) - test "don't send pleroma user agent" do assert RequestBuilder.headers(%Request{}, []) == %Request{headers: []} end test "send pleroma user agent" do - Config.put([:http, :send_user_agent], true) - Config.put([:http, :user_agent], :default) + clear_config([:http, :send_user_agent], true) + clear_config([:http, :user_agent], :default) assert RequestBuilder.headers(%Request{}, []) == %Request{ headers: [{"user-agent", Pleroma.Application.user_agent()}] @@ -27,8 +23,8 @@ defmodule Pleroma.HTTP.RequestBuilderTest do end test "send custom user agent" do - Config.put([:http, :send_user_agent], true) - Config.put([:http, :user_agent], "totally-not-pleroma") + clear_config([:http, :send_user_agent], true) + clear_config([:http, :user_agent], "totally-not-pleroma") assert RequestBuilder.headers(%Request{}, []) == %Request{ headers: [{"user-agent", "totally-not-pleroma"}] diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs index 4697af50e..94c59de9c 100644 --- a/test/web/admin_api/admin_api_controller_test.exs +++ b/test/web/admin_api/admin_api_controller_test.exs @@ -2862,26 +2862,25 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do group: ":pleroma", key: ":http", value: [ - %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "localhost", 1234]}]}, - %{"tuple" => [":send_user_agent", false]} + %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "localhost", 1234]}]} ] } ] }) - assert json_response(conn, 200) == %{ + assert %{ "configs" => [ %{ "group" => ":pleroma", "key" => ":http", - "value" => [ - %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "localhost", 1234]}]}, - %{"tuple" => [":send_user_agent", false]} - ], - "db" => [":proxy_url", ":send_user_agent"] + "value" => value, + "db" => db } ] - } + } = json_response(conn, 200) + + assert %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "localhost", 1234]}]} in value + assert ":proxy_url" in db end test "proxy tuple domain", %{conn: conn} do @@ -2892,26 +2891,25 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do group: ":pleroma", key: ":http", value: [ - %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "domain.com", 1234]}]}, - %{"tuple" => [":send_user_agent", false]} + %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "domain.com", 1234]}]} ] } ] }) - assert json_response(conn, 200) == %{ + assert %{ "configs" => [ %{ "group" => ":pleroma", "key" => ":http", - "value" => [ - %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "domain.com", 1234]}]}, - %{"tuple" => [":send_user_agent", false]} - ], - "db" => [":proxy_url", ":send_user_agent"] + "value" => value, + "db" => db } ] - } + } = json_response(conn, 200) + + assert %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "domain.com", 1234]}]} in value + assert ":proxy_url" in db end test "proxy tuple ip", %{conn: conn} do @@ -2922,26 +2920,25 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do group: ":pleroma", key: ":http", value: [ - %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "127.0.0.1", 1234]}]}, - %{"tuple" => [":send_user_agent", false]} + %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "127.0.0.1", 1234]}]} ] } ] }) - assert json_response(conn, 200) == %{ + assert %{ "configs" => [ %{ "group" => ":pleroma", "key" => ":http", - "value" => [ - %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "127.0.0.1", 1234]}]}, - %{"tuple" => [":send_user_agent", false]} - ], - "db" => [":proxy_url", ":send_user_agent"] + "value" => value, + "db" => db } ] - } + } = json_response(conn, 200) + + assert %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "127.0.0.1", 1234]}]} in value + assert ":proxy_url" in db end end From e0944dee993eec88f678e98de9382af82ca5a77a Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Mon, 11 May 2020 15:22:52 +0300 Subject: [PATCH 3/8] make test fail everytime --- test/web/feed/tag_controller_test.exs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/web/feed/tag_controller_test.exs b/test/web/feed/tag_controller_test.exs index d95aac108..d726300a9 100644 --- a/test/web/feed/tag_controller_test.exs +++ b/test/web/feed/tag_controller_test.exs @@ -82,6 +82,10 @@ defmodule Pleroma.Web.Feed.TagControllerTest do end test "gets a feed (RSS)", %{conn: conn} do + %{microsecond: {micro, _}} = DateTime.utc_now() + micro = (micro / 1000) |> floor() + Process.sleep(950 - micro) + Pleroma.Config.put( [:feed, :post_title], %{max_length: 25, omission: "..."} From ec27f346eebc99ff8bbc7d1e34c9559cf80b8691 Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Tue, 12 May 2020 12:12:10 +0300 Subject: [PATCH 4/8] correct order for publised in assert --- test/web/feed/tag_controller_test.exs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/test/web/feed/tag_controller_test.exs b/test/web/feed/tag_controller_test.exs index d726300a9..c3d83ef81 100644 --- a/test/web/feed/tag_controller_test.exs +++ b/test/web/feed/tag_controller_test.exs @@ -82,10 +82,6 @@ defmodule Pleroma.Web.Feed.TagControllerTest do end test "gets a feed (RSS)", %{conn: conn} do - %{microsecond: {micro, _}} = DateTime.utc_now() - micro = (micro / 1000) |> floor() - Process.sleep(950 - micro) - Pleroma.Config.put( [:feed, :post_title], %{max_length: 25, omission: "..."} @@ -142,8 +138,8 @@ defmodule Pleroma.Web.Feed.TagControllerTest do ] assert xpath(xml, ~x"//channel/item/pubDate/text()"sl) == [ - FeedView.pub_date(activity1.data["published"]), - FeedView.pub_date(activity2.data["published"]) + FeedView.pub_date(activity2.data["published"]), + FeedView.pub_date(activity1.data["published"]) ] assert xpath(xml, ~x"//channel/item/enclosure/@url"sl) == [ From b962b24e6f984dbec0089c80b22fac8f4f9c1fa4 Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Wed, 13 May 2020 08:00:17 +0300 Subject: [PATCH 5/8] don't run in async if tests depend on env config --- test/http/connection_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/http/connection_test.exs b/test/http/connection_test.exs index 5cc78ad5b..7c94a50b2 100644 --- a/test/http/connection_test.exs +++ b/test/http/connection_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.HTTP.ConnectionTest do - use ExUnit.Case, async: true + use ExUnit.Case use Pleroma.Tests.Helpers import ExUnit.CaptureLog From 12635bc15626dd7d2d4a02b9c8d763687a0d34ce Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Wed, 13 May 2020 09:20:25 +0300 Subject: [PATCH 6/8] don't use global mocks in setup callbacks --- test/activity_test.exs | 7 +++++-- .../mastodon_api/controllers/search_controller_test.exs | 2 +- test/web/push/impl_test.exs | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/test/activity_test.exs b/test/activity_test.exs index 0c19f481b..7c3f66da9 100644 --- a/test/activity_test.exs +++ b/test/activity_test.exs @@ -11,6 +11,11 @@ defmodule Pleroma.ActivityTest do alias Pleroma.ThreadMute import Pleroma.Factory + setup_all do + Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end) + :ok + end + test "returns an activity by it's AP id" do activity = insert(:note_activity) found_activity = Activity.get_by_ap_id(activity.data["id"]) @@ -107,8 +112,6 @@ defmodule Pleroma.ActivityTest do describe "search" do setup do - Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end) - user = insert(:user) params = %{ diff --git a/test/web/mastodon_api/controllers/search_controller_test.exs b/test/web/mastodon_api/controllers/search_controller_test.exs index 02476acb6..8b9459735 100644 --- a/test/web/mastodon_api/controllers/search_controller_test.exs +++ b/test/web/mastodon_api/controllers/search_controller_test.exs @@ -13,7 +13,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do import Tesla.Mock import Mock - setup do + setup_all do mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end) :ok end diff --git a/test/web/push/impl_test.exs b/test/web/push/impl_test.exs index b855d72ba..57b35061a 100644 --- a/test/web/push/impl_test.exs +++ b/test/web/push/impl_test.exs @@ -13,8 +13,8 @@ defmodule Pleroma.Web.Push.ImplTest do import Pleroma.Factory - setup_all do - Tesla.Mock.mock_global(fn + setup do + Tesla.Mock.mock(fn %{method: :post, url: "https://example.com/example/1234"} -> %Tesla.Env{status: 200} From 2c356a4bacc534702e9d1c1451fb351152c4bf7a Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Wed, 13 May 2020 09:29:41 +0300 Subject: [PATCH 7/8] don't use async with global mocks --- test/web/rel_me_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/web/rel_me_test.exs b/test/web/rel_me_test.exs index e05a8863d..65255916d 100644 --- a/test/web/rel_me_test.exs +++ b/test/web/rel_me_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.RelMeTest do - use ExUnit.Case, async: true + use ExUnit.Case setup_all do Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end) From fbe3d3aa5fe07a89c52a16b7bf0626e323366597 Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Wed, 13 May 2020 10:17:47 +0300 Subject: [PATCH 8/8] ignore order --- test/config/config_db_test.exs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/test/config/config_db_test.exs b/test/config/config_db_test.exs index 6b0e7b4b6..a8e947365 100644 --- a/test/config/config_db_test.exs +++ b/test/config/config_db_test.exs @@ -43,11 +43,9 @@ defmodule Pleroma.ConfigDBTest do {ConfigDB.from_string(saved.key), ConfigDB.from_binary(saved.value)} ] - assert config[:quack] == [ - level: :info, - meta: [:none], - webhook_url: "https://hooks.slack.com/services/KEY/some_val" - ] + assert config[:quack][:level] == :info + assert config[:quack][:meta] == [:none] + assert config[:quack][:webhook_url] == "https://hooks.slack.com/services/KEY/some_val" end describe "update_or_create/1" do