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

View File

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