From 72b3ec35f898b5eb2e69affee9c9569a8c2e0a0a Mon Sep 17 00:00:00 2001 From: Lain Soykaf Date: Tue, 3 Jan 2023 14:59:14 -0500 Subject: [PATCH 1/4] Fix warnings in tests, treat warnings as errors in CI. The warnings revealed two bad tests, the code still worked but the test didn't actually test for it. Activating this for CI to prevent issues like these in the future. --- .gitlab-ci.yml | 2 +- test/pleroma/user/import_test.exs | 1 - test/pleroma/user_search_test.exs | 1 - .../activity_pub/transmogrifier/emoji_react_handling_test.exs | 2 +- test/pleroma/web/mastodon_api/update_credentials_test.exs | 4 +++- test/test_helper.exs | 1 + 6 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8b0381d11..e35b4d29a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -85,7 +85,7 @@ unit-testing: script: - mix ecto.create - mix ecto.migrate - - mix test --cover --preload-modules + - mix test --cover --preload-modules --warnings-as-errors coverage: '/^Line total: ([^ ]*%)$/' artifacts: reports: diff --git a/test/pleroma/user/import_test.exs b/test/pleroma/user/import_test.exs index b4efd4bb0..f75305e0e 100644 --- a/test/pleroma/user/import_test.exs +++ b/test/pleroma/user/import_test.exs @@ -3,7 +3,6 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.User.ImportTest do - alias Pleroma.Repo alias Pleroma.Tests.ObanHelpers alias Pleroma.User diff --git a/test/pleroma/user_search_test.exs b/test/pleroma/user_search_test.exs index 1deab6888..1af9a1493 100644 --- a/test/pleroma/user_search_test.exs +++ b/test/pleroma/user_search_test.exs @@ -3,7 +3,6 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.UserSearchTest do - alias Pleroma.Repo alias Pleroma.User use Pleroma.DataCase diff --git a/test/pleroma/web/activity_pub/transmogrifier/emoji_react_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/emoji_react_handling_test.exs index 9d99df27c..83bf59c6f 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/emoji_react_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/emoji_react_handling_test.exs @@ -65,7 +65,7 @@ test "it works for incoming unqualified emoji reactions" do object = Object.get_by_ap_id(data["object"]) assert object.data["reaction_count"] == 1 - assert match?([[emoji, _]], object.data["reactions"]) + assert match?([[^emoji, _]], object.data["reactions"]) end test "it reject invalid emoji reactions" do diff --git a/test/pleroma/web/mastodon_api/update_credentials_test.exs b/test/pleroma/web/mastodon_api/update_credentials_test.exs index d5fac7e25..d4004bcb6 100644 --- a/test/pleroma/web/mastodon_api/update_credentials_test.exs +++ b/test/pleroma/web/mastodon_api/update_credentials_test.exs @@ -375,7 +375,9 @@ test "updates the user's background, upload_limit, returns a HTTP 413", %{ "pleroma_background_image" => new_background_oversized }) - assert user_response = json_response_and_validate_schema(res, 413) + assert %{"error" => "File is too large"} == json_response_and_validate_schema(res, 413) + + user = Repo.get(User, user.id) assert user.background == %{} clear_config([:instance, :upload_limit], upload_limit) diff --git a/test/test_helper.exs b/test/test_helper.exs index 60a61484f..046517b28 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -1,6 +1,7 @@ # Pleroma: A lightweight social networking server # Copyright © 2017-2022 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only +Code.put_compiler_option(:warnings_as_errors, true) os_exclude = if :os.type() == {:unix, :darwin}, do: [skip_on_mac: true], else: [] ExUnit.start(exclude: [:federated, :erratic] ++ os_exclude) From b3a1cfaa7a70315e2b295aac78c1404ab84410bf Mon Sep 17 00:00:00 2001 From: Lain Soykaf Date: Tue, 3 Jan 2023 15:39:14 -0500 Subject: [PATCH 2/4] Tests: Capture logs to clean up the test output. --- .../web/activity_pub/transmogrifier/note_handling_test.exs | 2 ++ .../web/admin_api/controllers/config_controller_test.exs | 1 + 2 files changed, 3 insertions(+) diff --git a/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs index 7c406fbd0..a9ad3e9c8 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs @@ -104,6 +104,7 @@ test "it does not fetch reply-to activities beyond max replies depth limit" do end end + @tag capture_log: true test "it does not crash if the object in inReplyTo can't be fetched" do data = File.read!("test/fixtures/mastodon-post-activity.json") @@ -723,6 +724,7 @@ test "the standalone note uses its own ID when context is missing" do assert modified.data["context"] == object.data["id"] end + @tag capture_log: true test "the reply note uses its parent's ID when context is missing and reply is unreachable" do insert(:user, ap_id: "https://mk.absturztau.be/users/8ozbzjs3o8") diff --git a/test/pleroma/web/admin_api/controllers/config_controller_test.exs b/test/pleroma/web/admin_api/controllers/config_controller_test.exs index 9ef7c0c46..9fb5fb520 100644 --- a/test/pleroma/web/admin_api/controllers/config_controller_test.exs +++ b/test/pleroma/web/admin_api/controllers/config_controller_test.exs @@ -316,6 +316,7 @@ test "create new config setting in db", %{conn: conn} do assert Application.get_env(:idna, :key5) == {"string", Pleroma.Captcha.NotReal, []} end + @tag capture_log: true test "save configs setting without explicit key", %{conn: conn} do adapter = Application.get_env(:http, :adapter) send_user_agent = Application.get_env(:http, :send_user_agent) From 2eec3f82072cc48443d10d52a48742924469cee1 Mon Sep 17 00:00:00 2001 From: Lain Soykaf Date: Tue, 3 Jan 2023 17:01:56 -0500 Subject: [PATCH 3/4] B TestHelper: Remove warnings-as-errors It's already set in mix.exs --- test/test_helper.exs | 1 - 1 file changed, 1 deletion(-) diff --git a/test/test_helper.exs b/test/test_helper.exs index 046517b28..60a61484f 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -1,7 +1,6 @@ # Pleroma: A lightweight social networking server # Copyright © 2017-2022 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only -Code.put_compiler_option(:warnings_as_errors, true) os_exclude = if :os.type() == {:unix, :darwin}, do: [skip_on_mac: true], else: [] ExUnit.start(exclude: [:federated, :erratic] ++ os_exclude) From 8583b3721d816805f926da667f361b8de235f941 Mon Sep 17 00:00:00 2001 From: Lain Soykaf Date: Thu, 9 Feb 2023 12:36:02 -0500 Subject: [PATCH 4/4] B TestHelper, CI: Work with older elixir version. --- .gitlab-ci.yml | 2 +- test/test_helper.exs | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e35b4d29a..8b0381d11 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -85,7 +85,7 @@ unit-testing: script: - mix ecto.create - mix ecto.migrate - - mix test --cover --preload-modules --warnings-as-errors + - mix test --cover --preload-modules coverage: '/^Line total: ([^ ]*%)$/' artifacts: reports: diff --git a/test/test_helper.exs b/test/test_helper.exs index 60a61484f..7727cffbc 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -2,6 +2,8 @@ # Copyright © 2017-2022 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only +Code.put_compiler_option(:warnings_as_errors, true) + os_exclude = if :os.type() == {:unix, :darwin}, do: [skip_on_mac: true], else: [] ExUnit.start(exclude: [:federated, :erratic] ++ os_exclude)