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
/
render_test.go
66 lines (54 loc) · 1.89 KB
/
render_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
65
66
package detour
import (
"errors"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
"github.com/smartystreets/assertions/should"
"github.com/smartystreets/gunit"
)
func TestResultFixture(t *testing.T) {
gunit.Run(new(ResultFixture), t)
}
type ResultFixture struct {
*gunit.Fixture
response *httptest.ResponseRecorder
request *http.Request
}
func (this *ResultFixture) Setup() {
this.response = httptest.NewRecorder()
this.request = httptest.NewRequest("GET", "/", nil)
}
func (this *ResultFixture) setRequestURLCallback(value string) {
query := this.request.URL.Query()
query.Set("callback", value)
this.request.URL.RawQuery = query.Encode()
}
func (this *ResultFixture) render(result Renderer) {
result.Render(this.response, this.request)
}
func (this *ResultFixture) assertStatusCode(expected int) {
this.So(this.response.Result().StatusCode, should.Equal, expected)
}
func (this *ResultFixture) assertContent(expected string) {
body, _ := ioutil.ReadAll(this.response.Result().Body)
this.So(string(body), should.EqualTrimSpace, expected)
}
func (this *ResultFixture) assertNoHeaders() {
this.So(this.response.Result().Header, should.HaveLength, 0)
}
func (this *ResultFixture) assertHasHeader(key, value string) {
this.So(this.response.Result().Header, should.ContainKey, key)
this.So(this.response.Result().Header[key], should.Contain, value)
}
///////////////////////////////////////////////////////////////////////////////
type BadJSON struct{}
func (this *BadJSON) Error() string { return "Implement the error interface." }
func (this *BadJSON) MarshalJSON() ([]byte, error) { return nil, errors.New("GOPHERS!") }
///////////////////////////////////////////////////////////////////////////////
func TestFirstNonBlank_WhenAllBlank_ReturnDefaultOfBlank(t *testing.T) {
if actual := firstNonBlank("", "", ""); actual != "" {
t.Error("Failed, expected '', got:", actual)
}
}