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

Function TestWrite

context_test.go:18–55  ·  view source on GitHub ↗

normal write

(t *testing.T)

Source from the content-addressed store, hash-verified

16
17// normal write
18func TestWrite(t *testing.T) {
19 param := &InitContextParam{
20 t,
21 &Animal{},
22 "",
23 test.ToDefault,
24 }
25
26 // init param
27 context := initResponseContext(param)
28
29 exceptedObject := &Animal{
30 "Black",
31 true,
32 }
33
34 animalJson, err := json.Marshal(exceptedObject)
35 test.Nil(t, err)
36
37 // call function
38 status := http.StatusNotFound
39 _, contextErr := context.Write(status, animalJson)
40 test.Nil(t, contextErr)
41
42 // check result
43
44 // header
45 contentType := context.response.header.Get(HeaderContentType)
46
47 // check the default value
48 test.Contains(t, CharsetUTF8, contentType)
49 test.Equal(t, status, context.response.Status)
50
51 // body
52 body := string(context.response.body)
53
54 test.Equal(t, string(animalJson), body)
55}
56
57// normal write string
58func TestWriteString(t *testing.T) {

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected