diff options
author | Haelwenn <contact+git.pleroma.social@hacktivis.me> | 2024-01-17 09:51:56 +0000 |
---|---|---|
committer | Haelwenn <contact+git.pleroma.social@hacktivis.me> | 2024-01-17 09:51:56 +0000 |
commit | 4c20713ecde9d429db937d3d66d4862bfb0456f5 (patch) | |
tree | 9f64c2f875f7f72b0728db95a9f4da60f308e284 /test/support/helpers.ex | |
parent | 9b39bc6aa8238ab2084f813d50210b75bd80e374 (diff) | |
parent | 355487041a610a2834eebca520660b74a667df06 (diff) | |
download | pleroma-4c20713ecde9d429db937d3d66d4862bfb0456f5.tar.gz pleroma-4c20713ecde9d429db937d3d66d4862bfb0456f5.zip |
Merge branch 'otp26' into 'develop'
OTP26 support
See merge request pleroma/pleroma!4025
Diffstat (limited to 'test/support/helpers.ex')
-rw-r--r-- | test/support/helpers.ex | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/support/helpers.ex b/test/support/helpers.ex index e3bfa73d2..7fa6c31a4 100644 --- a/test/support/helpers.ex +++ b/test/support/helpers.ex @@ -10,6 +10,39 @@ defmodule Pleroma.Tests.Helpers do require Logger + @doc "Accepts two URLs/URIs and sorts the query parameters before comparing" + def uri_equal?(a, b) do + a_sorted = uri_query_sort(a) + b_sorted = uri_query_sort(b) + + match?(^a_sorted, b_sorted) + end + + @doc "Accepts a URL/URI and sorts the query parameters" + def uri_query_sort(uri) do + parsed = URI.parse(uri) + + sorted_query = + String.split(parsed.query, "&") + |> Enum.sort() + |> Enum.join("&") + + parsed + |> Map.put(:query, sorted_query) + |> URI.to_string() + end + + @doc "Returns the value of the specified query parameter for the provided URL" + def get_query_parameter(url, param) do + url + |> URI.parse() + |> Map.get(:query) + |> URI.query_decoder() + |> Enum.to_list() + |> Enum.into(%{}, fn {x, y} -> {x, y} end) + |> Map.get(param) + end + defmacro clear_config(config_path) do quote do clear_config(unquote(config_path)) do |