def verifyAggregateFileAgainstChunkMetadata()

in src/main/scala/com/gu/zuora/fullexport/Impl.scala [242:258]


  def verifyAggregateFileAgainstChunkMetadata(objectName: String): Unit = {
    logger.info(s"Verifying total record count for $objectName.csv ...")
    val metadataTotalRecordCount = scratchDir
      .toFile
      .listRecursively
      .filter(_.name.startsWith(s"$objectName-"))
      .filter(_.extension.contains(".metadata"))
      .map(file => file.contentAsString.pipe(read[JobResults](_)))
      .flatMap(_.batches.map(_.recordCount))
      .sum
    val aggregateFileRecordCount = file"$outputDir/$objectName.csv".lineIterator.size - (1 /* header */ )
    Assert(
      s"$objectName.csv aggregate record count should match total metadata record count: $metadataTotalRecordCount =/= $aggregateFileRecordCount",
      metadataTotalRecordCount == aggregateFileRecordCount
    )
    logger.info(s"$objectName record count verified against chunk metadata: $metadataTotalRecordCount = $aggregateFileRecordCount")
  }