Skip to content

WiP: Improve matching of DataSourceUrl #260

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

Open
wants to merge 5 commits into
base: next
Choose a base branch
from
Open

Conversation

jimonthebarn
Copy link
Collaborator

This branch:

  • moves the implementation regarding DataSourceUrl matching and object creation into the DataSourceUrl class
  • adds additional tests for DataSourceUrl and DataSourceUrlExtractor

@jimonthebarn jimonthebarn changed the title Improve matching of DataSourceUrl WiP: Improve matching of DataSourceUrl Dec 9, 2024
Copy link

github-actions bot commented Dec 9, 2024

Qodana Community for JVM

It seems all right 👌

No new problems were found according to the checks applied

💡 Qodana analysis was run in the pull request mode: only the changed files were checked

View the detailed Qodana report

To be able to view the detailed Qodana report, you can either:

To get *.log files or any other Qodana artifacts, run the action with upload-result option set to true,
so that the action will upload the files as the job artifacts:

      - name: 'Qodana Scan'
        uses: JetBrains/qodana-action@v2024.2.5
        with:
          upload-result: true
Contact Qodana team

Contact us at qodana-support@jetbrains.com

@@ -1,42 +1,11 @@
package com.github.yusufugurozbek.testcontainers.port.updater

import com.intellij.database.dataSource.LocalDataSource

class DataSourceUrlExtractor {
Copy link
Collaborator Author

@jimonthebarn jimonthebarn Dec 9, 2024

Choose a reason for hiding this comment

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

@yusufugurozbek
Now that this actually only extracts the DataSourcesUrls - "segments" I'm not too happy with the naming yet. Whats your take on this? Maybe DataSourceComponentExtractor or DataSourceComponentMatcher which is a better hint at what is actually being returned. Yup naming is hard. :)


fun `test matchMode WITH_TESTCONTAINERS_PARAMETER successfully returns true for matching beforePort and afterPort containing testcontainers=true`() {
val dataSourceUrlA = DataSourceUrl("beforePort", "dontCareA", "testcontainers=true")
val dataSourceUrlB = DataSourceUrl("beforePort", "dontCareB", "dontCareC")
Copy link
Collaborator Author

@jimonthebarn jimonthebarn Dec 9, 2024

Choose a reason for hiding this comment

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

@yusufugurozbek
The match mode WITH_TESTCONTAINERS_PARAMETER seems a little weird to me. Especially the condition we're currently checking here which essentially requires for the current DataSourceUrl to have "testcontainers=true" within afterPort but it doesn't care whether the new DataSourceUrl also has it set. This follows the current implementation which I did not want to change as I'm oblivious to the intended semantic for the match mode.

Copy link
Owner

Choose a reason for hiding this comment

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

Could you please check this issue before we discuss it further?

Comment on lines +8 to +23
data class DataSourceUrl(val beforePort: String, val port: String, val afterPort: String?, private val urlExtractor: DataSourceUrlExtractor) {

constructor(beforePort: String, port: String, afterPort: String?) : this(beforePort, port, afterPort, DataSourceUrlExtractor())

init {
setUrlExtractor(urlExtractor)
}

companion object {
private lateinit var extractor: DataSourceUrlExtractor

private fun setUrlExtractor(extractor: DataSourceUrlExtractor) {
if (!::extractor.isInitialized) {
this.extractor = extractor
}
}
Copy link
Collaborator Author

@jimonthebarn jimonthebarn Dec 9, 2024

Choose a reason for hiding this comment

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

@yusufugurozbek
This seems a little convoluted here. The issue I was trying to solve is that for whatever reason the test classes could not find the constructor anymore if i define it it with a default value for the extractor like such:

data class DataSourceUrl(val beforePort: String, val port: String, val afterPort: String?, private val urlExtractor: DataSourceUrlExtractor = DataSourceUrlExtractor())

@yusufugurozbek yusufugurozbek changed the base branch from main to next January 30, 2025 17:10
Copy link

github-actions bot commented Jan 30, 2025

Qodana Community for JVM

It seems all right 👌

No new problems were found according to the checks applied

💡 Qodana analysis was run in the pull request mode: only the changed files were checked

View the detailed Qodana report

To be able to view the detailed Qodana report, you can either:

To get *.log files or any other Qodana artifacts, run the action with upload-result option set to true,
so that the action will upload the files as the job artifacts:

      - name: 'Qodana Scan'
        uses: JetBrains/qodana-action@v2024.3.4
        with:
          upload-result: true
Contact Qodana team

Contact us at qodana-support@jetbrains.com

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