forked from yaitoo/xun
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewer_xml_test.go
More file actions
44 lines (33 loc) · 827 Bytes
/
Copy pathviewer_xml_test.go
File metadata and controls
44 lines (33 loc) · 827 Bytes
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
package xun
import (
"encoding/xml"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/require"
)
func TestXmlViewerRenderError(t *testing.T) {
v := &XmlViewer{}
data := make(chan int)
r := httptest.NewRequest(http.MethodGet, "/", nil)
rw := httptest.NewRecorder()
rw.Code = -1
ctx := &Context{
Request: r,
Response: NewResponseWriter(rw),
}
// should get raw error when xml.marshal fails, and StatusCode should be written
err := v.Render(ctx, data)
_, ok := err.(*xml.UnsupportedTypeError)
require.True(t, ok)
require.Equal(t, -1, rw.Code)
r = httptest.NewRequest(http.MethodGet, "/", nil)
rw = httptest.NewRecorder()
ctx = &Context{
Request: r,
Response: NewResponseWriter(rw),
}
err = v.Render(ctx, "")
require.NoError(t, err)
require.Equal(t, 200, rw.Code)
}