Skip to content

Commit

Permalink
Be consistent and safe in our bash options. (#184)
Browse files Browse the repository at this point in the history
The pipefail option was clearly intended but was not being applied in a lot of cases.
DB creation code was wrong; use the postgres docker image's env var intended for this purpose instead.
  • Loading branch information
jeremyestein authored Dec 14, 2023
1 parent 09ac04d commit 228d46e
Show file tree
Hide file tree
Showing 11 changed files with 12 additions and 16 deletions.
2 changes: 1 addition & 1 deletion bin/run-all-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -eo pipefail
set -euxo pipefail

BIN_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="${BIN_DIR%/*}"
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -eux pipefail
set -euxo pipefail

function wait_until_service_healthy() {
while ! docker ps | grep "$1" | grep -q healthy ;do
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ services:
environment:
POSTGRES_USER: ${PIXL_DB_USER}
POSTGRES_PASSWORD: ${PIXL_DB_PASSWORD}
PIXL_DB_NAME: ${PIXL_DB_NAME}
POSTGRES_DB: ${PIXL_DB_NAME}
PGTZ: Europe/London
env_file:
- ./docker/common.env
Expand Down
2 changes: 1 addition & 1 deletion pixl_dcmd/bin/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -eo pipefail
set -euxo pipefail

BIN_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
PACKAGE_DIR="${BIN_DIR%/*}"
Expand Down
2 changes: 1 addition & 1 deletion pixl_ehr/tests/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ services:
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
PIXL_DB_NAME: pixl
POSTGRES_DB: pixl
PGTZ: Europe/London
PIXL_DB_EHR_SCHEMA_NAME: emap_data
env_file:
Expand Down
8 changes: 2 additions & 6 deletions postgres/pixl-db_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

set -o nounset

psql -U "${POSTGRES_USER}" -tc "SELECT 1 FROM pg_database WHERE datname = '${PIXL_DB_NAME}'" |\
grep -q 1 | \
psql -U "${POSTGRES_USER}" -c "CREATE DATABASE ${PIXL_DB_NAME}"
set -euxo pipefail

# Create the EHR schema and associated tables
columns_and_types="mrn text, accession_number text, age integer, sex text, ethnicity text, height real, weight real, gcs integer, xray_report text"
ehr_create_command="CREATE SCHEMA emap_data AUTHORIZATION ${POSTGRES_USER}
CREATE TABLE ehr_raw ($columns_and_types)
CREATE TABLE ehr_anon ($columns_and_types)
"
psql -U "${POSTGRES_USER}" --dbname "${PIXL_DB_NAME}" -c "$ehr_create_command"
psql -U "${POSTGRES_USER}" --dbname "${POSTGRES_DB}" -c "$ehr_create_command"
2 changes: 1 addition & 1 deletion test/run-system-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -eux pipefail
set -euxo pipefail
BIN_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
PACKAGE_DIR="${BIN_DIR%/*}"
cd "${PACKAGE_DIR}/test"
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/check_entry_in_orthanc_anon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -eux pipefail
set -euxo pipefail

# This could be much improved by having more realistic test data some of
# which actually was persisted
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/check_entry_in_pixl_anon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -eux pipefail
set -euxo pipefail

_sql_command="select * from emap_data.ehr_anon"
_result=$(docker exec -it test-postgres-1 /bin/bash -c \
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/check_max_storage_in_orthanc_raw.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -eux pipefail
set -euxo pipefail

# This could be much improved by having more realistic test data some of
# which actually was persisted
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/insert_test_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -eux pipefail
set -euxo pipefail

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

Expand Down

0 comments on commit 228d46e

Please sign in to comment.