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

Skip to content

Test execution data of utPLSQL project not showing on SonarCloud #1198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
felipebz opened this issue Mar 2, 2022 · 5 comments · Fixed by #1199
Closed

Test execution data of utPLSQL project not showing on SonarCloud #1198

felipebz opened this issue Mar 2, 2022 · 5 comments · Fixed by #1199
Assignees

Comments

@felipebz
Copy link
Contributor

felipebz commented Mar 2, 2022

Recently I saw this comment saying that the unit test data isn't showing on your SonarCloud project, then I decided to investigate this issue further and I would like to discuss what's the best way to fix it.

Just for reference, this is how the SonarCloud panel looks like now:

image

And how it should look like:

image

I saw that the utplsql-cli is executed using the user ut3_test_helper, but the unit tests are being compiled on users ut3_tester and ut3$user# and the option -owner for the test files is being omitted (line 10):

time utPLSQL-cli/bin/utplsql run ${UT3_TESTER_HELPER}/${UT3_TESTER_HELPER_PASSWORD}@${CONNECTION_STR} \
-source_path=source -owner=ut3_develop \
-p='ut3_tester,ut3$user#' \
-test_path=test -c \
-f=ut_coverage_sonar_reporter -o=coverage.xml \

When this option is omitted and there's no other mapping rule to identify the owner of a file by its path, the ut_file_mapper package assumes that the owner is the user running the tests, which is the user ut3_test_helper:

l_object_owner := coalesce(
upper(a_object_owner),
upper(regexp_substr(l_file_path, l_regex_pattern, 1, 1, 'i', l_object_owner_subexpression)),
sys_context('USERENV', 'CURRENT_SCHEMA'));

But actually the ut3_test_helper doesn't own any unit test and, as result, the test_results.xml file generated by ut_sonar_test_reporter doesn't contain any file path. This is the reason that the unit test data isn't being uploaded to SonarCloud.

The log of the "SonarCloud Scan" step on the GitHub Actions (example) also shows this, because the files aren't mapped correctly:

INFO: Test execution data ignored for 55 unknown files, including:
utplsql.ut3_tester.core.test_ut_utils
utplsql.ut3_tester.core.test_ut_test
(....)

One way I found to fix this issue without any changes to the utPLSQL code is executing the utplsql-cli twice, one for each schema, like:

utPLSQL-cli/bin/utplsql run ${UT3_TESTER_HELPER} (...)  -p='ut3_tester' -test_path=test -owner='ut3_tester'
utPLSQL-cli/bin/utplsql run ${UT3_TESTER_HELPER} (...)  -p='ut3$user#' -test_path=test -owner='ut3$user#'

But this would required some other changes to the build pipeline because the generated reports would also be duplicated.

Another alternative, that makes more sense to me, is to not assume any default value for the file owner on ut_file_mapper and change the ut_file_mapping usages (example) to compare the owner only if it's present. With this change, if there's no owner defined on the object-to-file mapping rules, the code will compare only the object name and object type to find the corresponding file, which should be good enough for most situations.

What do you folks think about it?

@lwasylow
Copy link
Member

lwasylow commented Mar 2, 2022

I think the CLI should resolve all filepath under test_path however the regex is possible not right gc_file_mapping_regex constant varchar2(100) := '/(((\w|[$#])+)\.)?((\w|[$#])+)\.(\w{3})$'; and we need to pass some extra options for

  -regex_expression="pattern"
  -type_mapping="matched_string=TYPE[/matched_string=TYPE]*"
  -owner_subexpression=subexpression_number
  -type_subexpression=subexpression_number
  -name_subexpression=subexpression_number

as per https://github.com/utPLSQL/utPLSQL-cli
I will have a play.

Ideally if we can avoid running twice would be ideal, or changing default behaviour.

@jgebal
Copy link
Member

jgebal commented Mar 2, 2022

We need to rename the folder: UT3_USER to UT3$USER#

@jgebal
Copy link
Member

jgebal commented Mar 2, 2022

I take this back.
We need to rename user UT3$USER# to UT3_USER
Unix doesn't like the special chars in folder names and for some reason utPLSQL-cli doesn't pass the paths to runner when the directory is named UT3$USER#

@jgebal
Copy link
Member

jgebal commented Mar 2, 2022

The parameters that seem to work for me locally were:

  -regex_expression="test/(\w+)(/(\w+))*/(\w+)\.(.{3})$" \
  -owner_subexpression=1 \
  -type_subexpression=5 \
  -name_subexpression=4 \

I have tested it locally with UT_DEBUG_REPORTER to see what are the file mappings generated by utPLSQL file mapper.

utPLSQL-cli/bin/utplsql run ${UT3_TESTER_HELPER}/${UT3_TESTER_HELPER_PASSWORD}@${CONNECTION_STR} \
-source_path=source -owner=ut3_develop \
-p='ut3_tester.test_file_mapper.default_mappings,ut3$user#.test_be_greater_or_equal.actual_date_greater' \
-test_path=test -c \
  -regex_expression="test/(\w+)(/(\w+))*/(\w+)\.(.{3})$" \
  -owner_subexpression=1 \
  -type_subexpression=5 \
  -name_subexpression=4 \
-f=ut_sonar_test_reporter         -o=test_results.xml \
-f=ut_debug_reporter              -o=debug.log.xml \
-f=ut_documentation_reporter      -o=test_results.log -s

@jgebal
Copy link
Member

jgebal commented Mar 3, 2022

@felipebz
Thanks for bringing this to our attention.
I have wrongly assumed that the issue with test-results not showing in sonar was related to sonar changes, while in fact it was related to tests refactoring that was done some time ago.

I've managed to fix the issue by change to how file mapping is interpreted (owner extracted from file path).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants