8
8
. "github.com/smartystreets/goconvey/convey"
9
9
)
10
10
11
- func Test_FromHeadersOrDefault (t * testing.T ) {
11
+ func Test_FromHeadersOrDefault_With_Forwarded_Headers (t * testing.T ) {
12
12
13
13
Convey ("Given a list of test cases" , t , func () {
14
14
tests := []struct {
@@ -184,7 +184,7 @@ func Test_FromHeadersOrDefault(t *testing.T) {
184
184
}
185
185
186
186
du .JoinPath ()
187
- builder := FromHeadersOrDefault (& h , du )
187
+ builder := FromHeadersOrDefault (& h , & http. Request {}, du )
188
188
So (builder , ShouldNotBeNil )
189
189
So (builder .URL , ShouldNotBeNil )
190
190
So (builder .URL .String (), ShouldEqual , tt .want )
@@ -195,6 +195,61 @@ func Test_FromHeadersOrDefault(t *testing.T) {
195
195
196
196
}
197
197
198
+ func Test_FromHeadersOrDefault_Without_Forwarded_Headers (t * testing.T ) {
199
+
200
+ Convey ("Given a list of test cases" , t , func () {
201
+ tests := []struct {
202
+ incomingRequestHost string
203
+ defaultURL string
204
+ want string
205
+ }{
206
+ // Without incoming request host
207
+ {
208
+ "" ,
209
+ "http://localhost:8080/" ,
210
+ "http://localhost:8080/" ,
211
+ },
212
+ // With incoming request host and no port
213
+ {
214
+ "localhost" ,
215
+ "http://localhost:8080/" ,
216
+ "http://localhost/" ,
217
+ },
218
+ // With incoming request host and different port
219
+ {
220
+ "localhost:6789" ,
221
+ "http://localhost:8080/" ,
222
+ "http://localhost:6789/" ,
223
+ },
224
+ {
225
+ "10.30.100.123:4567" ,
226
+ "http://localhost:8080/" ,
227
+ "http://10.30.100.123:4567/" ,
228
+ },
229
+ // With incoming request host and default URL with path
230
+ {
231
+ "localhost" ,
232
+ "http://localhost:8080/some/path" ,
233
+ "http://localhost/some/path" ,
234
+ },
235
+ }
236
+
237
+ for _ , tt := range tests {
238
+ du , err := url .Parse (tt .defaultURL )
239
+ So (err , ShouldBeNil )
240
+
241
+ incomingRequest := & http.Request {Host : tt .incomingRequestHost }
242
+
243
+ builder := FromHeadersOrDefault (& http.Header {}, incomingRequest , du )
244
+ So (builder , ShouldNotBeNil )
245
+ So (builder .URL , ShouldNotBeNil )
246
+ So (builder .URL .String (), ShouldEqual , tt .want )
247
+
248
+ }
249
+
250
+ })
251
+ }
252
+
198
253
func TestBuilder_BuildLink (t * testing.T ) {
199
254
200
255
Convey ("Given a list of test cases" , t , func () {
0 commit comments