All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.http4k.tracing.renderer.MarkdownTraceStepCountsTable.kt Maven / Gradle / Ivy

There is a newer version: 5.41.0.0
Show newest version
package org.http4k.tracing.renderer

import org.http4k.tracing.Trace
import org.http4k.tracing.TraceRender
import org.http4k.tracing.TraceRenderer
import org.http4k.tracing.TraceStep

object MarkdownTraceStepCountsTable : TraceRenderer {
    override fun render(scenarioName: String, steps: List): TraceRender {
        val body = steps.filterIsInstance()
            .map { it to it.counts() }
            .sortedByDescending { it.second }
            .joinToString("\n") {
                "|\t${it.first.origin.name}\t|\t${it.first.target.name}\t|\t${it.first.request}\t|\t${it.second}\t|"
            }

        val header = """
## $scenarioName - Trace Step Counts

| Origin | Target | Request |  Steps  |
|:------:|:------:|:-------:|:-------:|
"""
        return TraceRender("$scenarioName - Trace Step Counts", "MD", header + body)
    }

    private fun Trace.counts(): Int = 1 + children.fold(0) { acc, next -> acc + next.counts()}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy