Skip to content

Commit 82a953d

Browse files
authored
Test failing online check against a mock HTTP server (#2598)
1 parent a44aa0f commit 82a953d

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

test/online/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
[deps]
22
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
3+
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
34
IOCapture = "b5f81e59-6552-4d32-b1f0-c071b021bf89"
45
MarkdownAST = "d0879d2d-cac2-40c8-9cee-1863dc0c7391"
6+
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
57
RegistryInstances = "2792f1a3-b283-48e8-9a74-f99dce5104f3"
68
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
79

test/online/online_linkcheck.jl

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,21 @@ module OnlineLinkcheckTests
22
using Documenter: Documenter, MarkdownAST, AbstractTrees
33
using Documenter: linkcheck
44
using Markdown
5+
using HTTP
56
using 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

6686
end
6787

88+
# Close the mock HTTP server
89+
close(server)
90+
6891
end # module

0 commit comments

Comments
 (0)