MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / doRandomJSON

Function doRandomJSON

pkg/util/json/random.go:151–190  ·  view source on GitHub ↗
(rng *rand.Rand, cfg randConfig)

Source from the content-addressed store, hash-verified

149}
150
151func doRandomJSON(rng *rand.Rand, cfg randConfig) interface{} {
152 if cfg.complexity <= 0 || rng.Intn(cfg.complexity) == 0 {
153 switch rng.Intn(5) {
154 case 0:
155 return randomJSONString(rng, cfg)
156 case 1:
157 return randomJSONNumber(rng)
158 case 2:
159 return true
160 case 3:
161 return false
162 case 4:
163 return nil
164 }
165 }
166 cfg.complexity--
167 switch rng.Intn(3) {
168 case 0:
169 result := make([]interface{}, 0)
170 for cfg.complexity > 0 {
171 amount := 1 + rng.Intn(cfg.complexity)
172 cfg.complexity -= amount
173 result = append(result, doRandomJSON(rng, cfg))
174 }
175 return result
176 case 1:
177 result := make(map[string]interface{})
178 for cfg.complexity > 0 {
179 amount := 1 + rng.Intn(cfg.complexity)
180 cfg.complexity -= amount
181 result[randomJSONString(rng, objectKeyConfig)] = doRandomJSON(rng, cfg)
182 }
183 return result
184 default:
185 j, _ := MakeJSON(doRandomJSON(rng, cfg))
186 encoding, _ := EncodeJSON(nil, j)
187 encoded, _ := newEncodedFromRoot(encoding)
188 return encoded
189 }
190}
191
192// AsStringWithErrorChance returns string representation of JSON object,
193// but allows up to specified chance that the returned string will contain

Callers 2

RandGenFunction · 0.85
RandomFunction · 0.85

Calls 6

randomJSONStringFunction · 0.85
randomJSONNumberFunction · 0.85
MakeJSONFunction · 0.85
EncodeJSONFunction · 0.85
newEncodedFromRootFunction · 0.85
IntnMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…