mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-14 17:02:49 +03:00
server/mysql: integrate MySQL tests into dev.sh workflow
https://github.com/hasura/graphql-engine-mono/pull/1848 GitOrigin-RevId: 2bd7c0a18448f042a1e35d21aaf42232acf48a46
This commit is contained in:
parent
892e56ca6e
commit
1cd9fc376d
50
scripts/containers/mysql.sh
Normal file
50
scripts/containers/mysql.sh
Normal file
@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env bash
|
||||
### This file is not meant to be run directly, but to be sourced from
|
||||
### the dev script. It defines all the functions required to run an
|
||||
### MySQL docker container.
|
||||
|
||||
|
||||
######################
|
||||
# Configuration #
|
||||
######################
|
||||
|
||||
if [ "$MODE" = "test" ]; then
|
||||
MYSQL_PORT=33306
|
||||
else
|
||||
MYSQL_PORT=23306
|
||||
fi
|
||||
|
||||
MYSQL_USER=root
|
||||
MYSQL_PASSWORD=hasuraMySQL1
|
||||
MYSQL_CONTAINER_NAME="hasura-dev-mysql-$MYSQL_PORT"
|
||||
# space deliberately omitted between -u and -p params https://hub.docker.com/_/mysql
|
||||
MYSQL_DOCKER="docker exec -it $MYSQL_CONTAINER_NAME mysql -u$MYSQL_USER -p$MYSQL_PASSWORD"
|
||||
|
||||
######################
|
||||
# Functions #
|
||||
######################
|
||||
|
||||
function mysql_launch_container(){
|
||||
echo "Launching MySQL container: $MYSQL_CONTAINER_NAME"
|
||||
docker run --name $MYSQL_CONTAINER_NAME \
|
||||
-e MYSQL_ROOT_PASSWORD=$MYSQL_PASSWORD \
|
||||
-e MYSQL_DATABASE=hasura \
|
||||
-p 127.0.0.1:$MYSQL_PORT:3306 \
|
||||
-d mysql:8.0 -h "127.0.0.1"
|
||||
}
|
||||
|
||||
function mysql_wait {
|
||||
echo -n "Waiting for mysql to come up"
|
||||
until ( $MYSQL_DOCKER -e 'SELECT 1' ) &>/dev/null; do
|
||||
echo -n '.' && sleep 0.2
|
||||
done
|
||||
echo " Ok"
|
||||
}
|
||||
|
||||
function mysql_cleanup(){
|
||||
echo "Removing $MYSQL_CONTAINER_NAME and its volumes in 5 seconds!"
|
||||
echo " PRESS CTRL-C TO ABORT removal of all containers, or ENTER to clean up right away"
|
||||
read -rt5 || true
|
||||
docker stop "$MYSQL_CONTAINER_NAME"
|
||||
docker rm -v "$MYSQL_CONTAINER_NAME"
|
||||
}
|
@ -13,6 +13,9 @@ function add_sources() {
|
||||
mssql)
|
||||
add_mssql_source "$hasura_graphql_server_port" "$MSSQL_DB_URL"
|
||||
;;
|
||||
mysql)
|
||||
add_mysql_source "$hasura_graphql_server_port" "$MSSQL_DB_URL"
|
||||
;;
|
||||
# bigquery deliberately omitted as its test setup is atypical. See:
|
||||
# https://github.com/hasura/graphql-engine/blob/master/server/CONTRIBUTING.md#running-the-python-test-suite-on-bigquery
|
||||
esac
|
||||
@ -52,3 +55,15 @@ function add_mssql_source() {
|
||||
curl "$metadata_url" \
|
||||
--data-raw '{"type":"mssql_add_source","args":{"name":"mssql","configuration":{"connection_info":{"connection_string":"'"$connection_string"'"}}}}'
|
||||
}
|
||||
|
||||
function add_mysql_source() {
|
||||
hasura_graphql_server_port=${1}
|
||||
# connection_string currently unused as mysql_add_source not yet supported
|
||||
# connection_string=${2}
|
||||
metadata_url=http://127.0.0.1:$hasura_graphql_server_port/v1/metadata
|
||||
|
||||
echo ""
|
||||
echo "Adding MySQL source"
|
||||
curl "$metadata_url" \
|
||||
--data-raw '{"type":"replace_metadata","args":{"version":3,"sources":[{"name":"mysql","kind":"mysql","tables":[],"configuration":{"database":"hasura","user":"'"$MYSQL_USER"'","password":"'"$MYSQL_PASSWORD"'","host":"127.0.0.1","port":'"$MYSQL_PORT"',"pool_settings":{}}}]}}'
|
||||
}
|
||||
|
@ -50,6 +50,10 @@ Available COMMANDs:
|
||||
Launch a Citus single-node container suitable for use with graphql-engine,
|
||||
watch its logs, clean up nicely after
|
||||
|
||||
mysql
|
||||
Launch a MySQL container suitable for use with graphql-engine, watch its
|
||||
logs, clean up nicely after
|
||||
|
||||
test [--integration [pytest_args...] | --unit | --hlint]
|
||||
Run the unit and integration tests, handling spinning up all dependencies.
|
||||
This will force a recompile. A combined code coverage report will be
|
||||
@ -96,6 +100,8 @@ case "${1-}" in
|
||||
;;
|
||||
citus)
|
||||
;;
|
||||
mysql)
|
||||
;;
|
||||
test)
|
||||
case "${2-}" in
|
||||
--unit)
|
||||
@ -161,11 +167,13 @@ fi
|
||||
source scripts/containers/postgres
|
||||
source scripts/containers/mssql
|
||||
source scripts/containers/citus
|
||||
source scripts/containers/mysql.sh
|
||||
source scripts/data-sources-util.sh
|
||||
|
||||
PG_RUNNING=0
|
||||
MSSQL_RUNNING=0
|
||||
CITUS_RUNNING=0
|
||||
MYSQL_RUNNING=0
|
||||
|
||||
function cleanup {
|
||||
echo
|
||||
@ -178,6 +186,7 @@ function cleanup {
|
||||
if [ $PG_RUNNING -eq 1 ]; then pg_cleanup; fi
|
||||
if [ $MSSQL_RUNNING -eq 1 ]; then mssql_cleanup; fi
|
||||
if [ $CITUS_RUNNING -eq 1 ]; then citus_cleanup; fi
|
||||
if [ $MYSQL_RUNNING -eq 1 ]; then mysql_cleanup; fi
|
||||
|
||||
echo_pretty "Done"
|
||||
}
|
||||
@ -202,6 +211,13 @@ function citus_start() {
|
||||
citus_wait
|
||||
}
|
||||
|
||||
function mysql_start() {
|
||||
mysql_launch_container
|
||||
MYSQL_RUNNING=1
|
||||
mysql_wait
|
||||
}
|
||||
|
||||
|
||||
function start_dbs() {
|
||||
# always launch the postgres container
|
||||
pg_start
|
||||
@ -213,6 +229,9 @@ function start_dbs() {
|
||||
mssql)
|
||||
mssql_start
|
||||
;;
|
||||
mysql)
|
||||
mysql_start
|
||||
;;
|
||||
# bigquery deliberately omitted as its test setup is atypical. See:
|
||||
# https://github.com/hasura/graphql-engine/blob/master/server/CONTRIBUTING.md#running-the-python-test-suite-on-bigquery
|
||||
esac
|
||||
@ -388,6 +407,23 @@ elif [ "$MODE" = "citus" ]; then
|
||||
echo_pretty ""
|
||||
docker logs -f --tail=0 "$CITUS_CONTAINER_NAME"
|
||||
|
||||
#################################
|
||||
### MySQL Container ###
|
||||
#################################
|
||||
|
||||
elif [ "$MODE" = "mysql" ]; then
|
||||
mysql_start
|
||||
echo_pretty "MYSQL logs will start to show up in realtime here. Press CTRL-C to exit and "
|
||||
echo_pretty "shutdown this container."
|
||||
echo_pretty ""
|
||||
echo_pretty "You can use the following to connect to the running instance:"
|
||||
echo_pretty " $ $MYSQL_DOCKER"
|
||||
echo_pretty ""
|
||||
echo_pretty "If you want to import a SQL file into MYSQL:"
|
||||
echo_pretty " $ $MYSQL_DOCKER -i <import_file>"
|
||||
echo_pretty ""
|
||||
docker logs -f --tail=0 "$MYSQL_CONTAINER_NAME"
|
||||
|
||||
|
||||
elif [ "$MODE" = "test" ]; then
|
||||
########################################
|
||||
|
@ -9,6 +9,7 @@ Invalid --backend argument. Available backends:
|
||||
bigquery
|
||||
citus
|
||||
mssql
|
||||
mysql
|
||||
|
||||
EOL
|
||||
exit 1
|
||||
@ -47,6 +48,8 @@ case "$BACKEND" in
|
||||
;;
|
||||
mssql)
|
||||
;;
|
||||
mysql)
|
||||
;;
|
||||
*)
|
||||
die_backends
|
||||
;;
|
||||
|
@ -57,7 +57,7 @@ $(J.deriveToJSON hasuraJSON ''ConnPoolSettings)
|
||||
-- | Partial of Database.MySQL.Simple.ConnectInfo
|
||||
data ConnSourceConfig
|
||||
= ConnSourceConfig
|
||||
{ _cscHost :: !Text -- ^ Works with @127.0.0.1@ but not with @localhost@ for some reason
|
||||
{ _cscHost :: !Text -- ^ Works with @127.0.0.1@ but not with @localhost@: https://mariadb.com/kb/en/troubleshooting-connection-issues/#localhost-and
|
||||
, _cscPort :: !Word16
|
||||
, _cscUser :: !Text
|
||||
, _cscPassword :: !Text
|
||||
|
@ -12,9 +12,9 @@ query:
|
||||
kind: mysql
|
||||
configuration:
|
||||
host: '127.0.0.1'
|
||||
port: 3306
|
||||
user: hasura
|
||||
password: password
|
||||
port: 33306
|
||||
user: root
|
||||
password: hasuraMySQL1
|
||||
database: hasura
|
||||
pool_settings: {}
|
||||
tables:
|
||||
|
@ -9,14 +9,12 @@ pytestmark = pytest.mark.allow_server_upgrade_test
|
||||
usefixtures = pytest.mark.usefixtures
|
||||
|
||||
|
||||
@pytest.mark.parametrize("transport", ['http', 'websocket'])
|
||||
@pytest.mark.parametrize("backend", ['mysql'])
|
||||
@usefixtures('per_class_tests_db_state')
|
||||
class TestGraphQLQueryBasicMySQL:
|
||||
|
||||
# initialize the metadata
|
||||
def test_replace_metadata(self, hge_ctx, transport):
|
||||
if transport == 'http':
|
||||
# initialize the metadata with default 'http' transport fixture
|
||||
def test_replace_metadata(self, hge_ctx):
|
||||
check_query_f(hge_ctx, self.dir() + '/replace_metadata.yaml')
|
||||
|
||||
@classmethod
|
||||
|
Loading…
Reference in New Issue
Block a user