MCPcopy Index your code
hub / github.com/dunglas/httpsfv / TestOfficialTestSuiteSerialization

Function TestOfficialTestSuiteSerialization

httpwg_test.go:256–310  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

254}
255
256func TestOfficialTestSuiteSerialization(t *testing.T) {
257 t.Parallel()
258
259 const dir = "structured-field-tests/serialisation-tests/"
260
261 f, _ := os.Open(dir)
262 files, _ := f.Readdir(-1)
263
264 for _, fi := range files {
265 n := fi.Name()
266 if !strings.HasSuffix(n, ".json") {
267 continue
268 }
269
270 file, _ := os.Open(dir + n)
271 dec := json.NewDecoder(file)
272 dec.UseNumber()
273
274 var tests []test
275 _ = dec.Decode(&tests)
276
277 for _, te := range tests {
278 var sfv StructuredFieldValue
279
280 switch te.HeaderType {
281 case ITEM:
282 sfv = valToItem(te.Expected)
283 case LIST:
284 sfv = valToList(te.Expected)
285 case DICTIONARY:
286 sfv = valToDictionary(te.Expected)
287 default:
288 panic("unknown header type")
289 }
290
291 canonical, err := Marshal(sfv)
292
293 if te.MustFail && err == nil {
294 t.Errorf("%s: %s: must fail", n, te.Name)
295
296 continue
297 }
298
299 if (!te.MustFail && !te.CanFail) && err != nil {
300 t.Errorf("%s: %s: must not fail, got error %s", n, te.Name, err)
301
302 continue
303 }
304
305 if err == nil && te.Canonical[0] != canonical {
306 t.Errorf("%s: %s: %#v expected, got %#v", n, te.Name, te.Canonical[0], canonical)
307 }
308 }
309 }
310}

Callers

nothing calls this directly

Calls 4

valToItemFunction · 0.85
valToListFunction · 0.85
valToDictionaryFunction · 0.85
MarshalFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…