Skip to content

Commit

Permalink
custom nameFn for data-driven tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JesusMcCloud committed Sep 4, 2023
1 parent 3e99595 commit 05730b0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ProblemReporterTest : FreeSpec({
val problemReporter = ProblemReporter()

"sorter" - {
withData(ProblemReportSorter.values().asList()) {
withData(ProblemReportSorter.entries) {
val report = ProblemReport(
body = ProblemReportBody(
sorter = it,
Expand All @@ -36,7 +36,7 @@ class ProblemReporterTest : FreeSpec({
}

"scope" - {
withData(ProblemReportScope.values().asList()) {
withData(ProblemReportScope.entries) {
val report = ProblemReport(
body = ProblemReportBody(
sorter = ProblemReportSorter.WARNING,
Expand All @@ -57,7 +57,7 @@ class ProblemReporterTest : FreeSpec({
}

"descriptor" - {
withData(ProblemReportDescriptor.values().asList()) {
withData(ProblemReportDescriptor.entries) {
val report = ProblemReport(
body = ProblemReportBody(
sorter = ProblemReportSorter.WARNING,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
package at.asitplus.wallet.lib.agent

import at.asitplus.wallet.lib.data.AtomicAttribute2023
import at.asitplus.wallet.lib.data.ConstantIndex
import at.asitplus.wallet.lib.data.CredentialStatus
import at.asitplus.wallet.lib.data.VerifiableCredential
import at.asitplus.wallet.lib.data.VerifiableCredentialJws
import at.asitplus.wallet.lib.jws.DefaultJwsService
import at.asitplus.wallet.lib.jws.JwsAlgorithm
import at.asitplus.wallet.lib.jws.JwsContentTypeConstants
import at.asitplus.wallet.lib.jws.JwsHeader
import at.asitplus.wallet.lib.jws.JwsService
import at.asitplus.wallet.lib.jws.JwsSigned
import at.asitplus.wallet.lib.data.*
import at.asitplus.wallet.lib.jws.*
import com.benasher44.uuid.uuid4
import io.kotest.core.spec.style.FreeSpec
import io.kotest.datatest.withData
Expand Down Expand Up @@ -108,6 +99,7 @@ class ValidatorVcTest : FreeSpec() {

"Manually created and valid credential is valid" - {
withData(
nameFn = ::credentialNameFn,
dataProvider.getCredentialWithType(
verifier.identifier,
attributeTypes = listOf(ConstantIndex.AtomicAttribute2023.vcType)
Expand All @@ -124,6 +116,7 @@ class ValidatorVcTest : FreeSpec() {

"Wrong key ends in wrong signature is not valid" - {
withData(
nameFn = ::credentialNameFn,
dataProvider.getCredentialWithType(
verifier.identifier,
attributeTypes = listOf(ConstantIndex.AtomicAttribute2023.vcType)
Expand All @@ -141,6 +134,7 @@ class ValidatorVcTest : FreeSpec() {

"Invalid sub in credential is not valid" - {
withData(
nameFn = ::credentialNameFn,
dataProvider.getCredentialWithType(
verifier.identifier,
attributeTypes = listOf(ConstantIndex.AtomicAttribute2023.vcType)
Expand All @@ -158,6 +152,7 @@ class ValidatorVcTest : FreeSpec() {

"Invalid issuer in credential is not valid" - {
withData(
nameFn = ::credentialNameFn,
dataProvider.getCredentialWithType(
verifier.identifier,
attributeTypes = listOf(ConstantIndex.AtomicAttribute2023.vcType)
Expand All @@ -174,6 +169,7 @@ class ValidatorVcTest : FreeSpec() {

"Invalid jwtId in credential is not valid" - {
withData(
nameFn = ::credentialNameFn,
dataProvider.getCredentialWithType(
verifier.identifier,
attributeTypes = listOf(ConstantIndex.AtomicAttribute2023.vcType)
Expand All @@ -191,6 +187,7 @@ class ValidatorVcTest : FreeSpec() {

"Invalid type in credential is not valid" - {
withData(
nameFn = ::credentialNameFn,
dataProvider.getCredentialWithType(
verifier.identifier,
attributeTypes = listOf(ConstantIndex.AtomicAttribute2023.vcType)
Expand All @@ -209,6 +206,7 @@ class ValidatorVcTest : FreeSpec() {

"Invalid expiration in credential is not valid" - {
withData(
nameFn = ::credentialNameFn,
dataProvider.getCredentialWithType(
verifier.identifier,
attributeTypes = listOf(ConstantIndex.AtomicAttribute2023.vcType)
Expand All @@ -235,6 +233,7 @@ class ValidatorVcTest : FreeSpec() {

"No expiration date is valid" - {
withData(
nameFn = ::credentialNameFn,
dataProvider.getCredentialWithType(
verifier.identifier,
attributeTypes = listOf(ConstantIndex.AtomicAttribute2023.vcType)
Expand All @@ -251,6 +250,7 @@ class ValidatorVcTest : FreeSpec() {

"Invalid jws-expiration in credential is not valid" - {
withData(
nameFn = ::credentialNameFn,
dataProvider.getCredentialWithType(
verifier.identifier,
attributeTypes = listOf(ConstantIndex.AtomicAttribute2023.vcType)
Expand All @@ -268,6 +268,7 @@ class ValidatorVcTest : FreeSpec() {

"Expiration not matching in credential is not valid" - {
withData(
nameFn = ::credentialNameFn,
dataProvider.getCredentialWithType(
verifier.identifier,
attributeTypes = listOf(ConstantIndex.AtomicAttribute2023.vcType)
Expand All @@ -289,6 +290,7 @@ class ValidatorVcTest : FreeSpec() {

"Invalid NotBefore in credential is not valid" - {
withData(
nameFn = ::credentialNameFn,
dataProvider.getCredentialWithType(
verifier.identifier,
attributeTypes = listOf(ConstantIndex.AtomicAttribute2023.vcType)
Expand All @@ -308,6 +310,7 @@ class ValidatorVcTest : FreeSpec() {

"Invalid issuance date in credential is not valid" - {
withData(
nameFn = ::credentialNameFn,
dataProvider.getCredentialWithType(
verifier.identifier,
attributeTypes = listOf(ConstantIndex.AtomicAttribute2023.vcType)
Expand All @@ -325,6 +328,7 @@ class ValidatorVcTest : FreeSpec() {

"Issuance date and not before not matching is not valid" - {
withData(
nameFn = ::credentialNameFn,
dataProvider.getCredentialWithType(
verifier.identifier,
attributeTypes = listOf(ConstantIndex.AtomicAttribute2023.vcType)
Expand All @@ -341,6 +345,12 @@ class ValidatorVcTest : FreeSpec() {
}
}

private fun credentialNameFn(it: CredentialToBeIssued): String =
when (it) {
is CredentialToBeIssued.Iso -> it.attributeType;is CredentialToBeIssued.Vc -> it.attributeType

}

private fun issueCredential(
credential: CredentialToBeIssued,
issuanceDate: Instant = Clock.System.now(),
Expand Down

0 comments on commit 05730b0

Please sign in to comment.