(t *testing.T)
| 135 | } |
| 136 | |
| 137 | func 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 | |
| 166 | func TestUnSerializeInvalid(t *testing.T) { |
| 167 | res := UnSerialize("invalid json {{{") |
nothing calls this directly
no test coverage detected