@@ -2,8 +2,21 @@ module OnlineLinkcheckTests
22using Documenter: Documenter, MarkdownAST, AbstractTrees
33using Documenter: linkcheck
44using Markdown
5+ using HTTP
56using Test
67
8+ PORT = rand (10_000 : 40_000 )
9+ function lincheck_server_handler (req:: HTTP.Request )
10+ useragent = HTTP. header (req, " user-agent" )
11+ if startswith (useragent, " Mozilla/5.0" )
12+ return HTTP. Response (404 )
13+ elseif startswith (useragent, " curl" )
14+ return HTTP. Response (200 )
15+ end
16+ return HTTP. Response (500 )
17+ end
18+ server = HTTP. serve! (lincheck_server_handler, PORT)
19+
720@testset " Online linkcheck" begin
821
922 @testset " Successes" begin
@@ -25,14 +38,21 @@ using Test
2538 end
2639
2740 @testset " Empty User-Agent" begin
41+ # This used to point to
42+ #
43+ # https://www.intel.com/content/www/us/en/developer/tools/oneapi/mpi-library.html)
44+ #
45+ # but now we use a mock HTTP server, to guarantee that the server's behavior doesn't change.
2846 src = convert (
2947 MarkdownAST. Node,
30- md """
31- [Linkcheck Empty UA](https://www.intel.com/content/www/us/en/developer/tools/oneapi/mpi-library.html)
32- """
48+ Markdown. parse (
49+ """
50+ [Linkcheck Empty UA](http://localhost:$(PORT) /content/www/us/en/developer/tools/oneapi/mpi-library.html)
51+ """
52+ )
3353 )
3454
35- # The default user-agent fails (intel servers block it )
55+ # The default user-agent fails (server blocks it, returns a 500 )
3656 doc = Documenter. Document (; linkcheck = true , linkcheck_timeout = 20 )
3757 doc. blueprint. pages[" testpage" ] = Documenter. Page (" " , " " , " " , [], Documenter. Globals (), src)
3858 @test_logs (:error ,) @test linkcheck (doc) === nothing
@@ -65,4 +85,7 @@ using Test
6585
6686end
6787
88+ # Close the mock HTTP server
89+ close (server)
90+
6891end # module
0 commit comments