ci: add env vars to run cassandra tests locally
This commit is contained in:
parent
8c978ccbf3
commit
29d767bd62
|
@ -39,6 +39,10 @@ services:
|
|||
- 19042:9042
|
||||
# Cassandra TLS
|
||||
- 19142:9142
|
||||
# Cassandra No Auth
|
||||
- 19043:9043
|
||||
# Cassandra TLS No Auth
|
||||
- 19143:9143
|
||||
# S3
|
||||
- 19000:19000
|
||||
# S3 TLS
|
||||
|
|
|
@ -96,6 +96,18 @@
|
|||
"upstream": "cassandra:9142",
|
||||
"enabled": true
|
||||
},
|
||||
{
|
||||
"name": "cassa_no_auth_tcp",
|
||||
"listen": "0.0.0.0:9043",
|
||||
"upstream": "cassandra_noauth:9042",
|
||||
"enabled": true
|
||||
},
|
||||
{
|
||||
"name": "cassa_no_auth_tls",
|
||||
"listen": "0.0.0.0:9143",
|
||||
"upstream": "cassandra_noauth:9142",
|
||||
"enabled": true
|
||||
},
|
||||
{
|
||||
"name": "sqlserver",
|
||||
"listen": "0.0.0.0:1433",
|
||||
|
|
|
@ -11,6 +11,14 @@
|
|||
-include_lib("common_test/include/ct.hrl").
|
||||
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
|
||||
|
||||
%% To run this test locally:
|
||||
%% ./scripts/ct/run.sh --app apps/emqx_bridge_cassandra --only-up
|
||||
%% PROFILE=emqx-enterprise PROXY_HOST=localhost CASSA_TLS_HOST=localhost \
|
||||
%% CASSA_TLS_PORT=19142 CASSA_TCP_HOST=localhost CASSA_TCP_NO_AUTH_HOST=localhost \
|
||||
%% CASSA_TCP_PORT=19042 CASSA_TCP_NO_AUTH_PORT=19043 \
|
||||
%% ./rebar3 ct --name 'test@127.0.0.1' -v --suite \
|
||||
%% apps/emqx_bridge_cassandra/test/emqx_bridge_cassandra_SUITE
|
||||
|
||||
% SQL definitions
|
||||
-define(SQL_BRIDGE,
|
||||
"insert into mqtt_msg_test(topic, payload, arrived) "
|
||||
|
|
|
@ -14,20 +14,20 @@
|
|||
-include_lib("emqx/include/emqx.hrl").
|
||||
-include_lib("stdlib/include/assert.hrl").
|
||||
|
||||
%% To run this test locally:
|
||||
%% ./scripts/ct/run.sh --app apps/emqx_bridge_cassandra --only-up
|
||||
%% PROFILE=emqx-enterprise PROXY_HOST=localhost CASSA_TLS_HOST=localhost \
|
||||
%% CASSA_TLS_PORT=9142 CASSA_TCP_HOST=localhost CASSA_TCP_NO_AUTH_HOST=localhost \
|
||||
%% CASSA_TCP_PORT=19042 CASSA_TCP_NO_AUTH_PORT=19043 \
|
||||
%% ./rebar3 ct --name 'test@127.0.0.1' -v --suite \
|
||||
%% apps/emqx_bridge_cassandra/test/emqx_bridge_cassandra_connector_SUITE
|
||||
|
||||
%% Cassandra servers are defined at `.ci/docker-compose-file/docker-compose-cassandra.yaml`
|
||||
%% You can change it to `127.0.0.1`, if you run this SUITE locally
|
||||
-define(CASSANDRA_HOST, "cassandra").
|
||||
-define(CASSANDRA_HOST_NOAUTH, "cassandra_noauth").
|
||||
-define(CASSANDRA_RESOURCE_MOD, emqx_bridge_cassandra_connector).
|
||||
|
||||
%% This test SUITE requires a running cassandra instance. If you don't want to
|
||||
%% bring up the whole CI infrastuctucture with the `scripts/ct/run.sh` script
|
||||
%% you can create a cassandra instance with the following command (execute it
|
||||
%% from root of the EMQX directory.). You also need to set ?CASSANDRA_HOST and
|
||||
%% ?CASSANDRA_PORT to appropriate values.
|
||||
%%
|
||||
%% sudo docker run --rm -d --name cassandra --network host cassandra:3.11.14
|
||||
|
||||
%% Cassandra default username & password once enable `authenticator: PasswordAuthenticator`
|
||||
%% in cassandra config
|
||||
-define(CASSA_USERNAME, <<"cassandra">>).
|
||||
|
@ -45,14 +45,14 @@ groups() ->
|
|||
{noauth, [t_lifecycle]}
|
||||
].
|
||||
|
||||
cassandra_servers(CassandraHost) ->
|
||||
cassandra_servers(CassandraHost, CassandraPort) ->
|
||||
lists:map(
|
||||
fun(#{hostname := Host, port := Port}) ->
|
||||
{Host, Port}
|
||||
end,
|
||||
emqx_schema:parse_servers(
|
||||
iolist_to_binary([CassandraHost, ":", erlang:integer_to_list(?CASSANDRA_DEFAULT_PORT)]),
|
||||
#{default_port => ?CASSANDRA_DEFAULT_PORT}
|
||||
iolist_to_binary([CassandraHost, ":", erlang:integer_to_list(CassandraPort)]),
|
||||
#{default_port => CassandraPort}
|
||||
)
|
||||
).
|
||||
|
||||
|
@ -63,25 +63,30 @@ init_per_suite(Config) ->
|
|||
Config.
|
||||
|
||||
init_per_group(Group, Config) ->
|
||||
{CassandraHost, AuthOpts} =
|
||||
{CassandraHost, CassandraPort, AuthOpts} =
|
||||
case Group of
|
||||
auth ->
|
||||
{?CASSANDRA_HOST, [{username, ?CASSA_USERNAME}, {password, ?CASSA_PASSWORD}]};
|
||||
TcpHost = os:getenv("CASSA_TCP_HOST", "toxiproxy"),
|
||||
TcpPort = list_to_integer(os:getenv("CASSA_TCP_PORT", "9042")),
|
||||
{TcpHost, TcpPort, [{username, ?CASSA_USERNAME}, {password, ?CASSA_PASSWORD}]};
|
||||
noauth ->
|
||||
{?CASSANDRA_HOST_NOAUTH, []}
|
||||
TcpHost = os:getenv("CASSA_TCP_NO_AUTH_HOST", "toxiproxy"),
|
||||
TcpPort = list_to_integer(os:getenv("CASSA_TCP_NO_AUTH_PORT", "9043")),
|
||||
{TcpHost, TcpPort, []}
|
||||
end,
|
||||
case emqx_common_test_helpers:is_tcp_server_available(CassandraHost, ?CASSANDRA_DEFAULT_PORT) of
|
||||
case emqx_common_test_helpers:is_tcp_server_available(CassandraHost, CassandraPort) of
|
||||
true ->
|
||||
%% keyspace `mqtt` must be created in advance
|
||||
{ok, Conn} =
|
||||
ecql:connect([
|
||||
{nodes, cassandra_servers(CassandraHost)},
|
||||
{nodes, cassandra_servers(CassandraHost, CassandraPort)},
|
||||
{keyspace, "mqtt"}
|
||||
| AuthOpts
|
||||
]),
|
||||
ecql:close(Conn),
|
||||
[
|
||||
{cassa_host, CassandraHost},
|
||||
{cassa_port, CassandraPort},
|
||||
{cassa_auth_opts, AuthOpts}
|
||||
| Config
|
||||
];
|
||||
|
@ -212,6 +217,7 @@ create_local_resource(ResourceId, CheckedConfig) ->
|
|||
|
||||
cassandra_config(Config) ->
|
||||
Host = ?config(cassa_host, Config),
|
||||
Port = ?config(cassa_port, Config),
|
||||
AuthOpts = maps:from_list(?config(cassa_auth_opts, Config)),
|
||||
CassConfig =
|
||||
AuthOpts#{
|
||||
|
@ -223,7 +229,7 @@ cassandra_config(Config) ->
|
|||
"~s:~b",
|
||||
[
|
||||
Host,
|
||||
?CASSANDRA_DEFAULT_PORT
|
||||
Port
|
||||
]
|
||||
)
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue