This repository has been archived by the owner on May 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender_content_test.go
64 lines (53 loc) · 1.74 KB
/
render_content_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package detour
import (
"net/http"
"github.com/smartystreets/assertions/should"
)
func (this *ResultFixture) TestContentResult() {
result := ContentResult{
StatusCode: 456,
Content: "Hello, World!",
Headers: map[string]string{"custom-header": "custom-value"},
}
this.render(result)
this.assertStatusCode(456)
this.assertContent("Hello, World!")
this.assertHasHeader(contentTypeHeader, plaintextContentType)
this.assertHasHeader("Custom-Header", "custom-value")
this.So(len(this.response.HeaderMap), should.Equal, 2)
}
func (this *ResultFixture) TestContentResult_WithCustomContentType() {
result := ContentResult{
StatusCode: 456,
ContentType: "application/custom-text",
Content: "Hello, World!",
Headers: map[string]string{"another-header": "another-value"},
}
this.render(result)
this.assertStatusCode(456)
this.assertContent("Hello, World!")
this.assertHasHeader(contentTypeHeader, "application/custom-text")
this.assertHasHeader("Another-Header", "another-value")
this.So(len(this.response.HeaderMap), should.Equal, 2)
}
func (this *ResultFixture) TestContentResult_WithCustomContentTypeListedTwice() {
result := ContentResult{
StatusCode: 456,
ContentType: "application/custom-text",
Content: "Hello, World!",
Headers: map[string]string{"Content-Type": "ignored-content-type"},
}
this.render(result)
this.assertStatusCode(456)
this.assertContent("Hello, World!")
this.assertHasHeader(contentTypeHeader, "application/custom-text")
this.So(len(this.response.HeaderMap), should.Equal, 1)
}
func (this *ResultFixture) TestContentResult_StatusCodeDefaultsTo200() {
result := ContentResult{
StatusCode: 0,
Content: "Status OK",
}
this.render(result)
this.assertStatusCode(http.StatusOK)
}