Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 442af33

Browse files
committed
Removed reporting of cursor data when a diff is used.
Added test to confirm that only first 20 differences are shown.
1 parent a1e8113 commit 442af33

4 files changed

Lines changed: 63 additions & 45 deletions

File tree

source/expectations/data_values/ut_data_value_refcursor.tpb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ create or replace type body ut_data_value_refcursor as
140140
l_results ut_utils.t_clob_tab := ut_utils.t_clob_tab();
141141
l_result clob;
142142
l_result_string varchar2(32767);
143+
l_message varchar2(32767);
143144
l_ut_owner varchar2(250) := ut_utils.ut_owner;
144145
l_diff_row_count integer;
145146
l_actual ut_data_value_refcursor;
@@ -215,11 +216,13 @@ create or replace type body ut_data_value_refcursor as
215216
self.data_set_guid, l_actual.data_set_guid, l_diff_id, c_max_rows, l_exclude_xpath, a_include_xpath
216217
);
217218

218-
if l_row_diffs.count = 0 then
219-
ut_utils.append_to_clob(l_result,chr(10) || 'Rows:'||chr(10)||' All rows are different as the columns are not matching.');
220-
else
221-
ut_utils.append_to_clob(l_result,chr(10) || 'Rows: [ diff count = ' || to_char(l_diff_row_count) ||' ]' || chr(10));
222-
end if;
219+
l_message := chr(10)
220+
||'Rows: [ ' || l_diff_row_count ||' differences'
221+
|| case when l_diff_row_count > c_max_rows and l_row_diffs.count > 0 then ', showing first '||c_max_rows end
222+
||' ]' || chr(10)
223+
|| case when l_row_diffs.count = 0
224+
then ' All rows are different as the columns are not matching.' end;
225+
ut_utils.append_to_clob( l_result, l_message );
223226
for i in 1 .. l_row_diffs.count loop
224227
l_results.extend;
225228
l_results(l_results.last) := ' Row No. '||l_row_diffs(i).rn||' - '||rpad(l_row_diffs(i).diff_type,10)||l_row_diffs(i).diffed_row;

source/expectations/matchers/ut_equal.tpb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,12 @@ create or replace type body ut_equal as
221221
overriding member function failure_message(a_actual ut_data_value) return varchar2 is
222222
l_result varchar2(32767);
223223
begin
224-
l_result := (self as ut_matcher).failure_message(a_actual) || ': '|| self.expected.to_string_report();
225224
if self.expected.data_type = a_actual.data_type and self.expected.is_diffable then
226-
l_result := l_result || chr(10) || 'Diff:' || expected.diff(a_actual, get_exclude_xpath(), get_include_xpath());
225+
l_result :=
226+
'Actual: '||a_actual.get_object_info()||' '||self.description()||': '||self.expected.get_object_info()
227+
|| chr(10) || 'Diff:' || expected.diff(a_actual, get_exclude_xpath(), get_include_xpath());
228+
else
229+
l_result := (self as ut_matcher).failure_message(a_actual) || ': '|| self.expected.to_string_report();
227230
end if;
228231
return l_result;
229232
end;

test/core/expectations/compound_data/test_expectations_cursor.pkb

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -567,21 +567,9 @@ create or replace package body test_expectations_cursor is
567567
--Act
568568
ut3.ut.expect(l_actual).to_equal(l_expected);
569569

570-
l_expected_message := q'[Actual: (refcursor [ count = 2 ])
571-
Data-types:
572-
<ROW><RN>NUMBER</RN></ROW>
573-
Data:
574-
<ROW><RN>1</RN></ROW>%
575-
<ROW><RN>6</RN></ROW>%
576-
was expected to equal: (refcursor [ count = 3 ])
577-
Data-types:
578-
<ROW><RN>NUMBER</RN></ROW>
579-
Data:
580-
<ROW><RN>1</RN></ROW>%
581-
<ROW><RN>2</RN></ROW>%
582-
<ROW><RN>3</RN></ROW>%
570+
l_expected_message := q'[Actual: refcursor [ count = 2 ] was expected to equal: refcursor [ count = 3 ]
583571
Diff:
584-
Rows: [ diff count = 2 ]
572+
Rows: [ 2 differences ]
585573
Row No. 2 - Actual: <RN>6</RN>
586574
Row No. 2 - Expected: <RN>2</RN>
587575
Row No. 3 - Missing: <RN>3</RN>]';
@@ -615,7 +603,7 @@ Rows: [ diff count = 2 ]
615603
--Act
616604
ut3.ut.expect(l_actual).to_equal(l_expected);
617605

618-
l_expected_message := q'[%
606+
l_expected_message := q'[Actual: refcursor [ count = 2 ] was expected to equal: refcursor [ count = 2 ]
619607
Diff:
620608
Columns:
621609
Column <RN> data-type is invalid. Expected: NUMBER, actual: VARCHAR2.]';
@@ -636,7 +624,7 @@ Columns:
636624
--Act
637625
ut3.ut.expect(l_actual).to_equal(l_expected);
638626

639-
l_expected_message := q'[%
627+
l_expected_message := q'[Actual: refcursor [ count = 2 ] was expected to equal: refcursor [ count = 2 ]
640628
Diff:
641629
Columns:%
642630
Column <EXPECTED_COLUMN_NAME> [data-type: NUMBER] is missing. Expected column position: 2.%
@@ -659,13 +647,13 @@ Columns:%
659647
--Act
660648
ut3.ut.expect(l_actual).to_equal(l_expected);
661649

662-
l_expected_message := q'[%
650+
l_expected_message := q'[Actual: refcursor [ count = 2 ] was expected to equal: refcursor [ count = 2 ]
663651
Diff:
664652
Columns:
665653
Column <COL_4> is misplaced. Expected position: 2, actual position: 4.
666654
Column <COL_2> is misplaced. Expected position: 3, actual position: 2.
667655
Column <COL_3> is misplaced. Expected position: 4, actual position: 3.
668-
Rows:
656+
Rows: [ 2 differences ]
669657
All rows are different as the columns are not matching.]';
670658
l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message;
671659
--Assert
@@ -686,8 +674,9 @@ Rows:
686674
--Act
687675
ut3.ut.expect(l_actual).to_equal(l_expected);
688676

689-
l_expected_message := q'[%
690-
Rows: [ diff count = 2 ]
677+
l_expected_message := q'[Actual: refcursor [ count = 2 ] was expected to equal: refcursor [ count = 2 ]
678+
Diff:
679+
Rows: [ 2 differences ]
691680
Row No. 1 - Actual: <BAD_COL>-1</BAD_COL>
692681
Row No. 1 - Expected: <BAD_COL>1</BAD_COL>
693682
Row No. 2 - Actual: <BAD_COL>-2</BAD_COL>
@@ -697,6 +686,42 @@ Rows: [ diff count = 2 ]
697686
ut.expect(l_actual_message).to_be_like(l_expected_message);
698687
end;
699688

689+
procedure data_diff_on_20_rows_only is
690+
l_actual sys_refcursor;
691+
l_expected sys_refcursor;
692+
l_actual_message varchar2(32767);
693+
l_expected_message varchar2(32767);
694+
begin
695+
--Arrange
696+
open l_actual for
697+
select rownum
698+
* case when mod(rownum,2) = 0 then -1 else 1 end bad_col
699+
from dual connect by level <=100;
700+
open l_expected for select rownum bad_col from dual connect by level <=110;
701+
--Act
702+
ut3.ut.expect(l_actual).to_equal(l_expected);
703+
704+
l_expected_message := q'[Actual: refcursor [ count = 100 ] was expected to equal: refcursor [ count = 110 ]
705+
Diff:
706+
Rows: [ 60 differences, showing first 20 ]
707+
Row No. 2 - Actual: <BAD_COL>-2</BAD_COL>
708+
Row No. 2 - Expected: <BAD_COL>2</BAD_COL>
709+
Row No. 4 - Actual: <BAD_COL>-4</BAD_COL>
710+
Row No. 4 - Expected: <BAD_COL>4</BAD_COL>
711+
Row No. 6 - Actual: <BAD_COL>-6</BAD_COL>
712+
Row No. 6 - Expected: <BAD_COL>6</BAD_COL>
713+
Row No. 8 - Actual: <BAD_COL>-8</BAD_COL>
714+
Row No. 8 - Expected: <BAD_COL>8</BAD_COL>
715+
%
716+
Row No. 38 - Actual: <BAD_COL>-38</BAD_COL>
717+
Row No. 38 - Expected: <BAD_COL>38</BAD_COL>
718+
Row No. 40 - Actual: <BAD_COL>-40</BAD_COL>
719+
Row No. 40 - Expected: <BAD_COL>40</BAD_COL>]';
720+
l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message;
721+
--Assert
722+
ut.expect(l_actual_message).to_be_like(l_expected_message);
723+
end;
724+
700725
procedure column_and_data_diff is
701726
l_actual sys_refcursor;
702727
l_expected sys_refcursor;
@@ -717,31 +742,15 @@ Rows: [ diff count = 2 ]
717742
select 50 id, 'Mona' first_name, 'Lisa' last_name, date '1550-01-01' as birth_date from dual;
718743
--Act
719744
ut3.ut.expect(l_actual).to_equal(l_expected);
720-
l_expected_message := q'[%Actual: (refcursor [ count = 4 ])
721-
Data-types:
722-
<ROW><ID>NUMBER</ID><LAST_NAME>VARCHAR2</LAST_NAME><FIRST_NAME>VARCHAR2</FIRST_NAME><CREATE_TMSTMP>TIMESTAMP WITH TIME ZONE</CREATE_TMSTMP><CREATED_BY>VARCHAR2</CREATED_BY></ROW>
723-
Data:
724-
<ROW><ID>10</ID><LAST_NAME>Norris</LAST_NAME><FIRST_NAME>Chuck</FIRST_NAME><CREATE_TMSTMP>%</CREATE_TMSTMP><CREATED_BY>UT3_TESTER</CREATED_BY></ROW>
725-
<ROW><ID>20</ID><LAST_NAME>Skywalker</LAST_NAME><FIRST_NAME>Luke</FIRST_NAME><CREATE_TMSTMP>%</CREATE_TMSTMP><CREATED_BY>UT3_TESTER</CREATED_BY></ROW>
726-
<ROW><ID>30</ID><LAST_NAME>Bear</LAST_NAME><FIRST_NAME>Teddy</FIRST_NAME><CREATE_TMSTMP>%</CREATE_TMSTMP><CREATED_BY>UT3_TESTER</CREATED_BY></ROW>
727-
<ROW><ID>40</ID><LAST_NAME>Lee</LAST_NAME><FIRST_NAME>Bruce</FIRST_NAME><CREATE_TMSTMP>%</CREATE_TMSTMP><CREATED_BY>UT3_TESTER</CREATED_BY></ROW>
728-
was expected to equal: (refcursor [ count = 5 ])
729-
Data-types:
730-
<ROW><ID>NUMBER</ID><FIRST_NAME>VARCHAR2</FIRST_NAME><LAST_NAME>VARCHAR2</LAST_NAME><BIRTH_DATE>DATE</BIRTH_DATE></ROW>
731-
Data:
732-
<ROW><ID>10</ID><FIRST_NAME>Chuck</FIRST_NAME><LAST_NAME>Norris</LAST_NAME><BIRTH_DATE>%</BIRTH_DATE></ROW>
733-
<ROW><ID>20</ID><FIRST_NAME>Luke</FIRST_NAME><LAST_NAME>Skywalker</LAST_NAME><BIRTH_DATE>%</BIRTH_DATE></ROW>
734-
<ROW><ID>31</ID><FIRST_NAME>Teddy</FIRST_NAME><LAST_NAME>Bear</LAST_NAME><BIRTH_DATE>%</BIRTH_DATE></ROW>
735-
<ROW><ID>40</ID><FIRST_NAME>Brandon</FIRST_NAME><LAST_NAME>Lee</LAST_NAME><BIRTH_DATE>%</BIRTH_DATE></ROW>
736-
<ROW><ID>50</ID><FIRST_NAME>Mona</FIRST_NAME><LAST_NAME>Lisa</LAST_NAME><BIRTH_DATE>1550-01-01%</BIRTH_DATE></ROW>
745+
l_expected_message := q'[%Actual: refcursor [ count = 4 ] was expected to equal: refcursor [ count = 5 ]
737746
Diff:
738747
Columns:
739748
Column <FIRST_NAME> is misplaced. Expected position: 2, actual position: 3.
740749
Column <LAST_NAME> is misplaced. Expected position: 3, actual position: 2.
741750
Column <BIRTH_DATE> [data-type: DATE] is missing. Expected column position: 4.
742751
Column <CREATE_TMSTMP> [position: 4, data-type: TIMESTAMP WITH TIME ZONE] is not expected in results.
743752
Column <CREATED_BY> [position: 5, data-type: VARCHAR2] is not expected in results.
744-
Rows: [ diff count = 5 ]
753+
Rows: [ 5 differences ]
745754
Row No. 3 - Actual: <ID>30</ID>
746755
Row No. 3 - Expected: <ID>31</ID>
747756
Row No. 4 - Actual: <FIRST_NAME>Bruce</FIRST_NAME>

test/core/expectations/compound_data/test_expectations_cursor.pks

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ create or replace package test_expectations_cursor is
140140
--%test(Reports only mismatched columns on column data mismatch)
141141
procedure data_diff_on_col_data_mismatch;
142142

143+
--%test(Reports only first 20 rows of diff and gives a full diff count)
144+
procedure data_diff_on_20_rows_only;
145+
143146
--%test(Reports data diff and column diff when both are different)
144147
procedure column_and_data_diff;
145148

0 commit comments

Comments
 (0)