实现gzip

This commit is contained in:
GoEdgeLab
2020-09-29 17:23:11 +08:00
parent 3af4c6052c
commit aa0ca23211
16 changed files with 375 additions and 358 deletions

View File

@@ -0,0 +1,141 @@
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
}))
}
}