Skip to content

Commit

Permalink
inject testinfo thrugh stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
edgao committed Sep 10, 2024
1 parent 5a7f8ee commit 70220ef
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import kotlin.test.fail
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import org.apache.commons.lang3.RandomStringUtils
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.TestInfo
import org.junit.jupiter.api.parallel.Execution
import org.junit.jupiter.api.parallel.ExecutionMode

Expand All @@ -48,16 +50,25 @@ abstract class IntegrationTest(
// stream name doesn't need to be randomized, only the namespace.
val randomizedNamespace = "test$timestampString$randomSuffix"

/**
* This field is not initialized until after the constructor is called.
*/
lateinit var testInfo: TestInfo
@BeforeEach
fun setup(testInfo: TestInfo) {
this.testInfo = testInfo
}

fun dumpAndDiffRecords(
canonicalExpectedRecords: List<OutputRecord>,
streamName: String,
streamNamespace: String?,
extractPrimaryKey: (OutputRecord) -> List<Any?> = { emptyList() },
extractCursor: ((OutputRecord) -> Any?)? = null,
) {
val actualRecords: List<OutputRecord> = dataDumper.dumpRecords(streamName, streamNamespace)
val actualRecords: List<OutputRecord> = dataDumper.dumpRecords(streamName, streamNamespace, testInfo)
val expectedRecords: List<OutputRecord> =
canonicalExpectedRecords.map { recordMangler.mangleRecord(it) }
canonicalExpectedRecords.map { recordMangler.mangleRecord(it, testInfo) }

RecordDiffer(extractPrimaryKey, extractCursor)
.diffRecords(expectedRecords, actualRecords)
Expand Down Expand Up @@ -154,9 +165,9 @@ data class Record(
fun interface DestinationDataDumper {
// TODO we probably should compact this pair into a useful class
// (but not StreamDescriptor/AirbyteStreamNameNamespacePair :P )
fun dumpRecords(streamName: String, streamNamespace: String?): List<OutputRecord>
fun dumpRecords(streamName: String, streamNamespace: String?, testInfo: TestInfo): List<OutputRecord>
}

fun interface DestinationRecordMangler {
fun mangleRecord(expectedRecord: OutputRecord): OutputRecord
fun mangleRecord(expectedRecord: OutputRecord, testInfo: TestInfo): OutputRecord
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ package io.airbyte.integrations.destination.e2e_test

import io.airbyte.cdk.test.util.DestinationDataDumper
import io.airbyte.cdk.test.util.OutputRecord
import org.junit.jupiter.api.TestInfo

class E2eDestinationDataDumper : DestinationDataDumper {
override fun dumpRecords(streamName: String, streamNamespace: String?): List<OutputRecord> {
override fun dumpRecords(streamName: String, streamNamespace: String?, testInfo: TestInfo): List<OutputRecord> {
// TODO delete this
return listOf(
OutputRecord(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ package io.airbyte.integrations.destination.e2e_test

import io.airbyte.cdk.test.util.DestinationRecordMangler
import io.airbyte.cdk.test.util.OutputRecord
import org.junit.jupiter.api.TestInfo

class E2eDestinationRecordMangler : DestinationRecordMangler {
override fun mangleRecord(expectedRecord: OutputRecord): OutputRecord {
override fun mangleRecord(expectedRecord: OutputRecord, testInfo: TestInfo): OutputRecord {
// TODO delete this
return expectedRecord
// E2e destination doesn't actually write records, so we shouldn't even
Expand Down

0 comments on commit 70220ef

Please sign in to comment.