ci: add env vars to run clickhouse tests locally

This commit is contained in:
Shawn 2024-01-30 18:07:36 +08:00
parent 52cfeee2b1
commit 451c8ecaf5
2 changed files with 17 additions and 31 deletions

View File

@ -9,6 +9,7 @@
-define(APP, emqx_bridge_clickhouse).
-define(CLICKHOUSE_HOST, "clickhouse").
-define(CLICKHOUSE_PORT, "8123").
-include_lib("emqx_connector/include/emqx_connector.hrl").
%% See comment in
@ -20,9 +21,9 @@
%%------------------------------------------------------------------------------
init_per_suite(Config) ->
case
emqx_common_test_helpers:is_tcp_server_available(?CLICKHOUSE_HOST, ?CLICKHOUSE_DEFAULT_PORT)
of
Host = clickhouse_host(),
Port = list_to_integer(clickhouse_port()),
case emqx_common_test_helpers:is_tcp_server_available(Host, Port) of
true ->
emqx_common_test_helpers:render_and_load_app_config(emqx_conf),
ok = emqx_common_test_helpers:start_apps([emqx_conf, emqx_bridge]),
@ -114,13 +115,15 @@ sql_drop_table() ->
sql_create_database() ->
"CREATE DATABASE IF NOT EXISTS mqtt".
clickhouse_host() ->
os:getenv("CLICKHOUSE_HOST", ?CLICKHOUSE_HOST).
clickhouse_port() ->
os:getenv("CLICKHOUSE_PORT", ?CLICKHOUSE_PORT).
clickhouse_url() ->
erlang:iolist_to_binary([
<<"http://">>,
?CLICKHOUSE_HOST,
":",
erlang:integer_to_list(?CLICKHOUSE_DEFAULT_PORT)
]).
Host = clickhouse_host(),
Port = clickhouse_port(),
erlang:iolist_to_binary(["http://", Host, ":", Port]).
clickhouse_config(Config) ->
SQL = maps:get(sql, Config, sql_insert_template_for_bridge()),

View File

@ -13,7 +13,6 @@
-include_lib("common_test/include/ct.hrl").
-define(APP, emqx_bridge_clickhouse).
-define(CLICKHOUSE_HOST, "clickhouse").
-define(CLICKHOUSE_RESOURCE_MOD, emqx_bridge_clickhouse_connector).
-define(CLICKHOUSE_PASSWORD, "public").
@ -39,25 +38,17 @@ all() ->
groups() ->
[].
clickhouse_url() ->
erlang:iolist_to_binary([
<<"http://">>,
?CLICKHOUSE_HOST,
":",
erlang:integer_to_list(?CLICKHOUSE_DEFAULT_PORT)
]).
init_per_suite(Config) ->
case
emqx_common_test_helpers:is_tcp_server_available(?CLICKHOUSE_HOST, ?CLICKHOUSE_DEFAULT_PORT)
of
Host = emqx_bridge_clickhouse_SUITE:clickhouse_host(),
Port = list_to_integer(emqx_bridge_clickhouse_SUITE:clickhouse_port()),
case emqx_common_test_helpers:is_tcp_server_available(Host, Port) of
true ->
ok = emqx_common_test_helpers:start_apps([emqx_conf]),
ok = emqx_connector_test_helpers:start_apps([emqx_resource, ?APP]),
%% Create the db table
{ok, Conn} =
clickhouse:start_link([
{url, clickhouse_url()},
{url, emqx_bridge_clickhouse_SUITE:clickhouse_url()},
{user, <<"default">>},
{key, ?CLICKHOUSE_PASSWORD},
{pool, tmp_pool}
@ -205,15 +196,7 @@ clickhouse_config(Overrides) ->
username => <<"default">>,
password => <<?CLICKHOUSE_PASSWORD>>,
pool_size => 8,
url => iolist_to_binary(
io_lib:format(
"http://~s:~b",
[
?CLICKHOUSE_HOST,
?CLICKHOUSE_DEFAULT_PORT
]
)
),
url => emqx_bridge_clickhouse_SUITE:clickhouse_url(),
connect_timeout => <<"10s">>
},
#{<<"config">> => maps:merge(Config, Overrides)}.