-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conditionally skip test based on Elixir version
- Loading branch information
Showing
1 changed file
with
25 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |