randomObjectJSONBytes returns marshaled JSON for a random top-level object along with the map so tests can predict values.
(r *mathrand.Rand, depth int)
| 102 | // randomObjectJSONBytes returns marshaled JSON for a random top-level object |
| 103 | // along with the map so tests can predict values. |
| 104 | func randomObjectJSONBytes(r *mathrand.Rand, depth int) ([]byte, map[string]interface{}) { |
| 105 | n := r.Intn(4) + 1 |
| 106 | obj := make(map[string]interface{}, n) |
| 107 | for i := 0; i < n; i++ { |
| 108 | obj[randKey(r)] = randomJSONValue(r, depth) |
| 109 | } |
| 110 | b, err := json.Marshal(obj) |
| 111 | if err != nil { |
| 112 | // The generator must only emit json.Marshal-able values; if not, fall |
| 113 | // back to a trivial object so the property stays well-defined. |
| 114 | return []byte(`{}`), map[string]interface{}{} |
| 115 | } |
| 116 | return b, obj |
| 117 | } |
| 118 | |
| 119 | // randomJSONBytes returns marshaled JSON for any random value. |
| 120 | func randomJSONBytes(r *mathrand.Rand, depth int) []byte { |
no test coverage detected