Skip to content

Commit 95ddec1

Browse files
committed
Adding tests.
modifying code to cater for path with wildcard that can result in large item duplication due to parent/child search.
1 parent 0d8d34d commit 95ddec1

4 files changed

Lines changed: 225 additions & 25 deletions

File tree

source/core/ut_suite_cache_manager.pkb

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ create or replace package body ut_suite_cache_manager is
127127
end;
128128
end;
129129

130-
--Possible move logic to type
131130
function group_paths_by_schema(a_paths ut_varchar2_list) return ut_path_items is
132131
c_package_path_regex constant varchar2(100) := '^([A-Za-z0-9$#_]+)(\.([A-Za-z0-9$#_\*]+))?(\.([A-Za-z0-9$#_\*]+))?$';
133132
l_results ut_path_items := ut_path_items();
@@ -152,34 +151,41 @@ create or replace package body ut_suite_cache_manager is
152151

153152
function expand_paths(a_schema_paths ut_path_items) return ut_path_items is
154153
l_schema_paths ut_path_items:= ut_path_items();
155-
begin
154+
begin
156155
with paths_to_expand as (
157-
select /*+ no_parallel */ min(path) as suite_path,sp.schema_name as schema_name,nvl(sp.object_name,c.object_name) as object_name,
158-
sp.procedure_name as procedure_name
156+
/*
157+
The object name is populate but suitepath not
158+
We will use that object and try to match.
159+
We can pass also a wildcard this will result in one to many.
160+
*/
161+
select /*+ no_parallel */ min(path) as suite_path,sp.schema_name as schema_name,nvl(c.object_name,sp.object_name) as object_name,
162+
nvl2(sp.procedure_name,c.name,null) as procedure_name
159163
from table(a_schema_paths) sp left outer join ut_suite_cache c
160164
on ( c.object_owner = upper(sp.schema_name)
161165
and c.object_name like replace(upper(sp.object_name),'*','%')
162166
and c.name like nvl(replace(upper(sp.procedure_name),'*','%'), c.name))
163-
where sp.suite_path is null
164-
and sp.object_name is not null
165-
group by sp.schema_name,nvl(sp.object_name,c.object_name),sp.procedure_name
167+
where sp.suite_path is null and sp.object_name is not null
168+
group by sp.schema_name,nvl(c.object_name,sp.object_name),nvl2(sp.procedure_name,c.name,null)
166169
union all
167-
select /*+ no_parallel */ c.path as suite_path,sp.schema_name,sp.object_name,sp.procedure_name as procedure_name
170+
select /*+ no_parallel */ nvl(c.path,sp.suite_path) as suite_path,sp.schema_name,sp.object_name,sp.procedure_name as procedure_name
168171
from
169172
table(a_schema_paths) sp left outer join ut_suite_cache c on
170-
( c.object_owner = upper(sp.schema_name)
171-
and sp.suite_path is not null
172-
and instr(sp.suite_path,'*') > 0)
173-
where c.path like replace(sp.suite_path,'*','%')
173+
( c.object_owner = upper(sp.schema_name)
174+
and c.path like replace(sp.suite_path,'*','%'))
175+
where sp.suite_path is not null and instr(sp.suite_path,'*') > 0
174176
union all
177+
/*
178+
Get all data that do not have an wildcard and not require expanding.
179+
We will take them as they are.
180+
a)suite path is populated
181+
b)suite path and object is empty so schema name is by default ( or passed)
182+
*/
175183
select /*+ no_parallel */ sp.suite_path as suite_path,sp.schema_name,sp.object_name,sp.procedure_name as procedure_name
176184
from table(a_schema_paths) sp
177-
where sp.suite_path is not null
178-
and instr(sp.suite_path,'*') = 0
179-
union all
180-
select /*+ no_parallel */ sp.suite_path as suite_path,sp.schema_name,sp.object_name,sp.procedure_name as procedure_name
181-
from table(a_schema_paths) sp
182-
where sp.suite_path is null and sp.object_name is null
185+
where
186+
(sp.suite_path is not null and instr(sp.suite_path,'*') = 0)
187+
or
188+
(sp.suite_path is null and sp.object_name is null)
183189
)
184190
select ut_path_item(schema_name,object_name,procedure_name,suite_path)
185191
bulk collect into l_schema_paths
@@ -190,14 +196,25 @@ create or replace package body ut_suite_cache_manager is
190196
where r_num = 1 ;
191197
return l_schema_paths;
192198
end;
193-
199+
200+
/*
201+
Get a suite items rows that matching our criteria like
202+
path,object_name etc.
203+
We need to consider also an wildcard character on our procedures and object
204+
names.
205+
Were the path is populated we need to make sure we dont return duplicates
206+
as the wildcard can produce multiple results from same path and
207+
parents and child for each can be same resulting in duplicates
208+
TODO: Verify that this not duplicate with a expand paths.
209+
*/
194210
function get_suite_items (
195211
a_schema_paths ut_path_items
196212
) return ut_suite_cache_rows is
197213
l_suite_items ut_suite_cache_rows := ut_suite_cache_rows();
198214
begin
199-
select /*+ cardinality(c 500) */ value(c) as obj
200-
bulk collect into l_suite_items
215+
select obj bulk collect into l_suite_items
216+
from (
217+
select /*+ cardinality(c 500) */ value(c) as obj,row_number() over ( partition by path order by path asc) r_num
201218
from ut_suite_cache c,
202219
table(a_schema_paths) sp
203220
where c.object_owner = upper(sp.schema_name)
@@ -212,10 +229,14 @@ create or replace package body ut_suite_cache_manager is
212229
( sp.suite_path is null
213230
and c.object_name like nvl(upper(replace(sp.object_name,'*','%')),c.object_name)
214231
and c.name like nvl(upper(replace(sp.procedure_name,'*','%')),c.name)
215-
));
232+
))) where r_num = 1;
216233
return l_suite_items;
217234
end;
218235

236+
/*
237+
Having a base set of suites we will do a further filter down if there are
238+
any tags defined.
239+
*/
219240
function get_tags_suites (
220241
a_suite_items ut_suite_cache_rows,
221242
a_tags ut_varchar2_rows

source/core/ut_suite_manager.pks

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ create or replace package ut_suite_manager authid current_user is
2020
* Resposible for building hierarhy of sutes from individual suites created by suite_builder
2121
*/
2222

23-
2423
/**
2524
* @private
2625
*

test/ut3_tester/core/test_suite_manager.pkb

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,26 @@ end;]';
945945
ut.expect(sqlerrm).to_be_like('%failing_non_existing%');
946946
end;
947947

948+
procedure test_search_nonex_pck_wild is
949+
l_objects_to_run ut3_develop.ut_suite_items;
950+
begin
951+
l_objects_to_run := ut3_develop.ut_suite_manager.configure_execution_by_path(ut3_develop.ut_varchar2_list('ut3_develop.failing_non_*'));
952+
ut.fail('Non existing package did not raise exception');
953+
exception
954+
when others then
955+
ut.expect(sqlerrm).to_be_like('%failing_non_*%');
956+
end;
957+
958+
procedure test_search_nonex_path_wild is
959+
l_objects_to_run ut3_develop.ut_suite_items;
960+
begin
961+
l_objects_to_run := ut3_develop.ut_suite_manager.configure_execution_by_path(ut3_develop.ut_varchar2_list('ut3_develop:failing_non_*'));
962+
ut.fail('Non existing path did not raise exception');
963+
exception
964+
when others then
965+
ut.expect(sqlerrm).to_be_like('%:failing_non_*%');
966+
end;
967+
948968
procedure test_search_nonexist_sch_pck is
949969
l_objects_to_run ut3_develop.ut_suite_items;
950970
begin
@@ -1560,5 +1580,147 @@ end;]';
15601580

15611581
end;
15621582

1583+
procedure test_wild_card_obj_name is
1584+
c_path varchar2(100) := sys_context('USERENV', 'CURRENT_USER')||'.test_package_*';
1585+
l_objects_to_run ut3_develop.ut_suite_items;
1586+
l_test_suite ut3_develop.ut_logical_suite;
1587+
l_test1_suite ut3_develop.ut_logical_suite;
1588+
l_test2_suite ut3_develop.ut_logical_suite;
1589+
l_ctx_suite ut3_develop.ut_logical_suite;
1590+
l_test_proc ut3_develop.ut_test;
1591+
begin
1592+
--Act
1593+
l_objects_to_run := ut3_develop.ut_suite_manager.configure_execution_by_path(ut3_develop.ut_varchar2_list(c_path));
1594+
1595+
--Assert
1596+
ut.expect(l_objects_to_run.count).to_equal(3);
1597+
1598+
1599+
for i in 1 .. 3 loop
1600+
l_test_suite := treat(l_objects_to_run(i) as ut3_develop.ut_logical_suite);
1601+
ut.expect(l_test_suite.name in ('test_package_with_ctx','tests', 'tests2')).to_be_true;
1602+
1603+
case l_test_suite.name
1604+
when 'test_package_with_ctx' then
1605+
ut.expect(l_test_suite.items.count).to_equal(1);
1606+
l_ctx_suite:= treat(l_test_suite.items(1) as ut3_develop.ut_logical_suite);
1607+
ut.expect(l_ctx_suite.name).to_equal('some_context');
1608+
ut.expect(l_ctx_suite.description).to_equal('Some context description');
1609+
ut.expect(l_ctx_suite.items.count).to_equal(1);
1610+
l_test_proc := treat(l_ctx_suite.items(1) as ut3_develop.ut_test);
1611+
ut.expect(l_test_proc.name).to_equal('test1');
1612+
when 'tests' then
1613+
l_test1_suite := treat(l_test_suite.items(1) as ut3_develop.ut_logical_suite);
1614+
ut.expect(l_test1_suite.name).to_equal('test_package_1');
1615+
ut.expect(l_test1_suite.items.count).to_equal(3);
1616+
ut.expect(l_test1_suite.rollback_type).to_equal(ut3_develop.ut_utils.gc_rollback_manual);
1617+
l_test2_suite := treat(l_test1_suite.items(1) as ut3_develop.ut_logical_suite);
1618+
1619+
ut.expect(l_test2_suite.name).to_equal('test_package_2');
1620+
ut.expect(l_test2_suite.items.count).to_equal(3);
1621+
ut.expect(l_test2_suite.rollback_type).to_equal(ut3_develop.ut_utils.gc_rollback_manual);
1622+
when 'tests2' then
1623+
l_test1_suite := treat(l_test_suite.items(1) as ut3_develop.ut_logical_suite);
1624+
ut.expect(l_test1_suite.name).to_equal('test_package_3');
1625+
ut.expect(l_test1_suite.items.count).to_equal(3);
1626+
end case;
1627+
1628+
end loop;
1629+
1630+
end;
1631+
1632+
procedure test_wild_card_prc_name is
1633+
c_path varchar2(100) := sys_context('USERENV', 'CURRENT_USER')||'.test_package_1.test*';
1634+
l_objects_to_run ut3_develop.ut_suite_items;
1635+
l_test_suite ut3_develop.ut_logical_suite;
1636+
l_test1_suite ut3_develop.ut_logical_suite;
1637+
l_test1_proc ut3_develop.ut_test;
1638+
l_test2_proc ut3_develop.ut_test;
1639+
begin
1640+
--Act
1641+
l_objects_to_run := ut3_develop.ut_suite_manager.configure_execution_by_path(ut3_develop.ut_varchar2_list(c_path));
1642+
1643+
--Assert
1644+
ut.expect(l_objects_to_run.count).to_equal(1);
1645+
l_test_suite := treat(l_objects_to_run(1) as ut3_develop.ut_logical_suite);
1646+
ut.expect(l_test_suite.name).to_equal('tests');
1647+
1648+
l_test1_suite := treat(l_test_suite.items(1) as ut3_develop.ut_logical_suite);
1649+
ut.expect(l_test1_suite.name).to_equal('test_package_1');
1650+
ut.expect(l_test1_suite.items.count).to_equal(2);
1651+
1652+
l_test1_proc := treat(l_test1_suite.items(1) as ut3_develop.ut_test);
1653+
ut.expect(l_test1_proc.name).to_equal('test1');
1654+
1655+
l_test2_proc := treat(l_test1_suite.items(2) as ut3_develop.ut_test);
1656+
ut.expect(l_test2_proc.name).to_equal('test2');
1657+
end;
1658+
1659+
procedure test_wild_card_path_name is
1660+
c_path varchar2(100) := sys_context('USERENV', 'CURRENT_USER')||':tests*';
1661+
l_objects_to_run ut3_develop.ut_suite_items;
1662+
l_test_suite ut3_develop.ut_logical_suite;
1663+
l_test1_suite ut3_develop.ut_logical_suite;
1664+
l_test2_suite ut3_develop.ut_logical_suite;
1665+
l_test3_suite ut3_develop.ut_logical_suite;
1666+
l_ctx_suite ut3_develop.ut_logical_suite;
1667+
l_test_proc ut3_develop.ut_test;
1668+
begin
1669+
--Act
1670+
l_objects_to_run := ut3_develop.ut_suite_manager.configure_execution_by_path(ut3_develop.ut_varchar2_list(c_path));
1671+
1672+
--Assert
1673+
ut.expect(l_objects_to_run.count).to_equal(2);
1674+
1675+
1676+
for i in 1 .. 2 loop
1677+
l_test_suite := treat(l_objects_to_run(i) as ut3_develop.ut_logical_suite);
1678+
ut.expect(l_test_suite.name in ('tests', 'tests2')).to_be_true;
1679+
1680+
case l_test_suite.name
1681+
when 'tests' then
1682+
l_test1_suite := treat(l_test_suite.items(1) as ut3_develop.ut_logical_suite);
1683+
ut.expect(l_test1_suite.name).to_equal('test_package_1');
1684+
ut.expect(l_test1_suite.items.count).to_equal(3);
1685+
1686+
for i in 1 ..3 loop
1687+
--l_test2_suite := treat(l_test1_suite.items(i) as ut3_develop.ut_logical_suite);
1688+
--ut.expect(l_test2_suite.name).to_equal('test_package_2');
1689+
--ut.expect(l_test2_suite.items.count).to_equal(3);
1690+
case l_test1_suite.items(i).self_type
1691+
when 'UT_SUITE' then
1692+
l_test2_suite := treat(l_test1_suite.items(i) as ut3_develop.ut_logical_suite);
1693+
ut.expect(l_test2_suite.name).to_equal('test_package_2');
1694+
ut.expect(l_test2_suite.items.count).to_equal(3);
1695+
1696+
l_test_proc := treat(l_test2_suite.items(1) as ut3_develop.ut_test);
1697+
ut.expect(l_test_proc.name in ('test1', 'test2','context_test')).to_be_true;
1698+
1699+
l_test_proc := treat(l_test2_suite.items(2) as ut3_develop.ut_test);
1700+
ut.expect(l_test_proc.name in ('test1', 'test2','context_test')).to_be_true;
1701+
1702+
l_test_proc := treat(l_test2_suite.items(3) as ut3_develop.ut_test);
1703+
ut.expect(l_test_proc.name in ('test1', 'test2','context_test')).to_be_true;
1704+
1705+
when 'UT_TEST' then
1706+
l_test_proc := treat(l_test1_suite.items(i) as ut3_develop.ut_test);
1707+
ut.expect(l_test_proc.name in ('test1', 'test2')).to_be_true;
1708+
end case;
1709+
end loop;
1710+
when 'tests2' then
1711+
ut.expect(l_test_suite.items.count).to_equal(1);
1712+
l_test1_suite := treat(l_test_suite.items(1) as ut3_develop.ut_logical_suite);
1713+
ut.expect(l_test1_suite.name).to_equal('test_package_3');
1714+
ut.expect(l_test1_suite.items.count).to_equal(3);
1715+
for i in 1 .. 3 loop
1716+
l_test_proc := treat(l_test1_suite.items(i) as ut3_develop.ut_test);
1717+
ut.expect(l_test_proc.name in ('test1', 'test2','disabled_test')).to_be_true;
1718+
end loop;
1719+
end case;
1720+
1721+
end loop;
1722+
1723+
end;
1724+
15631725
end test_suite_manager;
15641726
/

test/ut3_tester/core/test_suite_manager.pks

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,14 @@ create or replace package test_suite_manager is
7575

7676
--%test(Prepare runner for nonexisting package with schema)
7777
procedure test_search_nonexisting_pck;
78-
79-
--%test(Prepare runner for nonexisting package without schema)
78+
79+
--%test(Prepare runner for nonexisting package using wildcard filter)
80+
procedure test_search_nonex_pck_wild;
81+
82+
--%test(Prepare runner for nonexisting path using wildcard filter)
83+
procedure test_search_nonex_path_wild;
84+
85+
--%test(Prepare runner for nonexisting package without schema)
8086
procedure test_search_nonexist_sch_pck;
8187

8288
--%test(Test description with comma)
@@ -185,6 +191,18 @@ create or replace package test_suite_manager is
185191
--%aftertest(clean_remove_annot_test)
186192
procedure test_rem_cache_on_crt_anno;
187193

194+
--%context(wildcard_filters)
195+
196+
--%test(Execute test_packages using a object_name with wildcard )
197+
procedure test_wild_card_obj_name;
198+
199+
--%test(Execute test_packages using a procedure name with wildcard )
200+
procedure test_wild_card_prc_name;
201+
202+
--%test(Execute test_packages using a path name with wildcard )
203+
procedure test_wild_card_path_name;
204+
205+
--%endcontext
188206

189207
end test_suite_manager;
190208
/

0 commit comments

Comments
 (0)