Skip to content

Commit 2e01488

Browse files
authored
Merge pull request #15 from jasonlyle88/cloud-wallet-enhancement
Add cloud wallet capabilities, better logging and output
2 parents 77c1798 + 7eb1c69 commit 2e01488

1 file changed

Lines changed: 95 additions & 56 deletions

File tree

source/sqlclUnitTest.sh

Lines changed: 95 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ function main() {
3939
printf -- ' If not provided, the user will be prompted for\n'
4040
printf -- ' a password.\n'
4141
printf -- '* -c {connection} -- The connect identifier used to connect to the database.\n'
42+
printf -- ' -C {wallet} -- The cloud wallet used to connect to the database.\n'
4243
printf -- ' -d {directory} -- The directory containing SQLcl (direct) tests to run.\n'
4344
printf -- ' If not provided, will default to "sqlcl_direct_unit_tests"\n'
4445
printf -- ' directory in the same directory as this script.\n'
@@ -162,7 +163,6 @@ function main() {
162163
local testResultCode
163164
local resultFile
164165
local logFile
165-
local count
166166
local wrapperFile
167167
local databaseChangelogTableName
168168

@@ -184,14 +184,15 @@ function main() {
184184
mkdir -p "$(dirname "${logFile}")"
185185
touch "${logFile}"
186186

187-
"${sqlclBinary}" -L -noupdates "${sqlclConnectStringWithoutPassword}" 1>"${logFile}" 2>&1 <<- EOF
188-
${databasePassword}
189-
whenever sqlerror exit failure
190-
set serveroutput on size unlimited
191-
set verify on
192-
set echo on
193-
@ "${testFile}" "${testDirectory}"
194-
EOF
187+
"${sqlclBinary}" -L -noupdates "${sqlclCloudConfigParameter[@]}" "${sqlclConnectStringWithoutPassword}" 1>"${logFile}" 2>&1 <<- EOF
188+
${databasePassword}
189+
whenever sqlerror exit failure
190+
set serveroutput on size unlimited
191+
set verify on
192+
set echo on
193+
show connection
194+
@ "${testFile}" "${testDirectory}"
195+
EOF
195196
testResultCode=$?
196197

197198
elif [[ "${testType}" = "${testTypeSqlclWrapped}" ]]; then
@@ -203,11 +204,12 @@ EOF
203204
touch "${logFile}"
204205

205206
{
206-
printf -- 'connect %s\n' "${sqlclConnectStringWithPassword}"
207207
printf -- 'whenever sqlerror exit failure\n'
208+
printf -- 'connect %s %s\n' "${sqlclCloudConfigParameter[*]}" "${sqlclConnectStringWithPassword}"
208209
printf -- 'set serveroutput on size unlimited\n'
209210
printf -- 'set verify on\n'
210211
printf -- 'set echo on\n'
212+
printf -- 'show connection\n'
211213
printf -- '@ "%s" "%s"' "${testFile}" "${testDirectory}"
212214
} > "${wrapperFile}"
213215

@@ -217,7 +219,7 @@ EOF
217219
rm "${wrapperFile}"
218220
elif [[ "${testType}" = "${testTypeSqlclLiquibaseCurrentDirectory}" ]]; then
219221
resultFile="${liquibaseCurrentDirectoryTestResultFile}"
220-
logFile="${logDirectory}/liquibase/${testName}.log"
222+
logFile="${logDirectory}/liquibase-current-directory/${testName}.log"
221223

222224
# Make sure database changelog table name is unique
223225
databaseChangelogTableName="ut${RANDOM}$(date +%s)"
@@ -227,46 +229,48 @@ EOF
227229

228230
cd "${testDirectory}" || return 1
229231

230-
"${sqlclBinary}" -L -noupdates "${sqlclConnectStringWithPassword}" 1>"${logFile}" 2>&1 <<- EOF
231-
whenever sqlerror exit failure
232-
set serveroutput on size unlimited
233-
set verify on
234-
set echo on
235-
liquibase update -contexts test_context -database-changelog-table-name ${databaseChangelogTableName} -changelog-file ${testFilename}
236-
EOF
232+
"${sqlclBinary}" -L -noupdates "${sqlclCloudConfigParameter[@]}" "${sqlclConnectStringWithPassword}" 1>"${logFile}" 2>&1 <<- EOF
233+
whenever sqlerror exit failure
234+
set serveroutput on size unlimited
235+
set verify on
236+
set echo on
237+
show connection
238+
liquibase update -contexts test_context -database-changelog-table-name ${databaseChangelogTableName} -changelog-file ${testFilename}
239+
EOF
237240
testResultCode=$?
238241

239-
"${sqlclBinary}" -L -noupdates "${sqlclConnectStringWithPassword}" 1>/dev/null 2>&1 <<- EOF
240-
drop view ${databaseChangelogTableName}_DETAILS;
241-
drop table ${databaseChangelogTableName}_ACTIONS;
242-
drop table ${databaseChangelogTableName};
243-
drop table ${databaseChangelogTableName}LOCK;
244-
EOF
242+
"${sqlclBinary}" -L -noupdates "${sqlclCloudConfigParameter[@]}" "${sqlclConnectStringWithPassword}" 1>/dev/null 2>&1 <<- EOF
243+
drop view ${databaseChangelogTableName}_DETAILS;
244+
drop table ${databaseChangelogTableName}_ACTIONS;
245+
drop table ${databaseChangelogTableName};
246+
drop table ${databaseChangelogTableName}LOCK;
247+
EOF
245248
elif [[ "${testType}" = "${testTypeSqlclLiquibaseSearchPath}" ]]; then
246249
resultFile="${liquibaseSearchPathTestResultFile}"
247-
logFile="${logDirectory}/liquibase/${testName}.log"
250+
logFile="${logDirectory}/liquibase-search-path/${testName}.log"
248251

249252
# Make sure database changelog table name is unique
250253
databaseChangelogTableName="ut${RANDOM}$(date +%s)"
251254

252255
mkdir -p "$(dirname "${logFile}")"
253256
touch "${logFile}"
254257

255-
"${sqlclBinary}" -L -noupdates "${sqlclConnectStringWithPassword}" 1>"${logFile}" 2>&1 <<- EOF
256-
whenever sqlerror exit failure
257-
set serveroutput on size unlimited
258-
set verify on
259-
set echo on
260-
liquibase update -contexts test_context -database-changelog-table-name ${databaseChangelogTableName} -search-path ${testDirectory} -changelog-file ${testFilename}
261-
EOF
258+
"${sqlclBinary}" -L -noupdates "${sqlclCloudConfigParameter[@]}" "${sqlclConnectStringWithPassword}" 1>"${logFile}" 2>&1 <<- EOF
259+
whenever sqlerror exit failure
260+
set serveroutput on size unlimited
261+
set verify on
262+
set echo on
263+
show connection
264+
liquibase update -contexts test_context -database-changelog-table-name ${databaseChangelogTableName} -search-path ${testDirectory} -changelog-file ${testFilename}
265+
EOF
262266
testResultCode=$?
263267

264-
"${sqlclBinary}" -L -noupdates "${sqlclConnectStringWithPassword}" 1>/dev/null 2>&1 <<- EOF
265-
drop view ${databaseChangelogTableName}_DETAILS;
266-
drop table ${databaseChangelogTableName}_ACTIONS;
267-
drop table ${databaseChangelogTableName};
268-
drop table ${databaseChangelogTableName}LOCK;
269-
EOF
268+
"${sqlclBinary}" -L -noupdates "${sqlclCloudConfigParameter[@]}" "${sqlclConnectStringWithPassword}" 1>/dev/null 2>&1 <<- EOF
269+
drop view ${databaseChangelogTableName}_DETAILS;
270+
drop table ${databaseChangelogTableName}_ACTIONS;
271+
drop table ${databaseChangelogTableName};
272+
drop table ${databaseChangelogTableName}LOCK;
273+
EOF
270274
fi
271275

272276
printf -- '%s:%s\n' "${testName}" "${testResultCode}" >> "${resultFile}"
@@ -284,7 +288,7 @@ EOF
284288
local testTypeSqlclDirect='SQLcl (direct)'
285289
local testTypeSqlclWrapped='SQLcl (wrapped)'
286290
local testTypeSqlclLiquibaseCurrentDirectory='SQLcl Liquibase (current directory)'
287-
local testTypeSqlclLiquibaseSearchPath='SQLcl Liquibase (-search-path)'
291+
local testTypeSqlclLiquibaseSearchPath='SQLcl Liquibase (search-path)'
288292
local testSuccessText='Succeeded'
289293
local textFailedText='Failed'
290294
local testTypeSummaryHeader='Test Type'
@@ -313,6 +317,7 @@ EOF
313317
local uFlag='false'
314318
local pFlag='false'
315319
local cFlag='false'
320+
local CFlag='false'
316321
local dFlag='false'
317322
local wFlag='false'
318323
local lFlag='false'
@@ -321,6 +326,7 @@ EOF
321326
local databaseUsername
322327
local databasePassword
323328
local databaseConnectIdentifier
329+
local databaseCloudWallet
324330
local sqlclDirectTestsDirectory
325331
local sqlclWrappedTestsDirectory
326332
local liquibaseTestsDirectory
@@ -355,6 +361,7 @@ EOF
355361
local liquibaseSearchPathTestResultFile
356362
local logDirectory
357363
local logMainFile
364+
local -a sqlclCloudConfigParameter
358365
local sqlclConnectStringWithoutPassword
359366
local sqlclConnectStringWithPassword
360367
local index
@@ -363,6 +370,7 @@ EOF
363370
local testFile
364371
local testExtension
365372
local testFilename
373+
local testTypePrevious
366374
local testType
367375
local testName
368376
local testResultFile
@@ -400,7 +408,7 @@ EOF
400408
# Option parsing
401409
#
402410
############################################################################
403-
while getopts ':b:u:p:c:d:w:l:h' opt
411+
while getopts ':b:u:p:c:C:d:w:l:h' opt
404412
do
405413

406414
case "${opt}" in
@@ -420,6 +428,10 @@ EOF
420428
cFlag='true'
421429
databaseConnectIdentifier="${OPTARG}"
422430
;;
431+
'C')
432+
CFlag='true'
433+
databaseCloudWallet="${OPTARG}"
434+
;;
423435
'd')
424436
dFlag='true'
425437
sqlclDirectTestsDirectory="${OPTARG}"
@@ -530,13 +542,23 @@ EOF
530542
return 16
531543
fi
532544

545+
if [[ "${CFlag}" == 'true' ]] && [[ ! -f "${databaseCloudWallet}" ]]; then
546+
printf -- 'ERROR: Cannot find specified cloud wallet: "%s"\n' "${databaseCloudWallet}" | tee -a "${logMainFile}" >&2
547+
return 17
548+
fi
549+
533550
##
534551
## Manipulate parameters
535552
##
536553
sqlclDirectTestsDirectory="$(getCanonicalPath "${sqlclDirectTestsDirectory}")"
537554
sqlclWrappedTestsDirectory="$(getCanonicalPath "${sqlclWrappedTestsDirectory}")"
538555
liquibaseTestsDirectory="$(getCanonicalPath "${liquibaseTestsDirectory}")"
539556

557+
sqlclCloudConfigParameter=()
558+
if [[ "${CFlag}" == 'true' ]]; then
559+
sqlclCloudConfigParameter=('-cloudconfig' "${databaseCloudWallet}")
560+
fi
561+
540562
printf -- '\n' | tee -a "${logMainFile}"
541563
printf -- '%s\n' "${h1}" | tee -a "${logMainFile}"
542564
printf -- '%s %s\n' "${hs}" 'SQLcl Version' | tee -a "${logMainFile}"
@@ -563,7 +585,11 @@ EOF
563585
sqlclConnectStringWithoutPassword="${databaseUsername}@'${databaseConnectIdentifier}'"
564586
sqlclConnectStringWithPassword="${databaseUsername}/${databasePassword}@'${databaseConnectIdentifier}'"
565587

566-
if ! "${sqlclBinary}" -S -L -noupdates "${sqlclConnectStringWithPassword}" 1>>"${logMainFile}" 2>&1 <<< 'exit'; then
588+
if ! "${sqlclBinary}" -S -L -noupdates "${sqlclCloudConfigParameter[@]}" "${sqlclConnectStringWithPassword}" 1>>"${logMainFile}" 2>&1 <<- EOF
589+
show connection
590+
exit
591+
EOF
592+
then
567593
printf -- 'ERROR: Could not connect to database\n' | tee -a "${logMainFile}" >&2
568594
return 25
569595
fi
@@ -586,11 +612,12 @@ EOF
586612

587613
{
588614
printf -- 'whenever sqlerror exit failure\n'
615+
printf -- 'show connection\n'
589616
printf -- 'exec raise_application_error(-20001, '\''Cause exit'\'')\n'
590617
printf -- 'exit'
591618
} > "${sqlWheneverErrorTest}"
592619

593-
if "${sqlclBinary}" -S -L -noupdates "${sqlclConnectStringWithPassword}" @"${sqlWheneverErrorTest}" 1>>"${logMainFile}" 2>&1; then
620+
if "${sqlclBinary}" -S -L -noupdates "${sqlclCloudConfigParameter[@]}" "${sqlclConnectStringWithPassword}" @"${sqlWheneverErrorTest}" 1>>"${logMainFile}" 2>&1; then
594621
printf -- 'ERROR: SQLcl not exiting appropriately on SQL error\n' | tee -a "${logMainFile}" >&2
595622
return 26
596623
fi
@@ -604,6 +631,7 @@ EOF
604631

605632
{
606633
printf -- 'whenever sqlerror exit failure\n'
634+
printf -- 'show connection\n'
607635
printf -- 'liquibase update -changelog-file %s\n' "$(basename "${liquibaseWehenverErrorTest}")"
608636
printf -- 'exit'
609637
} > "${sqlWheneverErrorTest}"
@@ -634,7 +662,7 @@ EOF
634662
} > "${liquibaseWehenverErrorTest}"
635663

636664
cd "${workingDirectory}" || return 1
637-
if "${sqlclBinary}" -S -L -noupdates "${sqlclConnectStringWithPassword}" @"${sqlWheneverErrorTest}" 1>>"${logMainFile}" 2>&1; then
665+
if "${sqlclBinary}" -S -L -noupdates "${sqlclCloudConfigParameter[@]}" "${sqlclConnectStringWithPassword}" @"${sqlWheneverErrorTest}" 1>>"${logMainFile}" 2>&1; then
638666
cd "${originalPWD}" || return 1
639667
printf -- 'ERROR: SQLcl not exiting appropriately on Liquibase error\n' | tee -a "${logMainFile}" >&2
640668
return 27
@@ -729,14 +757,14 @@ EOF
729757
testType="${testTypeSqlclDirect}"
730758
testResultFile="${directTestResultFile}"
731759
elif [[ "$index" -eq 2 ]]; then
732-
testType="${testTypeSqlclWrapped}"
733-
testResultFile="${wrappedTestResultFile}"
760+
testType="${testTypeSqlclLiquibaseCurrentDirectory}"
761+
testResultFile="${liquibaseCurrentDirectoryTestResultFile}"
734762
elif [[ "$index" -eq 3 ]]; then
735763
testType="${testTypeSqlclLiquibaseSearchPath}"
736764
testResultFile="${liquibaseSearchPathTestResultFile}"
737765
elif [[ "$index" -eq 4 ]]; then
738-
testType="${testTypeSqlclLiquibaseCurrentDirectory}"
739-
testResultFile="${liquibaseCurrentDirectoryTestResultFile}"
766+
testType="${testTypeSqlclWrapped}"
767+
testResultFile="${wrappedTestResultFile}"
740768
fi
741769

742770
while IFS= read -r readLine; do
@@ -795,15 +823,19 @@ EOF
795823
overallTestResultCode=0
796824

797825
# Print out the results table
798-
printf -- '\n' | tee -a "${logMainFile}"
799-
printf -- "%0.s-" $(seq 1 ${tableWidth}) | tee -a "${logMainFile}"
800-
printf -- '\n' | tee -a "${logMainFile}"
801-
printf -- \
802-
"${tableFormat}" \
803-
"${testTypeSummaryHeader}" \
804-
"${testNameSummaryHeader}" \
805-
"${testResultSummaryHeader}" | tee -a "${logMainFile}"
806-
printf -- "%0.s-" $(seq 1 ${tableWidth}) | tee -a "${logMainFile}"
826+
function printResultsTableHeader() {
827+
printf -- "%0.s-" $(seq 1 "${tableWidth}") | tee -a "${logMainFile}"
828+
printf -- '\n' | tee -a "${logMainFile}"
829+
# shellcheck disable=2059
830+
printf -- \
831+
"${tableFormat}" \
832+
"${testTypeSummaryHeader}" \
833+
"${testNameSummaryHeader}" \
834+
"${testResultSummaryHeader}" | tee -a "${logMainFile}"
835+
printf -- "%0.s-" $(seq 1 "${tableWidth}") | tee -a "${logMainFile}"
836+
printf -- '\n' | tee -a "${logMainFile}"
837+
} # printResultsTableHeader
838+
807839
printf -- '\n' | tee -a "${logMainFile}"
808840
for index in "${!testNames[@]}"; do
809841
testType="${testTypes[${index}]}"
@@ -812,15 +844,22 @@ EOF
812844
testResultPlainString="${testResultPlainStrings[${index}]}"
813845
testResultColorizedString="${testResultColorizedStrings[${index}]}"
814846

847+
if [[ "${testTypePrevious}" != "${testType}" ]]; then
848+
testTypePrevious="${testType}"
849+
printResultsTableHeader
850+
fi
851+
815852
if [[ "${testResultCode}" -gt 0 ]]; then
816853
overallTestResultCode=1
817854
fi
818855

856+
# shellcheck disable=2059
819857
printf -- \
820858
"${tableFormat}" \
821859
"${testType}" \
822860
"${testName}" \
823861
"${testResultColorizedString}"
862+
# shellcheck disable=2059
824863
printf -- \
825864
"${tableFormat}" \
826865
"${testType}" \

0 commit comments

Comments
 (0)