File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,8 @@ const supportedFeatures = [
36
36
'groovy_scripting' ,
37
37
'headers' ,
38
38
'transform_and_set' ,
39
- 'catch_unauthorized'
39
+ 'catch_unauthorized' ,
40
+ 'arbitrary_key'
40
41
]
41
42
42
43
class TestRunner {
@@ -312,7 +313,20 @@ class TestRunner {
312
313
* @returns {TestRunner }
313
314
*/
314
315
set ( key , name ) {
315
- this . stash . set ( name , delve ( this . response , key ) )
316
+ if ( key . includes ( '_arbitrary_key_' ) ) {
317
+ var currentVisit = null
318
+ for ( const path of key . split ( '.' ) ) {
319
+ if ( path === '_arbitrary_key_' ) {
320
+ const keys = Object . keys ( currentVisit )
321
+ const arbitraryKey = keys [ getRandomInt ( 0 , keys . length ) ]
322
+ this . stash . set ( name , arbitraryKey )
323
+ } else {
324
+ currentVisit = delve ( this . response , path )
325
+ }
326
+ }
327
+ } else {
328
+ this . stash . set ( name , delve ( this . response , key ) )
329
+ }
316
330
return this
317
331
}
318
332
@@ -766,4 +780,8 @@ function getNumbers (val1, val2) {
766
780
return [ val1Numeric , val2Numeric ]
767
781
}
768
782
783
+ function getRandomInt ( min , max ) {
784
+ return Math . floor ( Math . random ( ) * ( max - min ) ) + min
785
+ }
786
+
769
787
module . exports = TestRunner
You can’t perform that action at this time.
0 commit comments