Skip to content

Commit

Permalink
Conditionally skip test based on Elixir version
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerWitt committed Jan 13, 2025
1 parent 29c4ccd commit 2429e2f
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions test/postgrex_test.exs
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
defmodule PostgrexTest do
use ExUnit.Case, async: false
import ExUnit.CaptureLog

test "start_link/2 sets search path" do
# valid argument
search_path = ["public", "extension"]
{:ok, conn} = Postgrex.start_link(database: "postgrex_test", search_path: search_path)
%{rows: [[result]]} = Postgrex.query!(conn, "show search_path", [])
assert result == Enum.join(search_path, ", ")
# This test fails due to a bug betweem Elixir and Erlang in earlier versions of Elixir.
if Version.match?(Version.parse!(System.version()), Version.parse_requirement!(">= 1.17.2")) do
import ExUnit.CaptureLog

# invalid argument
Process.flag(:trap_exit, true)
search_path = "public, extension"
test "start_link/2 sets search path" do
# valid argument
search_path = ["public", "extension"]
{:ok, conn} = Postgrex.start_link(database: "postgrex_test", search_path: search_path)
%{rows: [[result]]} = Postgrex.query!(conn, "show search_path", [])
assert result == Enum.join(search_path, ", ")

opts = [
database: "postgrex_test",
search_path: search_path,
show_sensitive_data_on_connection_error: true
]
# invalid argument
Process.flag(:trap_exit, true)
search_path = "public, extension"

error_log =
capture_log(fn ->
Postgrex.start_link(opts)
assert_receive {:EXIT, _, :killed}
end)
opts = [
database: "postgrex_test",
search_path: search_path,
show_sensitive_data_on_connection_error: true
]

assert error_log =~ "expected :search_path to be a list of strings, got: \"#{search_path}\""
error_log =
capture_log(fn ->
Postgrex.start_link(opts)
assert_receive {:EXIT, _, :killed}
end)

assert error_log =~ "expected :search_path to be a list of strings, got: \"#{search_path}\""
end
end
end

0 comments on commit 2429e2f

Please sign in to comment.