@@ -28,7 +28,7 @@ import javax.net.ssl.SSLSession
28
28
import kotlin.io.path.toPath
29
29
30
30
typealias ResponseBuilder <T > = (HttpRequest ) -> HttpResponse <T >
31
- typealias ResponseMeta = Pair <Int , Map <String , String >>
31
+ typealias ResponseMeta = () -> Pair <Int , Map <String , String >>
32
32
33
33
internal class LinkCheckerTest {
34
34
@@ -57,10 +57,10 @@ internal class LinkCheckerTest {
57
57
val path = javaClass.getResource(" /linkChecker/Demo.md" )?.toURI()?.toPath()?.parent
58
58
assertThat(path).isNotNull.isDirectory.isReadable
59
59
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()) }
64
64
65
65
// Check links via: curl --silent -X GET --head 'URL'
66
66
val client = MockedHttpClient .fromMeta(
@@ -75,7 +75,6 @@ internal class LinkCheckerTest {
75
75
redirect(301 , " https://schema.org/" ),
76
76
),
77
77
" https://github.com/androidx/androidx/blob/androidx-main/build.gradle" to listOf (
78
- // todo Calculate header value on building response
79
78
// Will wait some time
80
79
rateLimitGH(2111 ),
81
80
// Will wait zero time
@@ -154,8 +153,9 @@ internal class LinkCheckerTest {
154
153
fun fromMeta (responses : Map <String , List <ResponseMeta >>): HttpClient = fromBuilders(
155
154
responses.mapValues {
156
155
it.value
157
- .map<ResponseMeta , ResponseBuilder <Any ?>> { meta ->
156
+ .map<ResponseMeta , ResponseBuilder <Any ?>> { metaBuilder ->
158
157
{ req ->
158
+ val meta = metaBuilder()
159
159
MockedHttpResponse .fromRequest(req, meta.first, meta.second.mapValues { h -> listOf (h.value) })
160
160
}
161
161
}
0 commit comments