From fdd51869a33e509ec4ac1f51b52c9853a3c988b6 Mon Sep 17 00:00:00 2001 From: TwiN Date: Tue, 6 Dec 2022 21:57:24 -0500 Subject: [PATCH] test: Improve condition validation test coverage --- core/condition_test.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/core/condition_test.go b/core/condition_test.go index 06540e65..8d63dced 100644 --- a/core/condition_test.go +++ b/core/condition_test.go @@ -21,16 +21,27 @@ func TestCondition_Validate(t *testing.T) { {condition: "[STATUS] > 200", expectedErr: nil}, {condition: "[STATUS] == any(200, 201, 202, 203)", expectedErr: nil}, {condition: "[STATUS] == [BODY].status", expectedErr: nil}, - {condition: "[BODY].test == wat", expectedErr: nil}, + {condition: "[CONNECTED] == true", expectedErr: nil}, + {condition: "[RESPONSE_TIME] < 500", expectedErr: nil}, + {condition: "[IP] == 127.0.0.1", expectedErr: nil}, + {condition: "[BODY] == 1", expectedErr: nil}, {condition: "[BODY].test == wat", expectedErr: nil}, {condition: "[BODY].test.wat == wat", expectedErr: nil}, + {condition: "[BODY].age == [BODY].id", expectedErr: nil}, {condition: "[BODY].users[0].id == 1", expectedErr: nil}, {condition: "len([BODY].users) == 100", expectedErr: nil}, - {condition: "has([BODY].users[0].name) == 100", expectedErr: nil}, + {condition: "len([BODY].data) < 5", expectedErr: nil}, + {condition: "has([BODY].errors) == false", expectedErr: nil}, + {condition: "has([BODY].users[0].name) == true", expectedErr: nil}, + {condition: "[BODY].name == pat(john*)", expectedErr: nil}, + {condition: "[CERTIFICATE_EXPIRATION] > 48h", expectedErr: nil}, + {condition: "[DOMAIN_EXPIRATION] > 720h", expectedErr: nil}, {condition: "raw == raw", expectedErr: nil}, {condition: "[STATUS] ? 201", expectedErr: errors.New("invalid condition: [STATUS] ? 201")}, {condition: "[STATUS]==201", expectedErr: errors.New("invalid condition: [STATUS]==201")}, {condition: "[STATUS] = = 201", expectedErr: errors.New("invalid condition: [STATUS] = = 201")}, + {condition: "[STATUS] ==", expectedErr: errors.New("invalid condition: [STATUS] ==")}, + {condition: "[STATUS]", expectedErr: errors.New("invalid condition: [STATUS]")}, // FIXME: Should return an error, but doesn't because jsonpath isn't evaluated due to body being empty in Condition.Validate() //{condition: "len([BODY].users == 100", expectedErr: nil}, }