|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 4 | +# or more contributor license agreements. See the NOTICE file |
| 5 | +# distributed with this work for additional information |
| 6 | +# regarding copyright ownership. The ASF licenses this file |
| 7 | +# to you under the Apache License, Version 2.0 (the |
| 8 | +# "License"); you may not use this file except in compliance |
| 9 | +# with the License. You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, |
| 14 | +# software distributed under the License is distributed on an |
| 15 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 | +# KIND, either express or implied. See the License for the |
| 17 | +# specific language governing permissions and limitations |
| 18 | +# under the License. |
| 19 | + |
| 20 | +set -e |
| 21 | + |
| 22 | +# |
| 23 | +# Reset test DATABASE |
| 24 | +# |
| 25 | +function reset_db() { |
| 26 | + echo -------------------- |
| 27 | + echo Reseting test DB |
| 28 | + echo -------------------- |
| 29 | + docker exec -i superset_db bash -c "/usr/bin/psql -h 127.0.0.1 -U ${DB_USER} -w -c 'DROP DATABASE ${DB_NAME};'" |
| 30 | + docker exec -i superset_db bash -c "/usr/bin/psql -h 127.0.0.1 -U ${DB_USER} -w -c 'CREATE DATABASE ${DB_NAME};'" |
| 31 | +} |
| 32 | + |
| 33 | +# |
| 34 | +# Run init test procedures |
| 35 | +# |
| 36 | +function test_init() { |
| 37 | + echo -------------------- |
| 38 | + echo Upgrading |
| 39 | + echo -------------------- |
| 40 | + superset db upgrade |
| 41 | + echo -------------------- |
| 42 | + echo Superset init |
| 43 | + echo -------------------- |
| 44 | + superset init |
| 45 | + echo -------------------- |
| 46 | + echo Load examples |
| 47 | + echo -------------------- |
| 48 | + nosetests tests/load_examples_test.py |
| 49 | +} |
| 50 | + |
| 51 | + |
| 52 | +if [[ "$#" -eq "0" ]] |
| 53 | +then |
| 54 | + echo "No argument suplied" |
| 55 | + echo ------------------------ |
| 56 | + echo use: |
| 57 | + echo "run.sh <test module name> [options]" |
| 58 | + echo "[options]:" |
| 59 | + echo "--no-init: Dont restart docker and no db migrations, superset init and test data" |
| 60 | + echo "--no-reset-db: Recreates test database (DROP, CREATE)" |
| 61 | + exit 1 |
| 62 | +fi |
| 63 | + |
| 64 | +# |
| 65 | +# Init global vars |
| 66 | +# |
| 67 | +DB_NAME="test" |
| 68 | +DB_USER="superset" |
| 69 | +DB_PASSWORD="superset" |
| 70 | +export SUPERSET__SQLALCHEMY_DATABASE_URI=${SUPERSET__SQLALCHEMY_DATABASE_URI:-postgresql+psycopg2://"${DB_USER}":"${DB_PASSWORD}"@localhost/"${DB_NAME}"} |
| 71 | +export SUPERSET_CONFIG=${SUPERSET_CONFIG:-tests.superset_test_config} |
| 72 | +RUN_INIT=1 |
| 73 | +RUN_RESET_DB=1 |
| 74 | +TEST_MODULE="${1}" |
| 75 | + |
| 76 | +# Shift to pass the first cmd parameter for the test module |
| 77 | +shift 1 |
| 78 | + |
| 79 | +PARAMS="" |
| 80 | +while (( "$#" )); do |
| 81 | + case "$1" in |
| 82 | + --no-init) |
| 83 | + RUN_INIT=0 |
| 84 | + RUN_RESET_DB=0 |
| 85 | + shift 1 |
| 86 | + ;; |
| 87 | + --no-reset-db) |
| 88 | + RUN_RESET_DB=0 |
| 89 | + shift 1 |
| 90 | + ;; |
| 91 | + --) # end argument parsing |
| 92 | + shift |
| 93 | + break |
| 94 | + ;; |
| 95 | + --*) # unsupported flags |
| 96 | + echo "Error: Unsupported flag $1" >&2 |
| 97 | + exit 1 |
| 98 | + ;; |
| 99 | + *) # preserve positional arguments |
| 100 | + PARAMS="$PARAMS $1" |
| 101 | + shift |
| 102 | + ;; |
| 103 | + esac |
| 104 | +done |
| 105 | + |
| 106 | +echo ------------------------------------ |
| 107 | +echo DB_URI="${SUPERSET__SQLALCHEMY_DATABASE_URI}" |
| 108 | +echo Superset config module="${SUPERSET_CONFIG}" |
| 109 | +echo Run init procedures=$RUN_INIT |
| 110 | +echo Run reset DB=$RUN_RESET_DB |
| 111 | +echo Test to run:"${TEST_MODULE}" |
| 112 | +echo ------------------------------------ |
| 113 | + |
| 114 | + |
| 115 | +if [ $RUN_RESET_DB -eq 1 ] |
| 116 | +then |
| 117 | + reset_db |
| 118 | +fi |
| 119 | + |
| 120 | +if [ $RUN_INIT -eq 1 ] |
| 121 | +then |
| 122 | + test_init |
| 123 | +fi |
| 124 | + |
| 125 | +nosetests --exclude=load_examples_test "${TEST_MODULE}" |
0 commit comments