mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-03 15:00:26 +08:00
优化测试用例
This commit is contained in:
@@ -6,4 +6,6 @@ if [ -z "$TAG" ]; then
|
|||||||
TAG="community"
|
TAG="community"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
go test -v ../... -tags=${TAG}
|
# reference: https://pkg.go.dev/cmd/go/internal/test
|
||||||
|
go clean -testcache
|
||||||
|
go test -timeout 10s -tags="${TAG}" -cover ../...
|
||||||
@@ -4,6 +4,7 @@ package caches_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/caches"
|
"github.com/TeaOSLab/EdgeNode/internal/caches"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/zero"
|
"github.com/TeaOSLab/EdgeNode/internal/zero"
|
||||||
"github.com/iwind/TeaGo/rands"
|
"github.com/iwind/TeaGo/rands"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
@@ -18,7 +19,11 @@ func TestItems_Memory(t *testing.T) {
|
|||||||
var memory1 = stat.HeapInuse
|
var memory1 = stat.HeapInuse
|
||||||
|
|
||||||
var items = []*caches.Item{}
|
var items = []*caches.Item{}
|
||||||
for i := 0; i < 10_000_000; i++ {
|
var count = 100
|
||||||
|
if testutils.IsSingleTesting() {
|
||||||
|
count = 10_000_000
|
||||||
|
}
|
||||||
|
for i := 0; i < count; i++ {
|
||||||
items = append(items, &caches.Item{
|
items = append(items, &caches.Item{
|
||||||
Key: types.String(i),
|
Key: types.String(i),
|
||||||
})
|
})
|
||||||
@@ -33,7 +38,9 @@ func TestItems_Memory(t *testing.T) {
|
|||||||
var memory3 = stat.HeapInuse
|
var memory3 = stat.HeapInuse
|
||||||
t.Log(memory2, memory3, (memory3-memory2)/1024/1024, "M")
|
t.Log(memory2, memory3, (memory3-memory2)/1024/1024, "M")
|
||||||
|
|
||||||
time.Sleep(1 * time.Second)
|
if testutils.IsSingleTesting() {
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestItems_Memory2(t *testing.T) {
|
func TestItems_Memory2(t *testing.T) {
|
||||||
@@ -42,7 +49,12 @@ func TestItems_Memory2(t *testing.T) {
|
|||||||
var memory1 = stat.HeapInuse
|
var memory1 = stat.HeapInuse
|
||||||
|
|
||||||
var items = map[int32]map[string]zero.Zero{}
|
var items = map[int32]map[string]zero.Zero{}
|
||||||
for i := 0; i < 10_000_000; i++ {
|
var count = 100
|
||||||
|
if testutils.IsSingleTesting() {
|
||||||
|
count = 10_000_000
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < count; i++ {
|
||||||
var week = int32((time.Now().Unix() - int64(86400*rands.Int(0, 300))) / (86400 * 7))
|
var week = int32((time.Now().Unix() - int64(86400*rands.Int(0, 300))) / (86400 * 7))
|
||||||
m, ok := items[week]
|
m, ok := items[week]
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -57,7 +69,9 @@ func TestItems_Memory2(t *testing.T) {
|
|||||||
|
|
||||||
t.Log(memory1, memory2, (memory2-memory1)/1024/1024, "M")
|
t.Log(memory1, memory2, (memory2-memory1)/1024/1024, "M")
|
||||||
|
|
||||||
time.Sleep(1 * time.Second)
|
if testutils.IsSingleTesting() {
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
}
|
||||||
for w, i := range items {
|
for w, i := range items {
|
||||||
t.Log(w, len(i))
|
t.Log(w, len(i))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ package caches_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/caches"
|
"github.com/TeaOSLab/EdgeNode/internal/caches"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/zero"
|
"github.com/TeaOSLab/EdgeNode/internal/zero"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"github.com/iwind/TeaGo/assert"
|
"github.com/iwind/TeaGo/assert"
|
||||||
@@ -86,6 +87,10 @@ func TestFileListHashMap_BigInt(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFileListHashMap_Load(t *testing.T) {
|
func TestFileListHashMap_Load(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var list = caches.NewFileList(Tea.Root + "/data/cache-index/p1").(*caches.FileList)
|
var list = caches.NewFileList(Tea.Root + "/data/cache-index/p1").(*caches.FileList)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestFileList_Init(t *testing.T) {
|
func TestFileList_Init(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var list = caches.NewFileList(Tea.Root + "/data/cache-index/p1")
|
var list = caches.NewFileList(Tea.Root + "/data/cache-index/p1")
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
@@ -34,6 +38,10 @@ func TestFileList_Init(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFileList_Add(t *testing.T) {
|
func TestFileList_Add(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var list = caches.NewFileList(Tea.Root + "/data/cache-index/p1").(*caches.FileList)
|
var list = caches.NewFileList(Tea.Root + "/data/cache-index/p1").(*caches.FileList)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
@@ -107,6 +115,10 @@ func TestFileList_Add_Many(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFileList_Exist(t *testing.T) {
|
func TestFileList_Exist(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var list = caches.NewFileList(Tea.Root + "/data/cache-index/p1").(*caches.FileList)
|
var list = caches.NewFileList(Tea.Root + "/data/cache-index/p1").(*caches.FileList)
|
||||||
defer func() {
|
defer func() {
|
||||||
_ = list.Close()
|
_ = list.Close()
|
||||||
@@ -143,6 +155,10 @@ func TestFileList_Exist(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFileList_Exist_Many_DB(t *testing.T) {
|
func TestFileList_Exist_Many_DB(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// 测试在多个数据库下的性能
|
// 测试在多个数据库下的性能
|
||||||
var listSlice = []caches.ListInterface{}
|
var listSlice = []caches.ListInterface{}
|
||||||
for i := 1; i <= 10; i++ {
|
for i := 1; i <= 10; i++ {
|
||||||
@@ -202,6 +218,10 @@ func TestFileList_Exist_Many_DB(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFileList_CleanPrefix(t *testing.T) {
|
func TestFileList_CleanPrefix(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var list = caches.NewFileList(Tea.Root + "/data/cache-index/p1")
|
var list = caches.NewFileList(Tea.Root + "/data/cache-index/p1")
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
@@ -222,6 +242,10 @@ func TestFileList_CleanPrefix(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFileList_Remove(t *testing.T) {
|
func TestFileList_Remove(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var list = caches.NewFileList(Tea.Root + "/data/cache-index/p1").(*caches.FileList)
|
var list = caches.NewFileList(Tea.Root + "/data/cache-index/p1").(*caches.FileList)
|
||||||
defer func() {
|
defer func() {
|
||||||
_ = list.Close()
|
_ = list.Close()
|
||||||
@@ -246,6 +270,10 @@ func TestFileList_Remove(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFileList_Purge(t *testing.T) {
|
func TestFileList_Purge(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var list = caches.NewFileList(Tea.Root + "/data/cache-index/p1")
|
var list = caches.NewFileList(Tea.Root + "/data/cache-index/p1")
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
@@ -270,6 +298,10 @@ func TestFileList_Purge(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFileList_PurgeLFU(t *testing.T) {
|
func TestFileList_PurgeLFU(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var list = caches.NewFileList(Tea.Root + "/data/cache-index/p1")
|
var list = caches.NewFileList(Tea.Root + "/data/cache-index/p1")
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
@@ -294,6 +326,10 @@ func TestFileList_PurgeLFU(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFileList_Stat(t *testing.T) {
|
func TestFileList_Stat(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var list = caches.NewFileList(Tea.Root + "/data/cache-index/p1")
|
var list = caches.NewFileList(Tea.Root + "/data/cache-index/p1")
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
@@ -313,6 +349,10 @@ func TestFileList_Stat(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFileList_Count(t *testing.T) {
|
func TestFileList_Count(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var list = caches.NewFileList(Tea.Root + "/data")
|
var list = caches.NewFileList(Tea.Root + "/data")
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
@@ -333,6 +373,10 @@ func TestFileList_Count(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFileList_CleanAll(t *testing.T) {
|
func TestFileList_CleanAll(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var list = caches.NewFileList(Tea.Root + "/data")
|
var list = caches.NewFileList(Tea.Root + "/data")
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
@@ -352,6 +396,10 @@ func TestFileList_CleanAll(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFileList_UpgradeV3(t *testing.T) {
|
func TestFileList_UpgradeV3(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var list = caches.NewFileList(Tea.Root + "/data/cache-index/p43").(*caches.FileList)
|
var list = caches.NewFileList(Tea.Root + "/data/cache-index/p43").(*caches.FileList)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
@@ -376,6 +424,10 @@ func TestFileList_UpgradeV3(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkFileList_Exist(b *testing.B) {
|
func BenchmarkFileList_Exist(b *testing.B) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var list = caches.NewFileList(Tea.Root + "/data/cache-index/p1")
|
var list = caches.NewFileList(Tea.Root + "/data/cache-index/p1")
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
|
|||||||
@@ -98,10 +98,15 @@ func TestMemoryList_Purge(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMemoryList_Purge_Large_List(t *testing.T) {
|
func TestMemoryList_Purge_Large_List(t *testing.T) {
|
||||||
list := caches.NewMemoryList().(*caches.MemoryList)
|
var list = caches.NewMemoryList().(*caches.MemoryList)
|
||||||
_ = list.Init()
|
_ = list.Init()
|
||||||
|
|
||||||
for i := 0; i < 1_000_000; i++ {
|
var count = 100
|
||||||
|
if testutils.IsSingleTesting() {
|
||||||
|
count = 1_000_000
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < count; i++ {
|
||||||
_ = list.Add("a"+strconv.Itoa(i), &caches.Item{
|
_ = list.Add("a"+strconv.Itoa(i), &caches.Item{
|
||||||
Key: "a" + strconv.Itoa(i),
|
Key: "a" + strconv.Itoa(i),
|
||||||
ExpiredAt: time.Now().Unix() + int64(rands.Int(0, 24*3600)),
|
ExpiredAt: time.Now().Unix() + int64(rands.Int(0, 24*3600)),
|
||||||
@@ -148,7 +153,11 @@ func TestMemoryList_CleanPrefix(t *testing.T) {
|
|||||||
list := caches.NewMemoryList()
|
list := caches.NewMemoryList()
|
||||||
_ = list.Init()
|
_ = list.Init()
|
||||||
before := time.Now()
|
before := time.Now()
|
||||||
for i := 0; i < 1_000_000; i++ {
|
var count = 100
|
||||||
|
if testutils.IsSingleTesting() {
|
||||||
|
count = 1_000_000
|
||||||
|
}
|
||||||
|
for i := 0; i < count; i++ {
|
||||||
key := "https://www.teaos.cn/hello/" + strconv.Itoa(i/10000) + "/" + strconv.Itoa(i) + ".html"
|
key := "https://www.teaos.cn/hello/" + strconv.Itoa(i/10000) + "/" + strconv.Itoa(i) + ".html"
|
||||||
_ = list.Add(fmt.Sprintf("%d", xxhash.Sum64String(key)), &caches.Item{
|
_ = list.Add(fmt.Sprintf("%d", xxhash.Sum64String(key)), &caches.Item{
|
||||||
Key: key,
|
Key: key,
|
||||||
@@ -175,7 +184,12 @@ func TestMemoryList_CleanPrefix(t *testing.T) {
|
|||||||
func TestMapRandomDelete(t *testing.T) {
|
func TestMapRandomDelete(t *testing.T) {
|
||||||
var countMap = map[int]int{} // k => count
|
var countMap = map[int]int{} // k => count
|
||||||
|
|
||||||
for j := 0; j < 1_000_000; j++ {
|
var count = 1000
|
||||||
|
if testutils.IsSingleTesting() {
|
||||||
|
count = 1_000_000
|
||||||
|
}
|
||||||
|
|
||||||
|
for j := 0; j < count; j++ {
|
||||||
var m = map[int]bool{}
|
var m = map[int]bool{}
|
||||||
for i := 0; i < 100; i++ {
|
for i := 0; i < 100; i++ {
|
||||||
m[i] = true
|
m[i] = true
|
||||||
@@ -269,7 +283,6 @@ func TestMemoryList_GC(t *testing.T) {
|
|||||||
HeaderSize: 0,
|
HeaderSize: 0,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
time.Sleep(10 * time.Second)
|
|
||||||
t.Log("clean...", len(list.ItemMaps()))
|
t.Log("clean...", len(list.ItemMaps()))
|
||||||
_ = list.CleanAll()
|
_ = list.CleanAll()
|
||||||
t.Log("cleanAll...", len(list.ItemMaps()))
|
t.Log("cleanAll...", len(list.ItemMaps()))
|
||||||
|
|||||||
@@ -19,6 +19,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestFileStorage_Init(t *testing.T) {
|
func TestFileStorage_Init(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var storage = NewFileStorage(&serverconfigs.HTTPCachePolicy{
|
var storage = NewFileStorage(&serverconfigs.HTTPCachePolicy{
|
||||||
Id: 1,
|
Id: 1,
|
||||||
IsOn: true,
|
IsOn: true,
|
||||||
@@ -49,6 +53,10 @@ func TestFileStorage_Init(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFileStorage_OpenWriter(t *testing.T) {
|
func TestFileStorage_OpenWriter(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var storage = NewFileStorage(&serverconfigs.HTTPCachePolicy{
|
var storage = NewFileStorage(&serverconfigs.HTTPCachePolicy{
|
||||||
Id: 1,
|
Id: 1,
|
||||||
IsOn: true,
|
IsOn: true,
|
||||||
@@ -96,6 +104,10 @@ func TestFileStorage_OpenWriter(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFileStorage_OpenWriter_Partial(t *testing.T) {
|
func TestFileStorage_OpenWriter_Partial(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var storage = NewFileStorage(&serverconfigs.HTTPCachePolicy{
|
var storage = NewFileStorage(&serverconfigs.HTTPCachePolicy{
|
||||||
Id: 2,
|
Id: 2,
|
||||||
IsOn: true,
|
IsOn: true,
|
||||||
@@ -134,6 +146,10 @@ func TestFileStorage_OpenWriter_Partial(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFileStorage_OpenWriter_HTTP(t *testing.T) {
|
func TestFileStorage_OpenWriter_HTTP(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var storage = NewFileStorage(&serverconfigs.HTTPCachePolicy{
|
var storage = NewFileStorage(&serverconfigs.HTTPCachePolicy{
|
||||||
Id: 1,
|
Id: 1,
|
||||||
IsOn: true,
|
IsOn: true,
|
||||||
@@ -202,6 +218,10 @@ func TestFileStorage_OpenWriter_HTTP(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFileStorage_Concurrent_Open_DifferentFile(t *testing.T) {
|
func TestFileStorage_Concurrent_Open_DifferentFile(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var storage = NewFileStorage(&serverconfigs.HTTPCachePolicy{
|
var storage = NewFileStorage(&serverconfigs.HTTPCachePolicy{
|
||||||
Id: 1,
|
Id: 1,
|
||||||
IsOn: true,
|
IsOn: true,
|
||||||
@@ -260,6 +280,10 @@ func TestFileStorage_Concurrent_Open_DifferentFile(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFileStorage_Concurrent_Open_SameFile(t *testing.T) {
|
func TestFileStorage_Concurrent_Open_SameFile(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var storage = NewFileStorage(&serverconfigs.HTTPCachePolicy{
|
var storage = NewFileStorage(&serverconfigs.HTTPCachePolicy{
|
||||||
Id: 1,
|
Id: 1,
|
||||||
IsOn: true,
|
IsOn: true,
|
||||||
@@ -319,6 +343,10 @@ func TestFileStorage_Concurrent_Open_SameFile(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFileStorage_Read(t *testing.T) {
|
func TestFileStorage_Read(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var storage = NewFileStorage(&serverconfigs.HTTPCachePolicy{
|
var storage = NewFileStorage(&serverconfigs.HTTPCachePolicy{
|
||||||
Id: 1,
|
Id: 1,
|
||||||
IsOn: true,
|
IsOn: true,
|
||||||
@@ -358,6 +386,10 @@ func TestFileStorage_Read(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFileStorage_Read_HTTP_Response(t *testing.T) {
|
func TestFileStorage_Read_HTTP_Response(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var storage = NewFileStorage(&serverconfigs.HTTPCachePolicy{
|
var storage = NewFileStorage(&serverconfigs.HTTPCachePolicy{
|
||||||
Id: 1,
|
Id: 1,
|
||||||
IsOn: true,
|
IsOn: true,
|
||||||
@@ -414,6 +446,10 @@ func TestFileStorage_Read_HTTP_Response(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFileStorage_Read_NotFound(t *testing.T) {
|
func TestFileStorage_Read_NotFound(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var storage = NewFileStorage(&serverconfigs.HTTPCachePolicy{
|
var storage = NewFileStorage(&serverconfigs.HTTPCachePolicy{
|
||||||
Id: 1,
|
Id: 1,
|
||||||
IsOn: true,
|
IsOn: true,
|
||||||
@@ -450,6 +486,10 @@ func TestFileStorage_Read_NotFound(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFileStorage_Delete(t *testing.T) {
|
func TestFileStorage_Delete(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var storage = NewFileStorage(&serverconfigs.HTTPCachePolicy{
|
var storage = NewFileStorage(&serverconfigs.HTTPCachePolicy{
|
||||||
Id: 1,
|
Id: 1,
|
||||||
IsOn: true,
|
IsOn: true,
|
||||||
@@ -472,6 +512,10 @@ func TestFileStorage_Delete(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFileStorage_Stat(t *testing.T) {
|
func TestFileStorage_Stat(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var storage = NewFileStorage(&serverconfigs.HTTPCachePolicy{
|
var storage = NewFileStorage(&serverconfigs.HTTPCachePolicy{
|
||||||
Id: 1,
|
Id: 1,
|
||||||
IsOn: true,
|
IsOn: true,
|
||||||
@@ -500,6 +544,10 @@ func TestFileStorage_Stat(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFileStorage_CleanAll(t *testing.T) {
|
func TestFileStorage_CleanAll(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var storage = NewFileStorage(&serverconfigs.HTTPCachePolicy{
|
var storage = NewFileStorage(&serverconfigs.HTTPCachePolicy{
|
||||||
Id: 1,
|
Id: 1,
|
||||||
IsOn: true,
|
IsOn: true,
|
||||||
@@ -534,6 +582,10 @@ func TestFileStorage_CleanAll(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFileStorage_Stop(t *testing.T) {
|
func TestFileStorage_Stop(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var storage = NewFileStorage(&serverconfigs.HTTPCachePolicy{
|
var storage = NewFileStorage(&serverconfigs.HTTPCachePolicy{
|
||||||
Id: 1,
|
Id: 1,
|
||||||
IsOn: true,
|
IsOn: true,
|
||||||
@@ -552,6 +604,10 @@ func TestFileStorage_Stop(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFileStorage_DecodeFile(t *testing.T) {
|
func TestFileStorage_DecodeFile(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var storage = NewFileStorage(&serverconfigs.HTTPCachePolicy{
|
var storage = NewFileStorage(&serverconfigs.HTTPCachePolicy{
|
||||||
Id: 1,
|
Id: 1,
|
||||||
IsOn: true,
|
IsOn: true,
|
||||||
@@ -571,6 +627,10 @@ func TestFileStorage_DecodeFile(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFileStorage_RemoveCacheFile(t *testing.T) {
|
func TestFileStorage_RemoveCacheFile(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var storage = NewFileStorage(nil)
|
var storage = NewFileStorage(nil)
|
||||||
|
|
||||||
defer storage.Stop()
|
defer storage.Stop()
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package caches
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
|
||||||
"github.com/iwind/TeaGo/logs"
|
"github.com/iwind/TeaGo/logs"
|
||||||
"github.com/iwind/TeaGo/rands"
|
"github.com/iwind/TeaGo/rands"
|
||||||
"runtime"
|
"runtime"
|
||||||
@@ -271,6 +272,10 @@ func TestMemoryStorage_Purge(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMemoryStorage_Expire(t *testing.T) {
|
func TestMemoryStorage_Expire(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var storage = NewMemoryStorage(&serverconfigs.HTTPCachePolicy{
|
var storage = NewMemoryStorage(&serverconfigs.HTTPCachePolicy{
|
||||||
MemoryAutoPurgeInterval: 5,
|
MemoryAutoPurgeInterval: 5,
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|||||||
@@ -4,11 +4,16 @@ package configs_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/configs"
|
"github.com/TeaOSLab/EdgeNode/internal/configs"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLoadClusterConfig(t *testing.T) {
|
func TestLoadClusterConfig(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
config, err := configs.LoadClusterConfig()
|
config, err := configs.LoadClusterConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|||||||
@@ -3,11 +3,16 @@ package iplibrary
|
|||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestHTTPAPIAction_AddItem(t *testing.T) {
|
func TestHTTPAPIAction_AddItem(t *testing.T) {
|
||||||
action := NewHTTPAPIAction()
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var action = NewHTTPAPIAction()
|
||||||
action.config = &firewallconfigs.FirewallActionHTTPAPIConfig{
|
action.config = &firewallconfigs.FirewallActionHTTPAPIConfig{
|
||||||
URL: "http://127.0.0.1:2345/post",
|
URL: "http://127.0.0.1:2345/post",
|
||||||
TimeoutSeconds: 0,
|
TimeoutSeconds: 0,
|
||||||
@@ -24,7 +29,11 @@ func TestHTTPAPIAction_AddItem(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestHTTPAPIAction_DeleteItem(t *testing.T) {
|
func TestHTTPAPIAction_DeleteItem(t *testing.T) {
|
||||||
action := NewHTTPAPIAction()
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var action = NewHTTPAPIAction()
|
||||||
action.config = &firewallconfigs.FirewallActionHTTPAPIConfig{
|
action.config = &firewallconfigs.FirewallActionHTTPAPIConfig{
|
||||||
URL: "http://127.0.0.1:2345/post",
|
URL: "http://127.0.0.1:2345/post",
|
||||||
TimeoutSeconds: 0,
|
TimeoutSeconds: 0,
|
||||||
|
|||||||
@@ -4,13 +4,19 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/iplibrary"
|
"github.com/TeaOSLab/EdgeNode/internal/iplibrary"
|
||||||
|
executils "github.com/TeaOSLab/EdgeNode/internal/utils/exec"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIPSetAction_Init(t *testing.T) {
|
func TestIPSetAction_Init(t *testing.T) {
|
||||||
action := iplibrary.NewIPSetAction()
|
_, lookupErr := executils.LookPath("iptables")
|
||||||
|
if lookupErr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var action = iplibrary.NewIPSetAction()
|
||||||
err := action.Init(&firewallconfigs.FirewallActionConfig{
|
err := action.Init(&firewallconfigs.FirewallActionConfig{
|
||||||
Params: maps.Map{
|
Params: maps.Map{
|
||||||
"path": "/usr/bin/iptables",
|
"path": "/usr/bin/iptables",
|
||||||
@@ -25,6 +31,11 @@ func TestIPSetAction_Init(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestIPSetAction_AddItem(t *testing.T) {
|
func TestIPSetAction_AddItem(t *testing.T) {
|
||||||
|
_, lookupErr := executils.LookPath("iptables")
|
||||||
|
if lookupErr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var action = iplibrary.NewIPSetAction()
|
var action = iplibrary.NewIPSetAction()
|
||||||
action.SetConfig(&firewallconfigs.FirewallActionIPSetConfig{
|
action.SetConfig(&firewallconfigs.FirewallActionIPSetConfig{
|
||||||
Path: "/usr/bin/iptables",
|
Path: "/usr/bin/iptables",
|
||||||
@@ -84,7 +95,12 @@ func TestIPSetAction_AddItem(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestIPSetAction_DeleteItem(t *testing.T) {
|
func TestIPSetAction_DeleteItem(t *testing.T) {
|
||||||
action := iplibrary.NewIPSetAction()
|
_, lookupErr := executils.LookPath("firewalld")
|
||||||
|
if lookupErr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var action = iplibrary.NewIPSetAction()
|
||||||
err := action.Init(&firewallconfigs.FirewallActionConfig{
|
err := action.Init(&firewallconfigs.FirewallActionConfig{
|
||||||
Params: maps.Map{
|
Params: maps.Map{
|
||||||
"path": "/usr/bin/firewalld",
|
"path": "/usr/bin/firewalld",
|
||||||
|
|||||||
@@ -3,12 +3,18 @@ package iplibrary
|
|||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
|
||||||
|
executils "github.com/TeaOSLab/EdgeNode/internal/utils/exec"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIPTablesAction_AddItem(t *testing.T) {
|
func TestIPTablesAction_AddItem(t *testing.T) {
|
||||||
action := NewIPTablesAction()
|
_, lookupErr := executils.LookPath("iptables")
|
||||||
|
if lookupErr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var action = NewIPTablesAction()
|
||||||
action.config = &firewallconfigs.FirewallActionIPTablesConfig{
|
action.config = &firewallconfigs.FirewallActionIPTablesConfig{
|
||||||
Path: "/usr/bin/iptables",
|
Path: "/usr/bin/iptables",
|
||||||
}
|
}
|
||||||
@@ -40,7 +46,12 @@ func TestIPTablesAction_AddItem(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestIPTablesAction_DeleteItem(t *testing.T) {
|
func TestIPTablesAction_DeleteItem(t *testing.T) {
|
||||||
action := NewIPTablesAction()
|
_, lookupErr := executils.LookPath("firewalld")
|
||||||
|
if lookupErr != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var action = NewIPTablesAction()
|
||||||
action.config = &firewallconfigs.FirewallActionIPTablesConfig{
|
action.config = &firewallconfigs.FirewallActionIPTablesConfig{
|
||||||
Path: "/usr/bin/firewalld",
|
Path: "/usr/bin/firewalld",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestActionManager_UpdateActions(t *testing.T) {
|
func TestActionManager_UpdateActions(t *testing.T) {
|
||||||
manager := NewActionManager()
|
var manager = NewActionManager()
|
||||||
manager.UpdateActions([]*firewallconfigs.FirewallActionConfig{
|
manager.UpdateActions([]*firewallconfigs.FirewallActionConfig{
|
||||||
{
|
{
|
||||||
Id: 1,
|
Id: 1,
|
||||||
|
|||||||
@@ -3,11 +3,16 @@ package iplibrary
|
|||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestScriptAction_AddItem(t *testing.T) {
|
func TestScriptAction_AddItem(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
action := NewScriptAction()
|
action := NewScriptAction()
|
||||||
action.config = &firewallconfigs.FirewallActionScriptConfig{
|
action.config = &firewallconfigs.FirewallActionScriptConfig{
|
||||||
Path: "/tmp/ip-item.sh",
|
Path: "/tmp/ip-item.sh",
|
||||||
@@ -27,6 +32,10 @@ func TestScriptAction_AddItem(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestScriptAction_DeleteItem(t *testing.T) {
|
func TestScriptAction_DeleteItem(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
action := NewScriptAction()
|
action := NewScriptAction()
|
||||||
action.config = &firewallconfigs.FirewallActionScriptConfig{
|
action.config = &firewallconfigs.FirewallActionScriptConfig{
|
||||||
Path: "/tmp/ip-item.sh",
|
Path: "/tmp/ip-item.sh",
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package iplibrary
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/utils"
|
"github.com/TeaOSLab/EdgeNode/internal/utils"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
|
||||||
"github.com/iwind/TeaGo/assert"
|
"github.com/iwind/TeaGo/assert"
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -75,8 +76,14 @@ func TestIPItem_Contains(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestIPItem_Memory(t *testing.T) {
|
func TestIPItem_Memory(t *testing.T) {
|
||||||
|
var isSingleTest = testutils.IsSingleTesting()
|
||||||
|
|
||||||
var list = NewIPList()
|
var list = NewIPList()
|
||||||
for i := 0; i < 2_000_000; i ++ {
|
var count = 100
|
||||||
|
if isSingleTest {
|
||||||
|
count = 2_000_000
|
||||||
|
}
|
||||||
|
for i := 0; i < count; i++ {
|
||||||
list.Add(&IPItem{
|
list.Add(&IPItem{
|
||||||
Type: "ip",
|
Type: "ip",
|
||||||
Id: uint64(i),
|
Id: uint64(i),
|
||||||
@@ -87,7 +94,9 @@ func TestIPItem_Memory(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
t.Log("waiting")
|
t.Log("waiting")
|
||||||
time.Sleep(10 * time.Second)
|
if isSingleTest {
|
||||||
|
time.Sleep(10 * time.Second)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkIPItem_Contains(b *testing.B) {
|
func BenchmarkIPItem_Contains(b *testing.B) {
|
||||||
@@ -105,4 +114,3 @@ func BenchmarkIPItem_Contains(b *testing.B) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ func TestIPListDB_AddItem(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
defer func() {
|
||||||
|
_ = db.Close()
|
||||||
|
}()
|
||||||
|
|
||||||
err = db.AddItem(&pb.IPItem{
|
err = db.AddItem(&pb.IPItem{
|
||||||
Id: 1,
|
Id: 1,
|
||||||
@@ -60,6 +63,9 @@ func TestIPListDB_ReadItems(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
defer func() {
|
||||||
|
_ = db.Close()
|
||||||
|
}()
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
_ = db.Close()
|
_ = db.Close()
|
||||||
@@ -77,6 +83,9 @@ func TestIPListDB_ReadMaxVersion(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
defer func() {
|
||||||
|
_ = db.Close()
|
||||||
|
}()
|
||||||
t.Log(db.ReadMaxVersion())
|
t.Log(db.ReadMaxVersion())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,6 +94,10 @@ func TestIPListDB_UpdateMaxVersion(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
defer func() {
|
||||||
|
_ = db.Close()
|
||||||
|
}()
|
||||||
|
|
||||||
err = db.UpdateMaxVersion(1027)
|
err = db.UpdateMaxVersion(1027)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|||||||
@@ -3,12 +3,17 @@
|
|||||||
package iplibrary
|
package iplibrary
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIPIsAllowed(t *testing.T) {
|
func TestIPIsAllowed(t *testing.T) {
|
||||||
manager := NewIPListManager()
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var manager = NewIPListManager()
|
||||||
manager.init()
|
manager.init()
|
||||||
|
|
||||||
var before = time.Now()
|
var before = time.Now()
|
||||||
|
|||||||
@@ -2,13 +2,18 @@ package iplibrary
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/utils"
|
"github.com/TeaOSLab/EdgeNode/internal/utils"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
|
||||||
"github.com/iwind/TeaGo/logs"
|
"github.com/iwind/TeaGo/logs"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIPListManager_init(t *testing.T) {
|
func TestIPListManager_init(t *testing.T) {
|
||||||
manager := NewIPListManager()
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var manager = NewIPListManager()
|
||||||
manager.init()
|
manager.init()
|
||||||
t.Log(manager.listMap)
|
t.Log(manager.listMap)
|
||||||
t.Log(SharedServerListManager.blackMap)
|
t.Log(SharedServerListManager.blackMap)
|
||||||
@@ -16,7 +21,11 @@ func TestIPListManager_init(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestIPListManager_check(t *testing.T) {
|
func TestIPListManager_check(t *testing.T) {
|
||||||
manager := NewIPListManager()
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var manager = NewIPListManager()
|
||||||
manager.init()
|
manager.init()
|
||||||
|
|
||||||
var before = time.Now()
|
var before = time.Now()
|
||||||
@@ -28,7 +37,11 @@ func TestIPListManager_check(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestIPListManager_loop(t *testing.T) {
|
func TestIPListManager_loop(t *testing.T) {
|
||||||
manager := NewIPListManager()
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var manager = NewIPListManager()
|
||||||
manager.Start()
|
manager.Start()
|
||||||
err := manager.loop()
|
err := manager.loop()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ package monitor
|
|||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/rpc"
|
"github.com/TeaOSLab/EdgeNode/internal/rpc"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
|
||||||
_ "github.com/iwind/TeaGo/bootstrap"
|
_ "github.com/iwind/TeaGo/bootstrap"
|
||||||
"github.com/iwind/TeaGo/logs"
|
"github.com/iwind/TeaGo/logs"
|
||||||
"google.golang.org/grpc/status"
|
"google.golang.org/grpc/status"
|
||||||
@@ -12,6 +13,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestValueQueue_RPC(t *testing.T) {
|
func TestValueQueue_RPC(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
rpcClient, err := rpc.SharedRPC()
|
rpcClient, err := rpc.SharedRPC()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
package nodes
|
package nodes
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
func TestAPIStream_Start(t *testing.T) {
|
func TestAPIStream_Start(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
apiStream := NewAPIStream()
|
apiStream := NewAPIStream()
|
||||||
apiStream.Start()
|
apiStream.Start()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,6 +110,10 @@ func TestHTTPAccessLogQueue_Push2(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestHTTPAccessLogQueue_Memory(t *testing.T) {
|
func TestHTTPAccessLogQueue_Memory(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
testutils.StartMemoryStats(t)
|
testutils.StartMemoryStats(t)
|
||||||
|
|
||||||
debug.SetGCPercent(10)
|
debug.SetGCPercent(10)
|
||||||
|
|||||||
@@ -3,13 +3,14 @@ package nodes
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestHTTPClientPool_Client(t *testing.T) {
|
func TestHTTPClientPool_Client(t *testing.T) {
|
||||||
pool := NewHTTPClientPool()
|
var pool = NewHTTPClientPool()
|
||||||
|
|
||||||
{
|
{
|
||||||
var origin = &serverconfigs.OriginConfig{
|
var origin = &serverconfigs.OriginConfig{
|
||||||
@@ -54,7 +55,10 @@ func TestHTTPClientPool_cleanClients(t *testing.T) {
|
|||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
t.Log("get", i)
|
t.Log("get", i)
|
||||||
_, _ = pool.Client(nil, origin, origin.Addr.PickAddress(), nil, false)
|
_, _ = pool.Client(nil, origin, origin.Addr.PickAddress(), nil, false)
|
||||||
time.Sleep(1 * time.Second)
|
|
||||||
|
if testutils.IsSingleTesting() {
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,60 +34,63 @@ func (this *HTTPRequest) doMismatch() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 根据配置进行相应的处理
|
// 根据配置进行相应的处理
|
||||||
var globalServerConfig = sharedNodeConfig.GlobalServerConfig
|
var nodeConfig = sharedNodeConfig // copy
|
||||||
if globalServerConfig != nil && globalServerConfig.HTTPAll.MatchDomainStrictly {
|
if nodeConfig != nil {
|
||||||
var statusCode = 404
|
var globalServerConfig = nodeConfig.GlobalServerConfig
|
||||||
var httpAllConfig = globalServerConfig.HTTPAll
|
if globalServerConfig != nil && globalServerConfig.HTTPAll.MatchDomainStrictly {
|
||||||
var mismatchAction = httpAllConfig.DomainMismatchAction
|
var statusCode = 404
|
||||||
|
var httpAllConfig = globalServerConfig.HTTPAll
|
||||||
|
var mismatchAction = httpAllConfig.DomainMismatchAction
|
||||||
|
|
||||||
if mismatchAction != nil && mismatchAction.Options != nil {
|
if mismatchAction != nil && mismatchAction.Options != nil {
|
||||||
var mismatchStatusCode = mismatchAction.Options.GetInt("statusCode")
|
var mismatchStatusCode = mismatchAction.Options.GetInt("statusCode")
|
||||||
if mismatchStatusCode > 0 && mismatchStatusCode >= 100 && mismatchStatusCode < 1000 {
|
if mismatchStatusCode > 0 && mismatchStatusCode >= 100 && mismatchStatusCode < 1000 {
|
||||||
statusCode = mismatchStatusCode
|
statusCode = mismatchStatusCode
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 是否正在访问IP
|
|
||||||
if globalServerConfig.HTTPAll.NodeIPShowPage && utils.IsWildIP(this.ReqHost) {
|
|
||||||
this.writer.statusCode = statusCode
|
|
||||||
var contentHTML = this.Format(globalServerConfig.HTTPAll.NodeIPPageHTML)
|
|
||||||
this.writer.Header().Set("Content-Type", "text/html; charset=utf-8")
|
|
||||||
this.writer.Header().Set("Content-Length", types.String(len(contentHTML)))
|
|
||||||
this.writer.WriteHeader(statusCode)
|
|
||||||
_, _ = this.writer.WriteString(contentHTML)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查cc
|
|
||||||
// TODO 可以在管理端配置是否开启以及最多尝试次数
|
|
||||||
// 要考虑到服务在切换集群时,域名未生效状态时,用户访问的仍然是老集群中的节点,就会产生找不到域名的情况
|
|
||||||
if len(remoteIP) > 0 {
|
|
||||||
const maxAttempts = 100
|
|
||||||
if ttlcache.SharedInt64Cache.IncreaseInt64("MISMATCH_DOMAIN:"+remoteIP, int64(1), time.Now().Unix()+60, false) > maxAttempts {
|
|
||||||
// 在加入之前再次检查黑名单
|
|
||||||
if !waf.SharedIPBlackList.Contains(waf.IPTypeAll, firewallconfigs.FirewallScopeGlobal, 0, remoteIP) {
|
|
||||||
waf.SharedIPBlackList.Add(waf.IPTypeAll, firewallconfigs.FirewallScopeGlobal, 0, remoteIP, time.Now().Unix()+3600)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 处理当前连接
|
// 是否正在访问IP
|
||||||
if mismatchAction != nil && mismatchAction.Code == serverconfigs.DomainMismatchActionPage {
|
if globalServerConfig.HTTPAll.NodeIPShowPage && utils.IsWildIP(this.ReqHost) {
|
||||||
if mismatchAction.Options != nil {
|
|
||||||
this.writer.statusCode = statusCode
|
this.writer.statusCode = statusCode
|
||||||
var contentHTML = this.Format(mismatchAction.Options.GetString("contentHTML"))
|
var contentHTML = this.Format(globalServerConfig.HTTPAll.NodeIPPageHTML)
|
||||||
this.writer.Header().Set("Content-Type", "text/html; charset=utf-8")
|
this.writer.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
this.writer.Header().Set("Content-Length", types.String(len(contentHTML)))
|
this.writer.Header().Set("Content-Length", types.String(len(contentHTML)))
|
||||||
this.writer.WriteHeader(statusCode)
|
this.writer.WriteHeader(statusCode)
|
||||||
_, _ = this.writer.Write([]byte(contentHTML))
|
_, _ = this.writer.WriteString(contentHTML)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查cc
|
||||||
|
// TODO 可以在管理端配置是否开启以及最多尝试次数
|
||||||
|
// 要考虑到服务在切换集群时,域名未生效状态时,用户访问的仍然是老集群中的节点,就会产生找不到域名的情况
|
||||||
|
if len(remoteIP) > 0 {
|
||||||
|
const maxAttempts = 100
|
||||||
|
if ttlcache.SharedInt64Cache.IncreaseInt64("MISMATCH_DOMAIN:"+remoteIP, int64(1), time.Now().Unix()+60, false) > maxAttempts {
|
||||||
|
// 在加入之前再次检查黑名单
|
||||||
|
if !waf.SharedIPBlackList.Contains(waf.IPTypeAll, firewallconfigs.FirewallScopeGlobal, 0, remoteIP) {
|
||||||
|
waf.SharedIPBlackList.Add(waf.IPTypeAll, firewallconfigs.FirewallScopeGlobal, 0, remoteIP, time.Now().Unix()+3600)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理当前连接
|
||||||
|
if mismatchAction != nil && mismatchAction.Code == serverconfigs.DomainMismatchActionPage {
|
||||||
|
if mismatchAction.Options != nil {
|
||||||
|
this.writer.statusCode = statusCode
|
||||||
|
var contentHTML = this.Format(mismatchAction.Options.GetString("contentHTML"))
|
||||||
|
this.writer.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
|
this.writer.Header().Set("Content-Length", types.String(len(contentHTML)))
|
||||||
|
this.writer.WriteHeader(statusCode)
|
||||||
|
_, _ = this.writer.Write([]byte(contentHTML))
|
||||||
|
} else {
|
||||||
|
http.Error(this.writer, "404 page not found: '"+this.URL()+"'", http.StatusNotFound)
|
||||||
|
}
|
||||||
|
return
|
||||||
} else {
|
} else {
|
||||||
http.Error(this.writer, "404 page not found: '"+this.URL()+"'", http.StatusNotFound)
|
http.Error(this.writer, "404 page not found: '"+this.URL()+"'", http.StatusNotFound)
|
||||||
|
this.Close()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
return
|
|
||||||
} else {
|
|
||||||
http.Error(this.writer, "404 page not found: '"+this.URL()+"'", http.StatusNotFound)
|
|
||||||
this.Close()
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package nodes
|
|||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
"github.com/iwind/TeaGo/assert"
|
"github.com/iwind/TeaGo/assert"
|
||||||
|
"net/http"
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@@ -10,26 +11,45 @@ import (
|
|||||||
func TestHTTPRequest_RedirectToHTTPS(t *testing.T) {
|
func TestHTTPRequest_RedirectToHTTPS(t *testing.T) {
|
||||||
var a = assert.NewAssertion(t)
|
var a = assert.NewAssertion(t)
|
||||||
{
|
{
|
||||||
req := &HTTPRequest{
|
rawReq, err := http.NewRequest(http.MethodGet, "/", nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
var req = &HTTPRequest{
|
||||||
|
RawReq: rawReq,
|
||||||
|
RawWriter: NewEmptyResponseWriter(nil),
|
||||||
ReqServer: &serverconfigs.ServerConfig{
|
ReqServer: &serverconfigs.ServerConfig{
|
||||||
|
IsOn: true,
|
||||||
Web: &serverconfigs.HTTPWebConfig{
|
Web: &serverconfigs.HTTPWebConfig{
|
||||||
|
IsOn: true,
|
||||||
RedirectToHttps: &serverconfigs.HTTPRedirectToHTTPSConfig{},
|
RedirectToHttps: &serverconfigs.HTTPRedirectToHTTPSConfig{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
req.init()
|
||||||
req.Do()
|
req.Do()
|
||||||
|
|
||||||
a.IsBool(req.web.RedirectToHttps.IsOn == false)
|
a.IsBool(req.web.RedirectToHttps.IsOn == false)
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
req := &HTTPRequest{
|
rawReq, err := http.NewRequest(http.MethodGet, "/", nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
var req = &HTTPRequest{
|
||||||
|
RawReq: rawReq,
|
||||||
|
RawWriter: NewEmptyResponseWriter(nil),
|
||||||
ReqServer: &serverconfigs.ServerConfig{
|
ReqServer: &serverconfigs.ServerConfig{
|
||||||
|
IsOn: true,
|
||||||
Web: &serverconfigs.HTTPWebConfig{
|
Web: &serverconfigs.HTTPWebConfig{
|
||||||
|
IsOn: true,
|
||||||
RedirectToHttps: &serverconfigs.HTTPRedirectToHTTPSConfig{
|
RedirectToHttps: &serverconfigs.HTTPRedirectToHTTPSConfig{
|
||||||
IsOn: true,
|
IsOn: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
req.init()
|
||||||
req.Do()
|
req.Do()
|
||||||
a.IsBool(req.web.RedirectToHttps.IsOn == true)
|
a.IsBool(req.web.RedirectToHttps.IsOn == true)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,26 @@
|
|||||||
package nodes
|
package nodes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
|
||||||
_ "github.com/iwind/TeaGo/bootstrap"
|
_ "github.com/iwind/TeaGo/bootstrap"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNode_Start(t *testing.T) {
|
func TestNode_Start(t *testing.T) {
|
||||||
node := NewNode()
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var node = NewNode()
|
||||||
node.Start()
|
node.Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNode_Test(t *testing.T) {
|
func TestNode_Test(t *testing.T) {
|
||||||
node := NewNode()
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var node = NewNode()
|
||||||
err := node.Test()
|
err := node.Test()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|||||||
@@ -3,11 +3,16 @@
|
|||||||
package nodes
|
package nodes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
|
||||||
_ "github.com/iwind/TeaGo/bootstrap"
|
_ "github.com/iwind/TeaGo/bootstrap"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUpgradeManager_install(t *testing.T) {
|
func TestUpgradeManager_install(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
err := NewUpgradeManager().install()
|
err := NewUpgradeManager().install()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ package rpc_test
|
|||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/rpc"
|
"github.com/TeaOSLab/EdgeNode/internal/rpc"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
|
||||||
_ "github.com/iwind/TeaGo/bootstrap"
|
_ "github.com/iwind/TeaGo/bootstrap"
|
||||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -13,6 +14,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestRPCConcurrentCall(t *testing.T) {
|
func TestRPCConcurrentCall(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
rpcClient, err := rpc.SharedRPC()
|
rpcClient, err := rpc.SharedRPC()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -43,6 +48,10 @@ func TestRPCConcurrentCall(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRPC_Retry(t *testing.T) {
|
func TestRPC_Retry(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
rpcClient, err := rpc.SharedRPC()
|
rpcClient, err := rpc.SharedRPC()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|||||||
@@ -125,6 +125,10 @@ func TestCache_IncreaseInt64(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCache_Read(t *testing.T) {
|
func TestCache_Read(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
runtime.GOMAXPROCS(1)
|
runtime.GOMAXPROCS(1)
|
||||||
|
|
||||||
var cache = NewCache[int](PiecesOption{Count: 32})
|
var cache = NewCache[int](PiecesOption{Count: 32})
|
||||||
|
|||||||
@@ -4,12 +4,17 @@ package agents_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/utils/agents"
|
"github.com/TeaOSLab/EdgeNode/internal/utils/agents"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
_ "github.com/iwind/TeaGo/bootstrap"
|
_ "github.com/iwind/TeaGo/bootstrap"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewManager(t *testing.T) {
|
func TestNewManager(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var db = agents.NewDB(Tea.Root + "/data/agents.db")
|
var db = agents.NewDB(Tea.Root + "/data/agents.db")
|
||||||
err := db.Init()
|
err := db.Init()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ package agents_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/utils/agents"
|
"github.com/TeaOSLab/EdgeNode/internal/utils/agents"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
|
||||||
"github.com/iwind/TeaGo/assert"
|
"github.com/iwind/TeaGo/assert"
|
||||||
_ "github.com/iwind/TeaGo/bootstrap"
|
_ "github.com/iwind/TeaGo/bootstrap"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -11,6 +12,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestParseQueue_Process(t *testing.T) {
|
func TestParseQueue_Process(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var queue = agents.NewQueue()
|
var queue = agents.NewQueue()
|
||||||
go queue.Start()
|
go queue.Start()
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
@@ -19,6 +24,10 @@ func TestParseQueue_Process(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseQueue_ParseIP(t *testing.T) {
|
func TestParseQueue_ParseIP(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var queue = agents.NewQueue()
|
var queue = agents.NewQueue()
|
||||||
for _, ip := range []string{
|
for _, ip := range []string{
|
||||||
"192.168.1.100",
|
"192.168.1.100",
|
||||||
|
|||||||
@@ -4,9 +4,14 @@ package clock_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/utils/clock"
|
"github.com/TeaOSLab/EdgeNode/internal/utils/clock"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestReadServer(t *testing.T) {
|
func TestReadServer(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
t.Log(clock.NewClockManager().ReadServer("pool.ntp.org"))
|
t.Log(clock.NewClockManager().ReadServer("pool.ntp.org"))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,12 +42,12 @@ func TestIsIPv4(t *testing.T) {
|
|||||||
func TestIsIPv6(t *testing.T) {
|
func TestIsIPv6(t *testing.T) {
|
||||||
var a = assert.NewAssertion(t)
|
var a = assert.NewAssertion(t)
|
||||||
a.IsFalse(utils.IsIPv6("192.168.1.1"))
|
a.IsFalse(utils.IsIPv6("192.168.1.1"))
|
||||||
a.IsFloat32(utils.IsIPv6("0.0.0.0"))
|
a.IsFalse(utils.IsIPv6("0.0.0.0"))
|
||||||
a.IsFalse(utils.IsIPv6("192.168.1.256"))
|
a.IsFalse(utils.IsIPv6("192.168.1.256"))
|
||||||
a.IsFalse(utils.IsIPv6("192.168.1"))
|
a.IsFalse(utils.IsIPv6("192.168.1"))
|
||||||
a.IsTrue(utils.IsIPv6("::1"))
|
a.IsTrue(utils.IsIPv6("::1"))
|
||||||
a.IsTrue(utils.IsIPv6("2001:0db8:85a3:0000:0000:8a2e:0370:7334"))
|
a.IsTrue(utils.IsIPv6("2001:0db8:85a3:0000:0000:8a2e:0370:7334"))
|
||||||
a.IsTrue(utils.IsIPv4("::ffff:192.168.0.1"))
|
a.IsFalse(utils.IsIPv4("::ffff:192.168.0.1"))
|
||||||
a.IsTrue(utils.IsIPv6("::ffff:192.168.0.1"))
|
a.IsTrue(utils.IsIPv6("::ffff:192.168.0.1"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,17 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRawTicker(t *testing.T) {
|
func TestRawTicker(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var ticker = time.NewTicker(2 * time.Second)
|
var ticker = time.NewTicker(2 * time.Second)
|
||||||
go func() {
|
go func() {
|
||||||
for range ticker.C {
|
for range ticker.C {
|
||||||
@@ -21,6 +26,10 @@ func TestRawTicker(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestTicker(t *testing.T) {
|
func TestTicker(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
ticker := NewTicker(3 * time.Second)
|
ticker := NewTicker(3 * time.Second)
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(10 * time.Second)
|
time.Sleep(10 * time.Second)
|
||||||
@@ -33,6 +42,10 @@ func TestTicker(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestTicker2(t *testing.T) {
|
func TestTicker2(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
ticker := NewTicker(1 * time.Second)
|
ticker := NewTicker(1 * time.Second)
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(5 * time.Second)
|
time.Sleep(5 * time.Second)
|
||||||
@@ -50,6 +63,10 @@ func TestTicker2(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestTickerEvery(t *testing.T) {
|
func TestTickerEvery(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
i := 0
|
i := 0
|
||||||
wg := &sync.WaitGroup{}
|
wg := &sync.WaitGroup{}
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
@@ -64,8 +81,11 @@ func TestTickerEvery(t *testing.T) {
|
|||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func TestTicker_StopTwice(t *testing.T) {
|
func TestTicker_StopTwice(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
ticker := NewTicker(3 * time.Second)
|
ticker := NewTicker(3 * time.Second)
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(10 * time.Second)
|
time.Sleep(10 * time.Second)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ package waf_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf"
|
"github.com/TeaOSLab/EdgeNode/internal/waf"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"github.com/iwind/TeaGo/assert"
|
"github.com/iwind/TeaGo/assert"
|
||||||
@@ -32,6 +33,10 @@ func TestNewIPList(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestIPList_Expire(t *testing.T) {
|
func TestIPList_Expire(t *testing.T) {
|
||||||
|
if !testutils.IsSingleTesting() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var list = waf.NewIPList(waf.IPListTypeDeny)
|
var list = waf.NewIPList(waf.IPListTypeDeny)
|
||||||
list.Add(waf.IPTypeAll, firewallconfigs.FirewallScopeGlobal, 1, "127.0.0.1", time.Now().Unix())
|
list.Add(waf.IPTypeAll, firewallconfigs.FirewallScopeGlobal, 1, "127.0.0.1", time.Now().Unix())
|
||||||
list.Add(waf.IPTypeAll, firewallconfigs.FirewallScopeGlobal, 1, "127.0.0.2", time.Now().Unix()+1)
|
list.Add(waf.IPTypeAll, firewallconfigs.FirewallScopeGlobal, 1, "127.0.0.2", time.Now().Unix()+1)
|
||||||
|
|||||||
@@ -695,7 +695,7 @@ func TestRule_IP(t *testing.T) {
|
|||||||
Value: "192.168.0.90,",
|
Value: "192.168.0.90,",
|
||||||
}
|
}
|
||||||
a.IsNil(rule.Init())
|
a.IsNil(rule.Init())
|
||||||
a.IsTrue(rule.Test("192.168.0.100"))
|
a.IsFalse(rule.Test("192.168.0.100"))
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -708,7 +708,7 @@ func TestRule_IP(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
rule := Rule{
|
var rule = Rule{
|
||||||
Operator: RuleOperatorIPRange,
|
Operator: RuleOperatorIPRange,
|
||||||
Value: ",192.168.1.100",
|
Value: ",192.168.1.100",
|
||||||
}
|
}
|
||||||
@@ -748,7 +748,7 @@ func TestRule_IP(t *testing.T) {
|
|||||||
Operator: RuleOperatorIPRange,
|
Operator: RuleOperatorIPRange,
|
||||||
Value: "a/18",
|
Value: "a/18",
|
||||||
}
|
}
|
||||||
a.IsNotNil(rule.Init())
|
a.IsNil(rule.Init())
|
||||||
a.IsFalse(rule.Test("192.168.1.100"))
|
a.IsFalse(rule.Test("192.168.1.100"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,11 @@ func ParseIPRangeList(value string) *IPRangeList {
|
|||||||
if strings.Contains(line, ",") { // IPFrom,IPTo
|
if strings.Contains(line, ",") { // IPFrom,IPTo
|
||||||
var pieces = strings.SplitN(line, ",", 2)
|
var pieces = strings.SplitN(line, ",", 2)
|
||||||
if len(pieces) == 2 {
|
if len(pieces) == 2 {
|
||||||
var ipFrom = net.ParseIP(strings.TrimSpace(pieces[0]))
|
var ipFromString = strings.TrimSpace(pieces[0])
|
||||||
|
if len(ipFromString) == 0 {
|
||||||
|
ipFromString = "0.0.0.0"
|
||||||
|
}
|
||||||
|
var ipFrom = net.ParseIP(ipFromString)
|
||||||
var ipTo = net.ParseIP(strings.TrimSpace(pieces[1]))
|
var ipTo = net.ParseIP(strings.TrimSpace(pieces[1]))
|
||||||
if ipFrom != nil && ipTo != nil {
|
if ipFrom != nil && ipTo != nil {
|
||||||
if bytes.Compare(ipFrom, ipTo) > 0 {
|
if bytes.Compare(ipFrom, ipTo) > 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user