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