Skip to content

Commit 95664f4

Browse files
committed
add and start using CLICKHOUSE_PASSWORD
1 parent e4fb189 commit 95664f4

File tree

6 files changed

+30
-15
lines changed

6 files changed

+30
-15
lines changed

.github/workflows/mix.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ jobs:
4646
- 8123:8123
4747
env:
4848
TZ: ${{ matrix.timezone }}
49+
CLICKHOUSE_PASSWORD: default
4950
options: >-
5051
--health-cmd nc -zw3 localhost 8124
5152
--health-interval 10s

test/ecto/adapters/clickhouse/migration_test.exs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
defmodule Ecto.Adapters.ClickHouse.MigrationTest do
22
use ExUnit.Case
3-
3+
import Ecto.Integration.Case, only: [client_opts: 1]
44
alias Ecto.Adapters.ClickHouse
55

66
defmodule MigrationRepo do
@@ -55,13 +55,15 @@ defmodule Ecto.Adapters.ClickHouse.MigrationTest do
5555

5656
test "events (table+index)" do
5757
database = "ecto_ch_migration_test_events"
58-
opts = [database: database]
58+
opts = client_opts(database: database)
5959

6060
assert :ok = ClickHouse.storage_up(opts)
6161
on_exit(fn -> ClickHouse.storage_down(opts) end)
6262

6363
Application.put_env(:migration_test, MigrationRepo,
6464
database: database,
65+
username: Keyword.fetch!(opts, :username),
66+
password: Keyword.fetch!(opts, :password),
6567
show_sensitive_data_on_connection_error: true
6668
)
6769

test/ecto/adapters/clickhouse/structure_test.exs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
defmodule Ecto.Adapters.ClickHouse.StructureTest do
22
use ExUnit.Case
3-
3+
import Ecto.Integration.Case, only: [client_opts: 1]
44
alias Ecto.Adapters.ClickHouse
55

66
defmodule Repo do
@@ -83,7 +83,7 @@ defmodule Ecto.Adapters.ClickHouse.StructureTest do
8383

8484
describe "structure_dump/1" do
8585
test "dump unknown db" do
86-
opts = [database: "ecto_ch_does_not_exist"]
86+
opts = client_opts(database: "ecto_ch_does_not_exist")
8787

8888
assert {:error, %Ch.Error{code: 81, message: message}} =
8989
ClickHouse.structure_dump("priv/repo", opts)
@@ -92,7 +92,7 @@ defmodule Ecto.Adapters.ClickHouse.StructureTest do
9292
end
9393

9494
test "dumps empty database" do
95-
opts = [database: "ecto_ch_temp_structure_empty"]
95+
opts = client_opts(database: "ecto_ch_temp_structure_empty")
9696

9797
assert :ok = ClickHouse.storage_up(opts)
9898
on_exit(fn -> ClickHouse.storage_down(opts) end)
@@ -105,13 +105,15 @@ defmodule Ecto.Adapters.ClickHouse.StructureTest do
105105

106106
test "dumps migrated database" do
107107
database = "ecto_ch_temp_structure_migrated"
108-
opts = [database: database]
108+
opts = client_opts(database: database)
109109

110110
assert :ok = ClickHouse.storage_up(opts)
111111
on_exit(fn -> ClickHouse.storage_down(opts) end)
112112

113113
Application.put_env(:structure_test, Repo,
114114
database: database,
115+
username: Keyword.fetch!(opts, :username),
116+
password: Keyword.fetch!(opts, :password),
115117
show_sensitive_data_on_connection_error: true
116118
)
117119

@@ -238,13 +240,15 @@ defmodule Ecto.Adapters.ClickHouse.StructureTest do
238240
describe "structure_load/2" do
239241
setup do
240242
database = "ecto_ch_temp_structure_load"
241-
opts = [database: database]
243+
opts = client_opts(database: database)
242244

243245
assert :ok = ClickHouse.storage_up(opts)
244246
on_exit(fn -> ClickHouse.storage_down(opts) end)
245247

246248
Application.put_env(:structure_test, Repo,
247249
database: database,
250+
username: Keyword.fetch!(opts, :username),
251+
password: Keyword.fetch!(opts, :password),
248252
show_sensitive_data_on_connection_error: true
249253
)
250254

test/ecto/adapters/clickhouse_test.exs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
defmodule Ecto.Adapters.ClickHouseTest do
22
use ExUnit.Case
3-
3+
import Ecto.Integration.Case, only: [client_opts: 1]
44
alias Ecto.Adapters.ClickHouse
55

66
describe "storage_up/1" do
77
test "create database" do
8-
opts = [database: "ecto_ch_temp_db"]
8+
opts = client_opts(database: "ecto_ch_temp_db")
99

1010
assert :ok = ClickHouse.storage_up(opts)
1111
on_exit(fn -> ClickHouse.storage_down(opts) end)
1212

13-
conn = start_supervised!(Ch)
13+
conn = start_supervised!({Ch, client_opts(database: "default")})
1414
assert {:ok, %{rows: rows}} = Ch.query(conn, "show databases")
1515
assert ["ecto_ch_temp_db"] in rows
1616
end
1717

1818
test "does not fail on second call" do
19-
opts = [database: "ecto_ch_temp_db_2"]
19+
opts = client_opts(database: "ecto_ch_temp_db_2")
2020

2121
assert :ok = ClickHouse.storage_up(opts)
2222
on_exit(fn -> ClickHouse.storage_down(opts) end)
@@ -33,12 +33,12 @@ defmodule Ecto.Adapters.ClickHouseTest do
3333

3434
describe "storage_down/1" do
3535
test "storage down (twice)" do
36-
opts = [database: "ecto_ch_temp_down_2"]
36+
opts = client_opts(database: "ecto_ch_temp_down_2")
3737

3838
assert :ok = ClickHouse.storage_up(opts)
3939
assert :ok = ClickHouse.storage_down(opts)
4040

41-
conn = start_supervised!(Ch)
41+
conn = start_supervised!({Ch, client_opts(database: "default")})
4242
assert {:ok, %{rows: rows}} = Ch.query(conn, "show databases")
4343
refute ["ecto_ch_temp_down_2"] in rows
4444

@@ -48,12 +48,12 @@ defmodule Ecto.Adapters.ClickHouseTest do
4848

4949
describe "storage_status/1" do
5050
test "when database is down" do
51-
opts = [database: "ecto_ch_temp_status_down"]
51+
opts = client_opts(database: "ecto_ch_temp_status_down")
5252
assert ClickHouse.storage_status(opts) == :down
5353
end
5454

5555
test "when database is up" do
56-
opts = [database: "ecto_ch_temp_status_up"]
56+
opts = client_opts(database: "ecto_ch_temp_status_up")
5757

5858
:ok = ClickHouse.storage_up(opts)
5959
on_exit(fn -> ClickHouse.storage_down(opts) end)

test/support/integration_case.ex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,10 @@ defmodule Ecto.Integration.Case do
4545
[[version]] = TestRepo.query!("select version()").rows
4646
version
4747
end
48+
49+
def client_opts(overrides \\ []) do
50+
TestRepo.config()
51+
|> Keyword.put(:pool_size, 1)
52+
|> Keyword.merge(overrides)
53+
end
4854
end

test/test_helper.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ alias Ecto.Integration.TestRepo
99
Application.put_env(:ecto_ch, TestRepo,
1010
adapter: Ecto.Adapters.ClickHouse,
1111
database: "ecto_ch_test",
12+
username: System.get_env("CLICKHOUSE_USER", "default"),
13+
password: System.get_env("CLICKHOUSE_PASSWORD", "default"),
1214
show_sensitive_data_on_connection_error: true
1315
)
1416

0 commit comments

Comments
 (0)