@@ -28,7 +28,7 @@ import javax.net.ssl.SSLSession
2828import kotlin.io.path.toPath
2929
3030typealias ResponseBuilder <T > = (HttpRequest ) -> HttpResponse <T >
31- typealias ResponseMeta = Pair <Int , Map <String , String >>
31+ typealias ResponseMeta = () -> Pair <Int , Map <String , String >>
3232
3333internal class LinkCheckerTest {
3434
@@ -55,10 +55,10 @@ internal class LinkCheckerTest {
5555 val path = javaClass.getResource(" /linkChecker/Demo.md" )?.toURI()?.toPath()?.parent
5656 assertThat(path).isNotNull.isDirectory.isReadable
5757
58- fun ok (): ResponseMeta = 200 to mapOf ()
59- fun notFound (): ResponseMeta = 404 to mapOf ()
60- fun redirect (code : Int , target : String ): ResponseMeta = code to mapOf (" Location" to target)
61- fun rateLimitGH (awaitMillis : Long ): ResponseMeta = 403 to mapOf (" x-ratelimit-reset" to Instant .now().plusMillis(awaitMillis).epochSecond.toString())
58+ fun ok (): ResponseMeta = { 200 to mapOf () }
59+ fun notFound (): ResponseMeta = { 404 to mapOf () }
60+ fun redirect (code : Int , target : String ): ResponseMeta = { code to mapOf (" Location" to target) }
61+ fun rateLimitGH (awaitMillis : Long ): ResponseMeta = { 403 to mapOf (" x-ratelimit-reset" to Instant .now().plusMillis(awaitMillis).epochSecond.toString()) }
6262
6363 // Check links via: curl --silent -X GET --head 'URL'
6464 val client = MockedHttpClient .fromMeta(
@@ -73,7 +73,6 @@ internal class LinkCheckerTest {
7373 redirect(301 , " https://schema.org/" ),
7474 ),
7575 " https://github.com/androidx/androidx/blob/androidx-main/build.gradle" to listOf (
76- // todo Calculate header value on building response
7776 // Will wait some time
7877 rateLimitGH(2111 ),
7978 // Will wait zero time
@@ -152,8 +151,9 @@ internal class LinkCheckerTest {
152151 fun fromMeta (responses : Map <String , List <ResponseMeta >>): HttpClient = fromBuilders(
153152 responses.mapValues {
154153 it.value
155- .map<ResponseMeta , ResponseBuilder <Any ?>> { meta ->
154+ .map<ResponseMeta , ResponseBuilder <Any ?>> { metaBuilder ->
156155 { req ->
156+ val meta = metaBuilder()
157157 MockedHttpResponse .fromRequest(req, meta.first, meta.second.mapValues { h -> listOf (h.value) })
158158 }
159159 }
0 commit comments