fix: Make sure len([BODY]) works if the body is a JSON array

Fixes #359
This commit is contained in:
TwiN
2022-11-03 20:46:35 -04:00
parent ed3683cb32
commit 1f84f2afa0
3 changed files with 32 additions and 3 deletions

View File

@ -234,6 +234,13 @@ func TestCondition_evaluate(t *testing.T) {
},
{
Name: "body-len-array",
Condition: Condition("len([BODY]) == 3"),
Result: &Result{body: []byte("[{\"id\": 1}, {\"id\": 2}, {\"id\": 3}]")},
ExpectedSuccess: true,
ExpectedOutput: "len([BODY]) == 3",
},
{
Name: "body-len-keyed-array",
Condition: Condition("len([BODY].data) == 3"),
Result: &Result{body: []byte("{\"data\": [{\"id\": 1}, {\"id\": 2}, {\"id\": 3}]}")},
ExpectedSuccess: true,
@ -248,6 +255,13 @@ func TestCondition_evaluate(t *testing.T) {
},
{
Name: "body-len-string",
Condition: Condition("len([BODY]) == 8"),
Result: &Result{body: []byte("john.doe")},
ExpectedSuccess: true,
ExpectedOutput: "len([BODY]) == 8",
},
{
Name: "body-len-keyed-string",
Condition: Condition("len([BODY].name) == 8"),
Result: &Result{body: []byte("{\"name\": \"john.doe\"}")},
ExpectedSuccess: true,