Skip to content
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

Fixed url paths not covered in api coverage report #687

Merged
merged 2 commits into from
Jul 28, 2023

Conversation

vikram-rao
Copy link
Collaborator

@vikram-rao vikram-rao commented Jul 21, 2023

What: Url path with multiple path parameters is not parsed correctly due to regex pattern matching error during parsing (requires non-greedy matching)

Why: Api Coverage is incorrect due to wrong path string manipulation. All apis with multiple path params are marked as not covered

How: Simple modification of the regex used for path conversion to be non greedy using ? operator

Checklist:

Issue ID:
N/A

…pected url when the path had multiple path parameters due to regex pattern matching error during parsing
@@ -6,7 +6,7 @@ import `in`.specmatic.core.Result

class ScenarioTestGenerationFailure(val scenario: Scenario, val e: Throwable) : ContractTest {
override fun testResultRecord(result: Result): TestResultRecord {
return TestResultRecord(scenario.path.replace(Regex("""\((.*):.*\)"""), "{$1}"), scenario.method, scenario.httpResponsePattern.status, result.testResult())
return TestResultRecord(scenario.path.replace(Regex("""\((.*?):.*?\)"""), "{$1}"), scenario.method, scenario.httpResponsePattern.status, result.testResult())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a unit test for this method

@@ -6,7 +6,7 @@ import `in`.specmatic.core.executeTest

class ScenarioTest(val scenario: Scenario, private val generativeTestingEnabled: Boolean = false) : ContractTest {
override fun testResultRecord(result: Result): TestResultRecord {
return TestResultRecord(scenario.path.replace(Regex("""\((.*):.*\)"""), "{$1}"), scenario.method, scenario.status, result.testResult())
return TestResultRecord(scenario.path.replace(Regex("""\((.*?):.*?\)"""), "{$1}"), scenario.method, scenario.status, result.testResult())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a unit test for this method

@@ -110,7 +110,7 @@ class TestReport(private val testReportRecords: MutableList<TestResultRecord> =
logger.newLine()

val recordsWithFixedURLs = testReportRecords.map {
it.copy(path = it.path.replace(Regex("""\((.*):.*\)"""), "{$1}"))
it.copy(path = it.path.replace(Regex("""\((.*?):.*?\)"""), "{$1}"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you extract this functionality to a method and add a unit test.

The functionality of doing the regex replace across all 3 seems the same.. if so, can you extract the regex replace itself into a common method.

Copy link
Member

@joelrosario joelrosario left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks @vikram-rao!

@vikram-rao vikram-rao merged commit 018561e into main Jul 28, 2023
@vikram-rao vikram-rao deleted the test-coverage-report-fixes branch July 28, 2023 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants