MCPcopy Create free account
hub / github.com/devfeel/dotweb / TestWriteString

Function TestWriteString

context_test.go:58–92  ·  view source on GitHub ↗

normal write string

(t *testing.T)

Source from the content-addressed store, hash-verified

56
57// normal write string
58func TestWriteString(t *testing.T) {
59 param := &InitContextParam{
60 t,
61 &Animal{},
62 "",
63 test.ToDefault,
64 }
65
66 // init param
67 context := initResponseContext(param)
68
69 exceptedObject := &Animal{
70 "Black",
71 true,
72 }
73
74 animalJson, err := json.Marshal(exceptedObject)
75 test.Nil(t, err)
76
77 // call function
78 // 这里是一个interface数组,用例需要小心.
79 contextErr := context.WriteString(string(animalJson))
80 test.Nil(t, contextErr)
81
82 // header
83 contentType := context.response.header.Get(HeaderContentType)
84 // 因writer中的header方法调用过http.Header默认设置
85 test.Contains(t, CharsetUTF8, contentType)
86 test.Equal(t, defaultHttpCode, context.response.Status)
87
88 // body
89 body := string(context.response.body)
90
91 test.Equal(t, string(animalJson), body)
92}
93
94func TestWriteJson(t *testing.T) {
95 param := &InitContextParam{

Callers

nothing calls this directly

Calls 6

NilFunction · 0.92
ContainsFunction · 0.92
EqualFunction · 0.92
initResponseContextFunction · 0.85
WriteStringMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected