@@ -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
@@ -57,10 +57,10 @@ internal class LinkCheckerTest {
5757 val path = javaClass.getResource(" /linkChecker/Demo.md" )?.toURI()?.toPath()?.parent
5858 assertThat(path).isNotNull.isDirectory.isReadable
5959
60- fun ok (): ResponseMeta = 200 to mapOf ()
61- fun notFound (): ResponseMeta = 404 to mapOf ()
62- fun redirect (code : Int , target : String ): ResponseMeta = code to mapOf (" Location" to target)
63- fun rateLimitGH (awaitMillis : Long ): ResponseMeta = 403 to mapOf (" x-ratelimit-reset" to Instant .now().plusMillis(awaitMillis).epochSecond.toString())
60+ fun ok (): ResponseMeta = { 200 to mapOf () }
61+ fun notFound (): ResponseMeta = { 404 to mapOf () }
62+ fun redirect (code : Int , target : String ): ResponseMeta = { code to mapOf (" Location" to target) }
63+ fun rateLimitGH (awaitMillis : Long ): ResponseMeta = { 403 to mapOf (" x-ratelimit-reset" to Instant .now().plusMillis(awaitMillis).epochSecond.toString()) }
6464
6565 // Check links via: curl --silent -X GET --head 'URL'
6666 val client = MockedHttpClient .fromMeta(
@@ -75,7 +75,6 @@ internal class LinkCheckerTest {
7575 redirect(301 , " https://schema.org/" ),
7676 ),
7777 " https://github.com/androidx/androidx/blob/androidx-main/build.gradle" to listOf (
78- // todo Calculate header value on building response
7978 // Will wait some time
8079 rateLimitGH(2111 ),
8180 // Will wait zero time
@@ -154,8 +153,9 @@ internal class LinkCheckerTest {
154153 fun fromMeta (responses : Map <String , List <ResponseMeta >>): HttpClient = fromBuilders(
155154 responses.mapValues {
156155 it.value
157- .map<ResponseMeta , ResponseBuilder <Any ?>> { meta ->
156+ .map<ResponseMeta , ResponseBuilder <Any ?>> { metaBuilder ->
158157 { req ->
158+ val meta = metaBuilder()
159159 MockedHttpResponse .fromRequest(req, meta.first, meta.second.mapValues { h -> listOf (h.value) })
160160 }
161161 }
0 commit comments