Files
EdgeCommon/pkg/serverconfigs/shared/http_request_cond_group_test.go

142 lines
2.5 KiB
Go
Raw Normal View History

2020-09-29 17:23:11 +08:00
package shared
import (
"github.com/iwind/TeaGo/assert"
"testing"
)
func TestHTTPRequestCondGroup_MatchRequest(t *testing.T) {
a := assert.NewAssertion(t)
{
group := &HTTPRequestCondGroup{}
group.Connector = "or"
group.IsOn = false
err := group.Init()
if err != nil {
t.Fatal(err)
}
a.IsTrue(group.MatchRequest(func(source string) string {
return source
}))
a.IsTrue(group.MatchResponse(func(source string) string {
return source
}))
}
{
group := &HTTPRequestCondGroup{}
group.IsOn = true
err := group.Init()
if err != nil {
t.Fatal(err)
}
a.IsTrue(group.MatchRequest(func(source string) string {
return source
}))
a.IsTrue(group.MatchResponse(func(source string) string {
return source
}))
}
{
group := &HTTPRequestCondGroup{}
group.IsOn = true
group.Connector = "or"
group.Conds = []*HTTPRequestCond{
{
IsRequest: true,
Param: "456",
Operator: "gt",
Value: "123",
},
{
IsRequest: false,
Param: "123",
Operator: "gt",
Value: "456",
},
}
err := group.Init()
if err != nil {
t.Fatal(err)
}
a.IsTrue(group.MatchRequest(func(source string) string {
return source
}))
a.IsFalse(group.MatchResponse(func(source string) string {
return source
}))
}
{
group := &HTTPRequestCondGroup{}
group.IsOn = true
group.Connector = "or"
group.Conds = []*HTTPRequestCond{
{
IsRequest: true,
Param: "456",
Operator: "gt",
Value: "1234",
},
{
IsRequest: true,
Param: "456",
Operator: "gt",
Value: "123",
},
{
IsRequest: false,
Param: "123",
Operator: "gt",
Value: "456",
},
}
err := group.Init()
if err != nil {
t.Fatal(err)
}
a.IsTrue(group.MatchRequest(func(source string) string {
return source
}))
a.IsFalse(group.MatchResponse(func(source string) string {
return source
}))
}
{
group := &HTTPRequestCondGroup{}
group.IsOn = true
group.Connector = "and"
group.Conds = []*HTTPRequestCond{
{
IsRequest: true,
Param: "456",
Operator: "gt",
Value: "123",
},
{
IsRequest: true,
Param: "456",
Operator: "gt",
Value: "1234",
},
{
IsRequest: false,
Param: "123",
Operator: "gt",
Value: "456",
},
}
err := group.Init()
if err != nil {
t.Fatal(err)
}
a.IsFalse(group.MatchRequest(func(source string) string {
return source
}))
a.IsFalse(group.MatchResponse(func(source string) string {
return source
}))
}
}