Skip to content

Commit

Permalink
Check number of output fields
Browse files Browse the repository at this point in the history
  • Loading branch information
pondzix committed Mar 25, 2024
1 parent 85212e7 commit 6d2afef
Showing 1 changed file with 24 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ class TransformStructuredSpec extends Specification {
def onlyAtomic = {
val event = createEvent()
val batchInfo = Result(List.empty, List.empty) // no custom entities
val expectedOutput = List(
val expectedAtomic = List(
NamedValue("event_id", Json.fromString(eventId.toString)),
NamedValue("collector_tstamp", Json.fromString(now.toString)),
NamedValue("geo_region", Json.Null)
)

assertSuccessful(event, batchInfo, expectedOutput)
assertSuccessful(event, batchInfo, expectedAtomic = expectedAtomic)
}

def unstruct = {
Expand All @@ -114,7 +114,7 @@ class TransformStructuredSpec extends Specification {
)
val expectedOutput = List(NamedValue(name = "unstruct_event_com_example_my_schema_1", value = json"""{ "my_string": "abc"}"""))

assertSuccessful(inputEvent, batchInfo, expectedOutput)
assertSuccessful(inputEvent, batchInfo, expectedAllEntities = expectedOutput)
}

def oneContext = {
Expand All @@ -128,7 +128,7 @@ class TransformStructuredSpec extends Specification {
NamedValue(name = "contexts_com_example_my_schema_1", value = json"""[{ "_schema_version": "1-0-0", "my_string": "abc"}]""")
)

assertSuccessful(inputEvent, batchInfo, expectedOutput)
assertSuccessful(inputEvent, batchInfo, expectedAllEntities = expectedOutput)
}

def twoContextsDifferentMajor = {
Expand Down Expand Up @@ -157,7 +157,7 @@ class TransformStructuredSpec extends Specification {
)
)

assertSuccessful(inputEvent, batchInfo, expectedOutput)
assertSuccessful(inputEvent, batchInfo, expectedAllEntities = expectedOutput)
}

def twoContextsSameMajor = {
Expand All @@ -184,7 +184,7 @@ class TransformStructuredSpec extends Specification {
)
)

assertSuccessful(inputEvent, batchTypesInfo, expectedOutput)
assertSuccessful(inputEvent, batchTypesInfo, expectedAllEntities = expectedOutput)
}

def onlyAtomicAllTypes = {
Expand All @@ -208,7 +208,7 @@ class TransformStructuredSpec extends Specification {
NamedValue("tr_total", json"12.34")
)

assertSuccessful(event, batchInfo, expectedOutput)
assertSuccessful(event, batchInfo, expectedAtomic = expectedOutput)
}

def unstructAllTypes = {
Expand All @@ -225,7 +225,7 @@ class TransformStructuredSpec extends Specification {
)
)

assertSuccessful(inputEvent, batchInfo, expectedOutput)
assertSuccessful(inputEvent, batchInfo, expectedAllEntities = expectedOutput)
}

def contextAllTypes = {
Expand Down Expand Up @@ -257,7 +257,7 @@ class TransformStructuredSpec extends Specification {
)
)

assertSuccessful(inputEvent, batchInfo, expectedOutput)
assertSuccessful(inputEvent, batchInfo, expectedAllEntities = expectedOutput)
}

def unstructNoData = {
Expand All @@ -276,7 +276,7 @@ class TransformStructuredSpec extends Specification {
)
)

assertSuccessful(inputEvent, batchTypesInfo, expectedOutput)
assertSuccessful(inputEvent, batchTypesInfo, expectedAllEntities = expectedOutput)
}

def contextsNoData = {
Expand All @@ -295,7 +295,7 @@ class TransformStructuredSpec extends Specification {
)
)

assertSuccessful(inputEvent, batchTypesInfo, expectedOutput)
assertSuccessful(inputEvent, batchTypesInfo, expectedAllEntities = expectedOutput)
}

def unstructNoFamily = {
Expand Down Expand Up @@ -327,7 +327,7 @@ class TransformStructuredSpec extends Specification {
)
)

assertSuccessful(inputEvent, batchTypesInfo, expectedOutput)
assertSuccessful(inputEvent, batchTypesInfo, expectedAllEntities = expectedOutput)
}

def contextNoFamily = {
Expand Down Expand Up @@ -365,7 +365,7 @@ class TransformStructuredSpec extends Specification {
)
)

assertSuccessful(inputEvent, batchTypesInfo, expectedOutput)
assertSuccessful(inputEvent, batchTypesInfo, expectedAllEntities = expectedOutput)
}

def atomicTooManyDecimalPoints = {
Expand Down Expand Up @@ -514,18 +514,23 @@ class TransformStructuredSpec extends Specification {
private def assertSuccessful(
event: Event,
batchInfo: Result,
shouldExist: List[NamedValue[Json]] = List.empty,
shouldNotExist: List[String] = List.empty
expectedAtomic: List[NamedValue[Json]] = List.empty,
expectedAllEntities: List[NamedValue[Json]] = List.empty,
shouldNotExist: List[String] = List.empty
) = {
val result = Transform.transformEvent[Json](BadRowProcessor("test-loader", "0.0.0"), TestCaster, event, batchInfo)

result must beRight { actualValues: Vector[NamedValue[Json]] =>
val actualFieldNames = actualValues.map(_.name)

val assertExist: MatchResult[Any] = actualValues must containAllOf(shouldExist)
val assertNotExist: MatchResult[Any] = actualFieldNames must not(containAnyOf(shouldNotExist))
val noDuplicates: MatchResult[Any] = actualFieldNames.distinct.size must beEqualTo(actualFieldNames.size)
assertExist and assertNotExist and noDuplicates
val assertAtomicExist: MatchResult[Any] = actualValues must containAllOf(expectedAtomic)
val assertEntitiesExist: MatchResult[Any] = actualValues must containAllOf(expectedAllEntities)
val assertNotExist: MatchResult[Any] = actualFieldNames must not(containAnyOf(shouldNotExist))
val noDuplicates: MatchResult[Any] = actualFieldNames.distinct.size must beEqualTo(actualFieldNames.size)
val totalNumberOfFields: MatchResult[Any] =
actualFieldNames.size must beEqualTo(128 + expectedAllEntities.size) // atomic + entities only

assertAtomicExist and assertEntitiesExist and assertNotExist and noDuplicates and totalNumberOfFields
}
}

Expand Down

0 comments on commit 6d2afef

Please sign in to comment.