MCPcopy
hub / github.com/andeya/pholcus / TestSerializeUnSerialize

Function TestSerializeUnSerialize

app/downloader/request/request_test.go:137–164  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

135}
136
137func TestSerializeUnSerialize(t *testing.T) {
138 r := &Request{
139 Spider: "s", URL: "http://example.com", Rule: "r",
140 Method: "POST", PostData: "a=1",
141 Header: http.Header{"X-Custom": {"v"}},
142 EnableCookie: true,
143 Temp: Temp{"k": "v"},
144 }
145 r.Prepare()
146
147 res := r.Serialize()
148 if res.IsErr() {
149 t.Fatalf("Serialize: %v", res.Err())
150 }
151 s := res.Unwrap()
152 if s == "" {
153 t.Error("Serialize returned empty string")
154 }
155
156 ures := UnSerialize(s)
157 if ures.IsErr() {
158 t.Fatalf("UnSerialize: %v", ures.Err())
159 }
160 req := ures.Unwrap()
161 if req.URL != r.URL || req.Method != r.Method || req.Spider != r.Spider {
162 t.Errorf("UnSerialize mismatch: got %+v", req)
163 }
164}
165
166func TestUnSerializeInvalid(t *testing.T) {
167 res := UnSerialize("invalid json {{{")

Callers

nothing calls this directly

Calls 5

PrepareMethod · 0.95
SerializeMethod · 0.95
UnSerializeFunction · 0.85
UnwrapMethod · 0.80
ErrorMethod · 0.65

Tested by

no test coverage detected