Skip to content

Commit 2b3c1ce

Browse files
authored
Merge pull request #31 from jasonlyle88/develop
Version 1.07.00
2 parents aae0a0e + 0f69473 commit 2b3c1ce

File tree

8 files changed

+160
-8
lines changed

8 files changed

+160
-8
lines changed

source/sqlclUnitTest.sh

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,23 @@ function main() {
158158
printf -- '%s' "${testResultString}"
159159
} # getTestResultColorizedString
160160

161+
function convertToWindowsPath() {
162+
local originalUnixPath="$1"
163+
local unixPath="${originalUnixPath}"
164+
local windowsPath
165+
166+
# Convert drive letter
167+
if [[ "${unixPath:0:1}" == '/' ]]; then
168+
windowsPath="${unixPath:1:1}:\\"
169+
170+
unixPath="${unixPath:3}"
171+
fi
172+
173+
windowsPath="${windowsPath}$(printf -- '%s' "${unixPath}" | sed 's|/|\\|g')"
174+
175+
printf -- '%s\n' "${windowsPath}"
176+
} # convertToWindowsPath
177+
161178
function executeUnitTest() {
162179
local testType="$1"
163180
local testFile="$2"
@@ -174,6 +191,10 @@ function main() {
174191
local resultFile
175192
local logFile
176193
local wrapperFile
194+
local nologParam
195+
local testFileOS
196+
local testFilenameOS
197+
local testDirectoryOS
177198

178199
testDirectory="$(dirname "${testFile}")"
179200
testFilename="$(basename "${testFile}")"
@@ -182,6 +203,23 @@ function main() {
182203

183204
cd "${testDirectory}" || return 1
184205

206+
# Determine cross-os specific variables needed for execute
207+
if [[ "${OSTYPE}" == "cygwin" || "${OSTYPE}" == "msys" || "${OSTYPE}" == "win32" ]]; then
208+
# Handle Windows systems
209+
nologParam="//nolog"
210+
211+
testFileOS="$(convertToWindowsPath "${testFile}")"
212+
testDirectoryOS="$(convertToWindowsPath "${testDirectory}")"
213+
testFilenameOS="$(convertToWindowsPath "${testFilename}")"
214+
else
215+
# Handle linux/unix based systems
216+
nologParam="/nolog"
217+
218+
testFileOS="${testFile}"
219+
testDirectoryOS="${testDirectory}"
220+
testFilenameOS="${testFilename}"
221+
fi
222+
185223
# Make sure SQLPATH is not set for SQLcl execution so no login.sql
186224
# script is runs
187225
export SQLPATH=""
@@ -202,7 +240,7 @@ function main() {
202240
set verify on
203241
set echo on
204242
show connection
205-
@ "${testFile}" "${functionUniqueIdentifier}" "${testDirectory}"
243+
@ "${testFileOS}" "${functionUniqueIdentifier}" "${testDirectoryOS}"
206244
EOF
207245
testResultCode=$?
208246

@@ -223,10 +261,10 @@ function main() {
223261
printf -- 'set verify on\n'
224262
printf -- 'set echo on\n'
225263
printf -- 'show connection\n'
226-
printf -- '@ "%s" "%s" "%s"' "${testFile}" "${functionUniqueIdentifier}" "${testDirectory}"
264+
printf -- '@ "%s" "%s" "%s"' "${testFileOS}" "${functionUniqueIdentifier}" "${testDirectoryOS}"
227265
} > "${wrapperFile}"
228266

229-
"${sqlclBinary}" -noupdates /nolog "@${wrapperFile}" 1>>"${logFile}" 2>&1
267+
"${sqlclBinary}" -noupdates "${nologParam}" "@${wrapperFile}" 1>>"${logFile}" 2>&1
230268
testResultCode=$?
231269

232270
rm "${wrapperFile}"
@@ -247,7 +285,7 @@ function main() {
247285
set verify on
248286
set echo on
249287
show connection
250-
liquibase update -contexts test_context -database-changelog-table-name ${databaseChangelogTableName} -changelog-file ${testFilename}
288+
liquibase update -contexts test_context -database-changelog-table-name ${databaseChangelogTableName} -changelog-file ${testFilenameOS}
251289
EOF
252290
testResultCode=$?
253291
elif [[ "${testType}" = "${testTypeSqlclLiquibaseSearchPath}" ]]; then
@@ -265,7 +303,7 @@ function main() {
265303
set verify on
266304
set echo on
267305
show connection
268-
liquibase update -contexts test_context -database-changelog-table-name ${databaseChangelogTableName} -search-path ${testDirectory} -changelog-file ${testFilename}
306+
liquibase update -contexts test_context -database-changelog-table-name ${databaseChangelogTableName} -search-path ${testDirectoryOS} -changelog-file ${testFilenameOS}
269307
EOF
270308
testResultCode=$?
271309
fi
@@ -606,8 +644,8 @@ function main() {
606644
printf -- '\n' | tee -a "${logMainFile}"
607645
fi
608646

609-
sqlParamsWithoutPassword+=("-user" "${databaseUsername}" "-url" "${databaseConnectIdentifier}")
610-
sqlParamsWithPassword+=("${sqlParamsWithoutPassword[@]}" "-password" "${databasePassword}")
647+
sqlParamsWithoutPassword+=("-user" "\"${databaseUsername}\"" "-url" "\"${databaseConnectIdentifier}\"")
648+
sqlParamsWithPassword+=("${sqlParamsWithoutPassword[@]}" "-password" "\"${databasePassword}\"")
611649

612650
if ! "${sqlclBinary}" "${sqlParamsDirectConnect[@]}" "${sqlParamsWithPassword[@]}" 1>>"${logMainFile}" 2>&1 <<- EOF
613651
show connection
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
-- Make sure the liquibase changelog table exists
2+
prompt "Run liquibase validate"
3+
liquibase validate -database-changelog-table-name &1._changelog -changelog-file sqlcl-liquibase-databasechangelog-filename-directory-seperator/changelog.xml
4+
5+
-- Call to see if functionality works
6+
prompt "Run liquibase update"
7+
liquibase update -database-changelog-table-name &1._changelog -changelog-file sqlcl-liquibase-databasechangelog-filename-directory-seperator/changelog.xml
8+
9+
-- See if any changesets were run
10+
prompt "Check changesets ran"
11+
declare
12+
c_table_name constant varchar2(255 char) := '&1._changelog';
13+
l_count number;
14+
begin
15+
execute immediate 'select count(1) from ' || c_table_name
16+
into l_count;
17+
18+
if l_count = 0 then
19+
raise_application_error(-20001, 'Liquibase update did not run');
20+
end if;
21+
end;
22+
/
23+
24+
-- Check filename directory separator directions
25+
prompt "Check changesets ran"
26+
declare
27+
c_root constant varchar2(255 char) := 'sqlcl-liquibase-databasechangelog-filename-directory-seperator';
28+
c_table_name constant varchar2(255 char) := '&1._changelog';
29+
l_id varchar2(255 char);
30+
l_filename varchar2(255 char);
31+
begin
32+
l_id := 'opensouce_liquibase_change';
33+
execute immediate 'select filename from ' || c_table_name || ' where id = :1'
34+
into l_filename
35+
using in l_id;
36+
37+
if l_filename != c_root || '/a/b/c/child.sql' then
38+
raise_application_error(-20002, 'Open source liquibase change did not match expected filename ("' || l_filename || '"")');
39+
end if;
40+
41+
l_id := 'sqlcl_liquibase_runoraclescript_change';
42+
execute immediate 'select filename from ' || c_table_name || ' where id = :1'
43+
into l_filename
44+
using in l_id;
45+
46+
if l_filename != c_root || '/a/b/c/child.xml' then
47+
raise_application_error(-20003, 'runOracleScript change did not match expected filename ("' || l_filename || '"")');
48+
end if;
49+
50+
l_id := 'sqlcl_liquibase_runapexscript_change';
51+
execute immediate 'select filename from ' || c_table_name || ' where id = :1'
52+
into l_filename
53+
using in l_id;
54+
55+
if l_filename != c_root || '/a/b/c/child.xml' then
56+
raise_application_error(-20004, 'runApexScript change did not match expected filename ("' || l_filename || '"")');
57+
end if;
58+
end;
59+
/
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
--liquibase formatted sql
2+
3+
--changeset jlyle:opensouce_liquibase_change stripComments:false runOnChange:true runAlways:false
4+
select 1 from sys.dual;
5+
--rollback not required
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<databaseChangeLog
3+
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:ora="http://www.oracle.com/xml/ns/dbchangelog-ext"
6+
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.17.xsd"
7+
>
8+
<include relativeToChangelogFile="true" file="child.sql" />
9+
10+
<changeSet
11+
author="jlyle"
12+
id="sqlcl_liquibase_runoraclescript_change"
13+
runOnChange="true"
14+
runAlways="false"
15+
>
16+
<ora:runOracleScript ownerName="jlyle" sourceType="FILE" objectType="SCRIPT" objectName="demo" relativeToChangelogFile="true" >
17+
<ora:source>
18+
child.sql
19+
</ora:source>
20+
</ora:runOracleScript>
21+
</changeSet>
22+
23+
<changeSet
24+
author="jlyle"
25+
id="sqlcl_liquibase_runapexscript_change"
26+
runOnChange="true"
27+
runAlways="false"
28+
>
29+
<ora:runApexScript ownerName="jlyle" sourceType="FILE" objectType="SCRIPT" objectName="demo" relativeToChangelogFile="true" >
30+
<ora:source>
31+
child.sql
32+
</ora:source>
33+
</ora:runApexScript>
34+
</changeSet>
35+
</databaseChangeLog>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<databaseChangeLog
3+
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:ora="http://www.oracle.com/xml/ns/dbchangelog-ext"
6+
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.17.xsd"
7+
>
8+
<include relativeToChangelogFile="true" file="a/b/c/child.xml" />
9+
</databaseChangeLog>

source/sqlcl_direct_unit_tests/sqlcl-liquibase-default-file-relative-to-script-absolute/script.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
-- Make sure the liquibase changelog table exists
2+
prompt "Run liquibase validate"
23
liquibase validate -database-changelog-table-name &1._changelog -changelog-file changelog.xml
34

45
-- Call to see if functionality works
6+
prompt "Run liquibase update"
57
liquibase update -database-changelog-table-name &1._changelog -changelog-file changelog.xml -defaults-file liquibase.properties
68

79
-- See if any changesets were run
10+
prompt "Check changesets ran"
811
declare
912
c_table_name constant varchar2(255 char) := '&1._changelog';
1013
l_count number;

source/sqlcl_direct_unit_tests/sqlcl-liquibase-default-file-relative-to-script-relative/script.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
-- Make sure the liquibase changelog table exists
2+
prompt "Run liquibase validate"
23
liquibase validate -database-changelog-table-name &1._changelog -changelog-file changelog.xml
34

45
-- Call to see if functionality works
6+
prompt "Run liquibase update"
57
liquibase update -database-changelog-table-name &1._changelog -changelog-file changelog.xml -defaults-file liquibase.properties
68

79
-- See if any changesets were run
10+
prompt "Check changesets ran"
811
declare
912
c_table_name constant varchar2(255 char) := '&1._changelog';
1013
l_count number;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
liquibase update -database-changelog-table-name &1._changelog -search-path / -defaults-file &2/sqlcl-liquibase-defaults-file-respected/liquibase.properties -changelog-file &2/sqlcl-liquibase-defaults-file-respected/changelog.xml
1+
liquibase update -database-changelog-table-name &1._changelog -search-path &2 -defaults-file sqlcl-liquibase-defaults-file-respected/liquibase.properties -changelog-file sqlcl-liquibase-defaults-file-respected/changelog.xml

0 commit comments

Comments
 (0)