File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ # This is a test file for a part of `_lib.sh`, where we read `.env.custom` file if there is one.
4+ # We only want to give very minimal value to the `.env.custom` file, and expect that it would
5+ # be merged with the original `.env` file, with the `.env.custom` file taking precedence.
6+ cat << EOF >".env.custom"
7+ SENTRY_EVENT_RETENTION_DAYS=10
8+ EOF
9+
10+ # The `_test_setup.sh` script sources `install/_lib.sh`, so.. finger crossed this should works.
11+ source _unit-test/_test_setup.sh
12+
13+ rm -f .env.custom
14+
15+ echo " Expecting SENTRY_EVENT_RETENTION_DAYS to be 10, got ${SENTRY_EVENT_RETENTION_DAYS} "
16+ test " $SENTRY_EVENT_RETENTION_DAYS " == " 10"
17+ echo " Pass"
18+ echo " Expecting SENTRY_BIND to be 9000, got ${SENTRY_BIND} "
19+ test " $SENTRY_BIND " == " 9000"
20+ echo " Pass"
21+ echo " Expecting COMPOSE_PROJECT_NAME to be sentry-self-hosted, got ${COMPOSE_PROJECT_NAME} "
22+ test " $COMPOSE_PROJECT_NAME " == " sentry-self-hosted"
23+ echo " Pass"
24+
25+ report_success
Original file line number Diff line number Diff line change 1616 _ENV=.env
1717fi
1818
19+ # Reading .env.custom has to come first. The value won't be overriden, instead
20+ # it would persist because of `export -p> >"$t"` later, which exports current
21+ # environment variables to a temporary file with a `declare -x KEY=value` format.
22+ # The new values on `.env` would be set only if they are not already set.
23+ if [[ " $_ENV " == " .env.custom" ]]; then
24+ q=$( mktemp) && export -p > " $q " && set -a && . " .env.custom" && set +a && . " $q " && rm " $q " && unset q
25+ fi
26+
1927# Read .env for default values with a tip o' the hat to https://stackoverflow.com/a/59831605/90297
20- t=$( mktemp) && export -p > " $t " && set -a && . $_ENV && set +a && . " $t " && rm " $t " && unset t
28+ t=$( mktemp) && export -p > " $t " && set -a && . " .env " && set +a && . " $t " && rm " $t " && unset t
2129
2230if [ " ${GITHUB_ACTIONS:- } " = " true" ]; then
2331 _group=" ::group::"
You can’t perform that action at this time.
0 commit comments