@@ -21,6 +21,7 @@ import (
21
21
"strings"
22
22
"testing"
23
23
24
+ qt "github.com/frankban/quicktest"
24
25
"github.com/gohugoio/hugo/hugolib"
25
26
)
26
27
@@ -67,10 +68,10 @@ func TestGetRemoteRetry(t *testing.T) {
67
68
t .Parallel ()
68
69
69
70
temporaryHTTPCodes := []int {408 , 429 , 500 , 502 , 503 , 504 }
70
- numPages := 30
71
+ numPages := 20
71
72
72
73
handler := func (w http.ResponseWriter , r * http.Request ) {
73
- if rand .Intn (4 ) == 0 {
74
+ if rand .Intn (3 ) == 0 {
74
75
w .WriteHeader (temporaryHTTPCodes [rand .Intn (len (temporaryHTTPCodes ))])
75
76
return
76
77
}
@@ -81,9 +82,10 @@ func TestGetRemoteRetry(t *testing.T) {
81
82
srv := httptest .NewServer (http .HandlerFunc (handler ))
82
83
t .Cleanup (func () { srv .Close () })
83
84
84
- files := `
85
+ filesTemplate := `
85
86
-- hugo.toml --
86
87
disableKinds = ["home", "taxonomy", "term"]
88
+ timeout = "TIMEOUT"
87
89
[security]
88
90
[security.http]
89
91
urls = ['.*']
@@ -93,7 +95,7 @@ mediaTypes = ['text/plain']
93
95
{{ $opts := dict }}
94
96
{{ with resources.GetRemote $url $opts }}
95
97
{{ with .Err }}
96
- {{ errorf "Unable to get remote resource : %s " . }}
98
+ {{ errorf "Got Err: %s. Data : %v " . .Data }}
97
99
{{ else }}
98
100
Content: {{ .Content }}
99
101
{{ end }}
@@ -103,22 +105,41 @@ mediaTypes = ['text/plain']
103
105
`
104
106
105
107
for i := 0 ; i < numPages ; i ++ {
106
- files += fmt .Sprintf ("-- content/post/p%d.md --\n " , i )
108
+ filesTemplate += fmt .Sprintf ("-- content/post/p%d.md --\n " , i )
107
109
}
108
110
109
- files = strings .ReplaceAll (files , "URL" , srv .URL )
111
+ filesTemplate = strings .ReplaceAll (filesTemplate , "URL" , srv .URL )
110
112
111
- b := hugolib .NewIntegrationTestBuilder (
112
- hugolib.IntegrationTestConfig {
113
- T : t ,
114
- TxtarString : files ,
115
- },
116
- )
113
+ t .Run ("OK" , func (t * testing.T ) {
114
+ files := strings .ReplaceAll (filesTemplate , "TIMEOUT" , "60s" )
115
+ b := hugolib .NewIntegrationTestBuilder (
116
+ hugolib.IntegrationTestConfig {
117
+ T : t ,
118
+ TxtarString : files ,
119
+ },
120
+ )
117
121
118
- b .Build ()
122
+ b .Build ()
119
123
120
- for i := 0 ; i < numPages ; i ++ {
121
- b .AssertFileContent (fmt .Sprintf ("public/post/p%d/index.html" , i ), fmt .Sprintf ("Content: Response for /post/p%d/." , i ))
122
- }
124
+ for i := 0 ; i < numPages ; i ++ {
125
+ b .AssertFileContent (fmt .Sprintf ("public/post/p%d/index.html" , i ), fmt .Sprintf ("Content: Response for /post/p%d/." , i ))
126
+ }
127
+ })
128
+
129
+ t .Run ("Timeout" , func (t * testing.T ) {
130
+ files := strings .ReplaceAll (filesTemplate , "TIMEOUT" , "100ms" )
131
+ b , err := hugolib .NewIntegrationTestBuilder (
132
+ hugolib.IntegrationTestConfig {
133
+ T : t ,
134
+ TxtarString : files ,
135
+ },
136
+ ).BuildE ()
137
+
138
+ b .Assert (err , qt .IsNotNil )
139
+ b .AssertLogContains ("Got Err" )
140
+ b .AssertLogContains ("Retry timeout" )
141
+ b .AssertLogContains ("ContentLength:0" )
142
+
143
+ })
123
144
124
145
}
0 commit comments