Skip to content

Commit

Permalink
Fixing issue where saving grouped results wasn't setting the test sui…
Browse files Browse the repository at this point in the history
…te index correctly
  • Loading branch information
craigatk committed Jan 17, 2020
1 parent f1f8dcb commit b93de60
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class TestRunDatabaseRepository(private val dslContext: DSLContext) : TestRunRep

logger.info("Inserted test run $publicId")

saveTestSuites(testSuites, testRunDB.id, null, configuration)
saveTestSuites(testSuites, testRunDB.id, null, 0, configuration)
}

testRunSummary
Expand All @@ -57,24 +57,34 @@ class TestRunDatabaseRepository(private val dslContext: DSLContext) : TestRunRep

logger.info("Inserted test run $publicId")

var testSuiteStartingIndex = 0

groupedResults.groupedTestSuites.forEach { groupedTestSuites ->
val testSuiteGroupDB = groupedTestSuites.toDB(testRunDB.id)
testSuiteGroupDao.insert(testSuiteGroupDB)

saveTestSuites(groupedTestSuites.testSuites, testRunDB.id, testSuiteGroupDB.id, configuration)
saveTestSuites(groupedTestSuites.testSuites, testRunDB.id, testSuiteGroupDB.id, testSuiteStartingIndex, configuration)

testSuiteStartingIndex += groupedTestSuites.testSuites.size
}
}

testRunSummary
}

private fun saveTestSuites(testSuites: List<ParsedTestSuite>, testRunId: Long, testGroupId: Long?, configuration: Configuration) {
private fun saveTestSuites(
testSuites: List<ParsedTestSuite>,
testRunId: Long,
testGroupId: Long?,
testSuiteStartingIndex: Int,
configuration: Configuration
) {
val testSuiteDao = TestSuiteDao(configuration)
val testCaseDao = TestCaseDao(configuration)
val testFailureDao = TestFailureDao(configuration)

testSuites.forEachIndexed { testSuiteIdx, testSuite ->
val testSuiteDB = testSuite.toDB(testRunId, testGroupId, testSuiteIdx + 1)
val testSuiteDB = testSuite.toDB(testRunId, testGroupId, testSuiteStartingIndex + testSuiteIdx + 1)
testSuiteDao.insert(testSuiteDB)

testSuite.testCases.forEachIndexed { testCaseIdx, testCase ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import projektor.server.api.SaveResultsResponse
import strikt.api.expectThat
import strikt.assertions.hasSize
import strikt.assertions.isEqualTo
import strikt.assertions.isNotNull

@KtorExperimentalAPI
class SaveGroupedResultsApplicationTest : ApplicationTestCase() {
Expand All @@ -37,9 +38,24 @@ class SaveGroupedResultsApplicationTest : ApplicationTestCase() {
val testRun = await untilNotNull { testRunDao.fetchOneByPublicId(publicId) }
assertNotNull(testRun)

val testSuites = testSuiteDao.fetchByTestRunId(testRun.id)
expectThat(testSuites).hasSize(3)

expectThat(testSuites.find { it.idx == 1 }).isNotNull()
expectThat(testSuites.find { it.idx == 2 }).isNotNull()
expectThat(testSuites.find { it.idx == 3 }).isNotNull()

val testSuiteGroups = testSuiteGroupDao.fetchByTestRunId(testRun.id)
expectThat(testSuiteGroups)
.hasSize(2)

val testSuiteGroup1 = testSuiteGroups.find { it.groupName == "Group1" }
assertNotNull(testSuiteGroup1)
expectThat(testSuiteDao.fetchByTestSuiteGroupId(testSuiteGroup1.id)).hasSize(2)

val testSuiteGroup2 = testSuiteGroups.find { it.groupName == "Group2" }
assertNotNull(testSuiteGroup2)
expectThat(testSuiteDao.fetchByTestSuiteGroupId(testSuiteGroup2.id)).hasSize(1)
}
}
}
Expand Down

0 comments on commit b93de60

Please sign in to comment.