@@ -5,19 +5,23 @@ defmodule Phoenix.Sync.ApplicationTest do
55
66 Code . ensure_loaded! ( Support.ConfigTestRepo )
77
8- defp validate_repo_connection_opts! ( opts ) do
8+ defp validate_repo_connection_opts! ( opts , overrides \\ [ ] ) do
99 assert { pass_fun , connection_opts } = Keyword . pop! ( opts [ :connection_opts ] , :password )
1010
1111 assert pass_fun . ( ) == "password"
1212
13- assert connection_opts == [
14- username: "postgres" ,
15- hostname: "localhost" ,
16- database: "electric" ,
17- port: 54321 ,
18- sslmode: :require ,
19- ipv6: true
20- ]
13+ base_opts = [
14+ username: "postgres" ,
15+ hostname: "localhost" ,
16+ database: "electric" ,
17+ port: 5432 ,
18+ sslmode: :require ,
19+ ipv6: true
20+ ]
21+
22+ expected_opts = Keyword . merge ( base_opts , overrides )
23+
24+ assert Enum . sort ( connection_opts ) == Enum . sort ( expected_opts )
2125 end
2226
2327 describe "children/1" do
@@ -75,6 +79,35 @@ defmodule Phoenix.Sync.ApplicationTest do
7579 } = Map . new ( opts )
7680 end
7781
82+ test "with defined port" do
83+ original_config = Application . get_env ( :phoenix_sync , Support.ConfigTestRepo , [ ] )
84+
85+ override_port = 6543
86+
87+ config = [
88+ env: :dev ,
89+ repo: Support.ConfigTestRepo
90+ ]
91+
92+ try do
93+ Application . put_env (
94+ :phoenix_sync ,
95+ Support.ConfigTestRepo ,
96+ Keyword . put ( original_config , :port , override_port )
97+ )
98+
99+ assert { :ok , [ { Electric.StackSupervisor , opts } ] } = App . children ( config )
100+
101+ validate_repo_connection_opts! ( opts , port: override_port )
102+ after
103+ Application . put_env (
104+ :phoenix_sync ,
105+ Support.ConfigTestRepo ,
106+ original_config
107+ )
108+ end
109+ end
110+
78111 test "only repo config given and electric installed defaults to embedded" do
79112 config = [
80113 env: :dev ,
0 commit comments