Skip to content

Commit 0cd9f02

Browse files
committed
Added support for arbitrary_key (#910)
1 parent cefd424 commit 0cd9f02

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

test/integration/test-runner.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ const supportedFeatures = [
3636
'groovy_scripting',
3737
'headers',
3838
'transform_and_set',
39-
'catch_unauthorized'
39+
'catch_unauthorized',
40+
'arbitrary_key'
4041
]
4142

4243
class TestRunner {
@@ -312,7 +313,20 @@ class TestRunner {
312313
* @returns {TestRunner}
313314
*/
314315
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+
}
316330
return this
317331
}
318332

@@ -766,4 +780,8 @@ function getNumbers (val1, val2) {
766780
return [val1Numeric, val2Numeric]
767781
}
768782

783+
function getRandomInt (min, max) {
784+
return Math.floor(Math.random() * (max - min)) + min
785+
}
786+
769787
module.exports = TestRunner

0 commit comments

Comments
 (0)