Skip to content

Commit

Permalink
feat(core): add filter disabling thought config
Browse files Browse the repository at this point in the history
  • Loading branch information
Vacxe committed May 22, 2024
1 parent fbb4958 commit 131de5b
Show file tree
Hide file tree
Showing 15 changed files with 175 additions and 59 deletions.
30 changes: 30 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ sealed class TestFilterConfiguration {
@JsonProperty("regex") val regex: Regex? = null,
@JsonProperty("values") val values: List<String>? = null,
@JsonProperty("file") val file: File? = null,
@JsonProperty("enabled") val enabled: Boolean = true,
) : TestFilterConfiguration() {
override fun validate() {
var i = 0
Expand Down Expand Up @@ -75,6 +76,7 @@ sealed class TestFilterConfiguration {
@JsonProperty("regex") val regex: Regex? = null,
@JsonProperty("values") val values: List<String>? = null,
@JsonProperty("file") val file: File? = null,
@JsonProperty("enabled") val enabled: Boolean = true,
) : TestFilterConfiguration() {
override fun validate() {
var i = 0
Expand Down Expand Up @@ -111,6 +113,7 @@ sealed class TestFilterConfiguration {
@JsonProperty("regex") val regex: Regex? = null,
@JsonProperty("values") val values: List<String>? = null,
@JsonProperty("file") val file: File? = null,
@JsonProperty("enabled") val enabled: Boolean = true,
) : TestFilterConfiguration() {
override fun validate() {
var i = 0
Expand Down Expand Up @@ -148,6 +151,7 @@ sealed class TestFilterConfiguration {
@JsonProperty("values") val values: List<String>? = null,
@JsonProperty("file") val file: File? = null,
@JsonProperty("subpackages") val subpackages: Boolean = false,
@JsonProperty("enabled") val enabled: Boolean = true,
) : TestFilterConfiguration() {
override fun validate() {
var i = 0
Expand Down Expand Up @@ -184,7 +188,8 @@ sealed class TestFilterConfiguration {

data class AnnotationDataFilterConfiguration(
@JsonProperty("nameRegex") val nameRegex: Regex,
@JsonProperty("valueRegex") val valueRegex: Regex
@JsonProperty("valueRegex") val valueRegex: Regex,
@JsonProperty("enabled") val enabled: Boolean = true,
) : TestFilterConfiguration() {
override fun validate() {}

Expand All @@ -200,6 +205,7 @@ sealed class TestFilterConfiguration {
@JsonProperty("regex") val regex: Regex? = null,
@JsonProperty("values") val values: List<String>? = null,
@JsonProperty("file") val file: File? = null,
@JsonProperty("enabled") val enabled: Boolean = true,
) : TestFilterConfiguration() {
override fun validate() {
var i = 0
Expand Down Expand Up @@ -235,6 +241,7 @@ sealed class TestFilterConfiguration {
data class FragmentationFilterConfiguration(
val index: Int,
val count: Int,
val enabled: Boolean,
) : TestFilterConfiguration() {
override fun validate() {
if (index < 0) throw ConfigurationException("Fragment index [$index] should be >= 0")
Expand All @@ -247,6 +254,7 @@ sealed class TestFilterConfiguration {
@JsonProperty("regex") val regex: Regex? = null,
@JsonProperty("values") val values: List<String>? = null,
@JsonProperty("file") val file: File? = null,
@JsonProperty("enabled") val enabled: Boolean = true,
) : TestFilterConfiguration() {
override fun validate() {
var i = 0
Expand Down Expand Up @@ -283,6 +291,7 @@ sealed class TestFilterConfiguration {
@JsonProperty("regex") val regex: Regex? = null,
@JsonProperty("values") val values: List<String>? = null,
@JsonProperty("file") val file: File? = null,
@JsonProperty("enabled") val enabled: Boolean = true,
) : TestFilterConfiguration() {
override fun validate() {
var i = 0
Expand Down Expand Up @@ -317,7 +326,8 @@ sealed class TestFilterConfiguration {

data class CompositionFilterConfiguration(
@JsonProperty("filters") val filters: List<TestFilterConfiguration>,
@JsonProperty("op") val op: OPERATION
@JsonProperty("op") val op: OPERATION,
@JsonProperty("enabled") val enabled: Boolean = true,
) : TestFilterConfiguration() {
override fun validate() {
filters.forEach { it.validate() }
Expand All @@ -342,7 +352,9 @@ sealed class TestFilterConfiguration {
override fun hashCode(): Int = filters.hashCode() + op.hashCode()
}

object AllureFilterConfiguration : TestFilterConfiguration() {
data class AllureFilterConfiguration(
@JsonProperty("enabled") val enabled: Boolean = true,
) : TestFilterConfiguration() {
override fun validate() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ import io.qameta.allure.testfilter.TestPlanSupplier
import io.qameta.allure.testfilter.TestPlanV1_0

val ALLURE_ID_ANNOTATIONS = setOf("io.qameta.allure.AllureId", "io.qameta.allure.kotlin.AllureId")
class AllureTestFilter(val cnf: TestFilterConfiguration.AllureFilterConfiguration, private val testPlanSupplier: TestPlanSupplier = FileTestPlanSupplier()) : TestFilter {

class AllureTestFilter(
val cnf: TestFilterConfiguration.AllureFilterConfiguration,
private val testPlanSupplier: TestPlanSupplier = FileTestPlanSupplier()
) : ToggleTestFilter {

override val enabled: Boolean
get() = cnf.enabled

private val testPlan: TestPlan? by lazy {
val optional = testPlanSupplier.supply()
if (optional.isPresent) {
Expand All @@ -20,7 +28,7 @@ class AllureTestFilter(val cnf: TestFilterConfiguration.AllureFilterConfiguratio
}
}

override fun filter(tests: List<Test>): List<Test> {
override fun filterPredicate(tests: List<Test>): List<Test> {
return if (testPlan != null && testPlan is TestPlanV1_0) {
val plan = testPlan as TestPlanV1_0
tests.filter { test ->
Expand All @@ -31,10 +39,11 @@ class AllureTestFilter(val cnf: TestFilterConfiguration.AllureFilterConfiguratio
tests
}
}

private fun findAllureId(test: Test) =
test.metaProperties.find { ALLURE_ID_ANNOTATIONS.contains(it.name) }?.values?.get("value") as? String

override fun filterNot(tests: List<Test>): List<Test> {
override fun filterNotPredicate(tests: List<Test>): List<Test> {
return if (testPlan != null && testPlan is TestPlanV1_0) {
val plan = testPlan as TestPlanV1_0
tests.filterNot { test ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ import com.malinskiy.marathon.execution.TestFilter
import com.malinskiy.marathon.test.MetaProperty
import com.malinskiy.marathon.test.Test

data class AnnotationDataFilter(val cnf: TestFilterConfiguration.AnnotationDataFilterConfiguration) : TestFilter {
override fun filter(tests: List<Test>): List<Test> = tests.filter { test ->
data class AnnotationDataFilter(val cnf: TestFilterConfiguration.AnnotationDataFilterConfiguration) : ToggleTestFilter {

override val enabled: Boolean
get() = cnf.enabled

override fun filterPredicate(tests: List<Test>): List<Test> = tests.filter { test ->
test.metaProperties.any {
match(it)
}
}

override fun filterNot(tests: List<Test>): List<Test> = tests.filterNot { test ->
override fun filterNotPredicate(tests: List<Test>): List<Test> = tests.filterNot { test ->
test.metaProperties.any {
match(it)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@ package com.malinskiy.marathon.execution.filter
import com.malinskiy.marathon.config.TestFilterConfiguration

class AnnotationFilter(cnf: TestFilterConfiguration.AnnotationFilterConfiguration) :
SingleValueTestFilter(cnf.regex, cnf.values, cnf.file, { test, values ->
when {
regex != null -> {
test.metaProperties.map { it.name }.any(regex::matches)
}
values != null -> {
test.metaProperties.map { it.name }.intersect(values).isNotEmpty()
}
else -> {
true
SingleValueTestFilter(
cnf.regex,
cnf.values,
cnf.file,
cnf.enabled,
{ test, values ->
when {
regex != null -> {
test.metaProperties.map { it.name }.any(regex::matches)
}

values != null -> {
test.metaProperties.map { it.name }.intersect(values).isNotEmpty()
}

else -> {
true
}
}
}
})
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ import com.malinskiy.marathon.test.Test

class CompositionFilter(
private val filters: List<TestFilter>,
private val op: TestFilterConfiguration.CompositionFilterConfiguration.OPERATION
) : TestFilter {
private val op: TestFilterConfiguration.CompositionFilterConfiguration.OPERATION,
override val enabled: Boolean
) : ToggleTestFilter {

override fun filter(tests: List<Test>): List<Test> {
override fun filterPredicate(tests: List<Test>): List<Test> {
return when (op) {
TestFilterConfiguration.CompositionFilterConfiguration.OPERATION.UNION -> filterWithUnionOperation(tests)
TestFilterConfiguration.CompositionFilterConfiguration.OPERATION.INTERSECTION -> filterWithIntersectionOperation(tests)
TestFilterConfiguration.CompositionFilterConfiguration.OPERATION.SUBTRACT -> filterWithSubtractOperation(tests)
}
}

override fun filterNot(tests: List<Test>): List<Test> {
override fun filterNotPredicate(tests: List<Test>): List<Test> {
val filteredTests = filter(tests)
return when (op) {
TestFilterConfiguration.CompositionFilterConfiguration.OPERATION.UNION -> tests.subtract(filteredTests).toList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ import java.math.BigInteger
* This is a dynamic programming technique, hence the results will be sub-optimal compared to connecting multiple devices to the same test
* run
*/
class FragmentationFilter(private val cnf: TestFilterConfiguration.FragmentationFilterConfiguration) : TestFilter {
class FragmentationFilter(private val cnf: TestFilterConfiguration.FragmentationFilterConfiguration) : ToggleTestFilter {
private val power by lazy { BigInteger.valueOf(cnf.count.toLong()) }
private val remainder by lazy { BigInteger.valueOf(cnf.index.toLong()) }
override val enabled: Boolean
get() = cnf.enabled
private val predicate: (Test) -> Boolean = {
/**
* Randomizing the distribution via md5
Expand All @@ -35,7 +37,7 @@ class FragmentationFilter(private val cnf: TestFilterConfiguration.Fragmentation
actualRemainder == remainder
}

override fun filter(tests: List<Test>): List<Test> = tests.filter(predicate)
override fun filterPredicate(tests: List<Test>): List<Test> = tests.filter(predicate)

override fun filterNot(tests: List<Test>): List<Test> = tests.filterNot(predicate)
override fun filterNotPredicate(tests: List<Test>): List<Test> = tests.filterNot(predicate)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import com.malinskiy.marathon.config.TestFilterConfiguration
import com.malinskiy.marathon.test.toClassName

class FullyQualifiedClassnameFilter(cnf: TestFilterConfiguration.FullyQualifiedClassnameFilterConfiguration) :
SingleValueTestFilter(cnf.regex, cnf.values, cnf.file, { test, values ->
(regex?.matches(test.toClassName()) ?: true) && (values?.contains(test.toClassName()) ?: true)
})
SingleValueTestFilter(
cnf.regex,
cnf.values,
cnf.file,
cnf.enabled,
{ test, values ->
(regex?.matches(test.toClassName()) ?: true) && (values?.contains(test.toClassName()) ?: true)
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import com.malinskiy.marathon.config.TestFilterConfiguration
import com.malinskiy.marathon.test.toTestName

class FullyQualifiedTestnameFilter(cnf: TestFilterConfiguration.FullyQualifiedTestnameFilterConfiguration) :
SingleValueTestFilter(cnf.regex, cnf.values, cnf.file, { test, values ->
(regex?.matches(test.toTestName()) ?: true) && (values?.contains(test.toTestName()) ?: true)
})
SingleValueTestFilter(
cnf.regex,
cnf.values,
cnf.file,
cnf.enabled,
{ test, values ->
(regex?.matches(test.toTestName()) ?: true) && (values?.contains(test.toTestName()) ?: true)
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ package com.malinskiy.marathon.execution.filter
import com.malinskiy.marathon.config.TestFilterConfiguration

class SimpleClassnameFilter(cnf: TestFilterConfiguration.SimpleClassnameFilterConfiguration) :
SingleValueTestFilter(cnf.regex, cnf.values, cnf.file, { test, values ->
(regex?.matches(test.clazz) ?: true) && (values?.contains(test.clazz) ?: true)
})
SingleValueTestFilter(cnf.regex,
cnf.values,
cnf.file,
cnf.enabled,
{ test, values ->
(regex?.matches(test.clazz) ?: true) && (values?.contains(test.clazz) ?: true)
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import com.malinskiy.marathon.config.TestFilterConfiguration
import com.malinskiy.marathon.test.toSimpleSafeTestName

class SimpleTestnameFilter(cnf: TestFilterConfiguration.SimpleTestnameFilterConfiguration) :
SingleValueTestFilter(cnf.regex, cnf.values, cnf.file, { test, values ->
val simpleSafeTestName = test.toSimpleSafeTestName(methodSeparator = '#')
(regex?.matches(simpleSafeTestName) ?: true) && (values?.contains(simpleSafeTestName) ?: true)
})
SingleValueTestFilter(
cnf.regex,
cnf.values,
cnf.file,
cnf.enabled,
{ test, values ->
val simpleSafeTestName = test.toSimpleSafeTestName(methodSeparator = '#')
(regex?.matches(simpleSafeTestName) ?: true) && (values?.contains(simpleSafeTestName) ?: true)
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ package com.malinskiy.marathon.execution.filter
import com.malinskiy.marathon.execution.TestFilter
import com.malinskiy.marathon.log.MarathonLogging
import com.malinskiy.marathon.test.Test
import jdk.jfr.Enabled
import java.io.File

open class SingleValueTestFilter(
val regex: Regex?,
val values: List<String>?,
val file: File?,
override val enabled: Boolean,
val predicate: SingleValueTestFilter.(test: Test, values: List<String>?) -> Boolean,
) : TestFilter {
) : ToggleTestFilter {
private val log = MarathonLogging.logger("SingleValueTestFilter")

private val fileValuesCache: List<String>? by lazy {
Expand All @@ -28,11 +30,11 @@ open class SingleValueTestFilter(
return values ?: fileValuesCache
}

override fun filter(tests: List<Test>): List<Test> = with(tests) {
override fun filterPredicate(tests: List<Test>): List<Test> = with(tests) {
filter { predicate(this@SingleValueTestFilter, it, readValues()) }
}

override fun filterNot(tests: List<Test>): List<Test> = with(tests) {
override fun filterNotPredicate(tests: List<Test>): List<Test> = with(tests) {
filterNot { predicate(this@SingleValueTestFilter, it, readValues()) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ package com.malinskiy.marathon.execution.filter
import com.malinskiy.marathon.config.TestFilterConfiguration

class TestMethodFilter(cnf: TestFilterConfiguration.TestMethodFilterConfiguration) :
SingleValueTestFilter(cnf.regex, cnf.values, cnf.file, { test, values ->
(regex?.matches(test.method) ?: true) && (values?.contains(test.method) ?: true)
})
SingleValueTestFilter(cnf.regex,
cnf.values,
cnf.file,
cnf.enabled,
{ test, values ->
(regex?.matches(test.method) ?: true) && (values?.contains(test.method) ?: true)
}
)
Loading

0 comments on commit 131de5b

Please sign in to comment.