-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve PG unix sockets configuration (#4202)
* improve pg unix sockets configuration * changelog * don't use test env in config tests
- Loading branch information
1 parent
8a77968
commit b988364
Showing
3 changed files
with
117 additions
and
16 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
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
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 |
---|---|---|
|
@@ -347,6 +347,74 @@ defmodule Plausible.ConfigTest do | |
end | ||
end | ||
|
||
describe "postgres" do | ||
test "default" do | ||
env = [{"DATABASE_URL", nil}] | ||
config = runtime_config(env) | ||
|
||
assert get_in(config, [:plausible, Plausible.Repo]) == [ | ||
url: "postgres://postgres:postgres@plausible_db:5432/plausible_db", | ||
socket_options: [], | ||
ssl_opts: [ | ||
cacertfile: CAStore.file_path(), | ||
verify: :verify_peer, | ||
customize_hostname_check: [ | ||
match_fun: :public_key.pkix_verify_hostname_match_fun(:https) | ||
] | ||
] | ||
] | ||
end | ||
|
||
test "socket_dir in hostname" do | ||
env = [{"DATABASE_URL", "postgresql://postgres:postgres@%2Frun%2Fpostgresql/plausible_db"}] | ||
config = runtime_config(env) | ||
|
||
assert get_in(config, [:plausible, Plausible.Repo]) == [ | ||
socket_dir: "/run/postgresql", | ||
database: "plausible_db", | ||
username: "postgres", | ||
password: "postgres" | ||
] | ||
end | ||
|
||
test "socket_dir in query" do | ||
env = [{"DATABASE_URL", "postgresql:///plausible_db?host=/run/postgresql"}] | ||
config = runtime_config(env) | ||
|
||
assert get_in(config, [:plausible, Plausible.Repo]) == [ | ||
socket_dir: "/run/postgresql", | ||
database: "plausible_db" | ||
] | ||
end | ||
|
||
test "socket_dir missing" do | ||
env = [{"DATABASE_URL", "postgresql:///plausible_db"}] | ||
assert_raise ArgumentError, ~r/doesn't include host info/, fn -> runtime_config(env) end | ||
end | ||
|
||
test "custom URL" do | ||
env = [ | ||
{"DATABASE_URL", | ||
"postgresql://your_username:[email protected]:25060/defaultdb"} | ||
] | ||
|
||
config = runtime_config(env) | ||
|
||
assert get_in(config, [:plausible, Plausible.Repo]) == [ | ||
url: | ||
"postgresql://your_username:[email protected]:25060/defaultdb", | ||
socket_options: [], | ||
ssl_opts: [ | ||
cacertfile: CAStore.file_path(), | ||
verify: :verify_peer, | ||
customize_hostname_check: [ | ||
match_fun: :public_key.pkix_verify_hostname_match_fun(:https) | ||
] | ||
] | ||
] | ||
end | ||
end | ||
|
||
describe "extra config" do | ||
test "no-op when no extra path is set" do | ||
put_system_env_undo({"EXTRA_CONFIG_PATH", nil}) | ||
|