2024-05-10 02:56:16 +00:00
|
|
|
package endpoint
|
2021-01-15 01:08:27 +00:00
|
|
|
|
2024-05-10 02:56:16 +00:00
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
2021-01-15 01:08:27 +00:00
|
|
|
|
|
|
|
func BenchmarkCondition_evaluateWithBodyStringAny(b *testing.B) {
|
|
|
|
condition := Condition("[BODY].name == any(john.doe, jane.doe)")
|
|
|
|
for n := 0; n < b.N; n++ {
|
2023-03-15 00:02:31 +00:00
|
|
|
result := &Result{Body: []byte("{\"name\": \"john.doe\"}")}
|
2021-09-14 23:34:46 +00:00
|
|
|
condition.evaluate(result, false)
|
2021-01-15 01:08:27 +00:00
|
|
|
}
|
|
|
|
b.ReportAllocs()
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkCondition_evaluateWithBodyStringAnyFailure(b *testing.B) {
|
|
|
|
condition := Condition("[BODY].name == any(john.doe, jane.doe)")
|
|
|
|
for n := 0; n < b.N; n++ {
|
2023-03-15 00:02:31 +00:00
|
|
|
result := &Result{Body: []byte("{\"name\": \"bob.doe\"}")}
|
2021-09-14 23:34:46 +00:00
|
|
|
condition.evaluate(result, false)
|
2021-01-15 01:08:27 +00:00
|
|
|
}
|
|
|
|
b.ReportAllocs()
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkCondition_evaluateWithBodyString(b *testing.B) {
|
|
|
|
condition := Condition("[BODY].name == john.doe")
|
|
|
|
for n := 0; n < b.N; n++ {
|
2023-03-15 00:02:31 +00:00
|
|
|
result := &Result{Body: []byte("{\"name\": \"john.doe\"}")}
|
2021-09-14 23:34:46 +00:00
|
|
|
condition.evaluate(result, false)
|
2021-01-15 01:08:27 +00:00
|
|
|
}
|
|
|
|
b.ReportAllocs()
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkCondition_evaluateWithBodyStringFailure(b *testing.B) {
|
|
|
|
condition := Condition("[BODY].name == john.doe")
|
|
|
|
for n := 0; n < b.N; n++ {
|
2023-03-15 00:02:31 +00:00
|
|
|
result := &Result{Body: []byte("{\"name\": \"bob.doe\"}")}
|
2021-09-14 23:34:46 +00:00
|
|
|
condition.evaluate(result, false)
|
2021-06-05 22:50:24 +00:00
|
|
|
}
|
|
|
|
b.ReportAllocs()
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkCondition_evaluateWithBodyStringFailureInvalidPath(b *testing.B) {
|
|
|
|
condition := Condition("[BODY].user.name == bob.doe")
|
|
|
|
for n := 0; n < b.N; n++ {
|
2023-03-15 00:02:31 +00:00
|
|
|
result := &Result{Body: []byte("{\"name\": \"bob.doe\"}")}
|
2021-09-14 23:34:46 +00:00
|
|
|
condition.evaluate(result, false)
|
2021-01-15 01:08:27 +00:00
|
|
|
}
|
|
|
|
b.ReportAllocs()
|
|
|
|
}
|
|
|
|
|
2021-01-15 03:49:48 +00:00
|
|
|
func BenchmarkCondition_evaluateWithBodyStringLen(b *testing.B) {
|
|
|
|
condition := Condition("len([BODY].name) == 8")
|
|
|
|
for n := 0; n < b.N; n++ {
|
2023-03-15 00:02:31 +00:00
|
|
|
result := &Result{Body: []byte("{\"name\": \"john.doe\"}")}
|
2021-09-14 23:34:46 +00:00
|
|
|
condition.evaluate(result, false)
|
2021-01-15 03:49:48 +00:00
|
|
|
}
|
|
|
|
b.ReportAllocs()
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkCondition_evaluateWithBodyStringLenFailure(b *testing.B) {
|
|
|
|
condition := Condition("len([BODY].name) == 8")
|
|
|
|
for n := 0; n < b.N; n++ {
|
2023-03-15 00:02:31 +00:00
|
|
|
result := &Result{Body: []byte("{\"name\": \"bob.doe\"}")}
|
2021-09-14 23:34:46 +00:00
|
|
|
condition.evaluate(result, false)
|
2021-01-15 03:49:48 +00:00
|
|
|
}
|
|
|
|
b.ReportAllocs()
|
|
|
|
}
|
|
|
|
|
2021-01-15 01:08:27 +00:00
|
|
|
func BenchmarkCondition_evaluateWithStatus(b *testing.B) {
|
|
|
|
condition := Condition("[STATUS] == 200")
|
|
|
|
for n := 0; n < b.N; n++ {
|
|
|
|
result := &Result{HTTPStatus: 200}
|
2021-09-14 23:34:46 +00:00
|
|
|
condition.evaluate(result, false)
|
2021-01-15 01:08:27 +00:00
|
|
|
}
|
|
|
|
b.ReportAllocs()
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkCondition_evaluateWithStatusFailure(b *testing.B) {
|
|
|
|
condition := Condition("[STATUS] == 200")
|
|
|
|
for n := 0; n < b.N; n++ {
|
|
|
|
result := &Result{HTTPStatus: 400}
|
2021-09-14 23:34:46 +00:00
|
|
|
condition.evaluate(result, false)
|
2021-01-15 01:08:27 +00:00
|
|
|
}
|
|
|
|
b.ReportAllocs()
|
|
|
|
}
|