MCPcopy Create free account
hub / github.com/pquerna/ffjson / TestFuzzMapToType

Function TestFuzzMapToType

tests/fuzz_test.go:684–713  ·  view source on GitHub ↗

This contains maps. Since map order is random, we can expect the encoding order to be random Therefore we cannot use binary compare.

(t *testing.T)

Source from the content-addressed store, hash-verified

682// Since map order is random, we can expect the encoding order to be random
683// Therefore we cannot use binary compare.
684func TestFuzzMapToType(t *testing.T) {
685 base := &TTestMaps{}
686 ff := &XTestMaps{}
687 f := fuzz.New()
688 f.NumElements(0, 50)
689 f.NilChance(0.1)
690 f.Funcs(fuzzTime)
691 for i := 0; i < 100; i++ {
692 f.RandSource(rand.New(rand.NewSource(int64(i * 5275))))
693 f.Fuzz(base)
694 ff = &XTestMaps{*base}
695
696 bufbase, err := json.Marshal(base)
697 require.NoError(t, err, "base[%T] failed to Marshal", base)
698
699 bufff, err := json.Marshal(ff)
700 require.NoError(t, err, "ff[%T] failed to Marshal", ff)
701
702 var baseD map[string]interface{}
703 var ffD map[string]interface{}
704
705 err = json.Unmarshal(bufbase, &baseD)
706 require.NoError(t, err, "ff[%T] failed to Unmarshal", base)
707
708 err = json.Unmarshal(bufff, &ffD)
709 require.NoError(t, err, "ff[%T] failed to Unmarshal", ff)
710
711 require.Equal(t, baseD, ffD, "Inspected struct difference of base[%T] != ff[%T]", base, ff)
712 }
713}
714
715func TestFuzzReType(t *testing.T) {
716 testTypeFuzzN(t, &TReTyped{}, &XReTyped{}, 100)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…