mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2026-01-07 00:05:49 +08:00
优化测试用例
This commit is contained in:
@@ -4,12 +4,17 @@ package agents_test
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeNode/internal/utils/agents"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
_ "github.com/iwind/TeaGo/bootstrap"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewManager(t *testing.T) {
|
||||
if !testutils.IsSingleTesting() {
|
||||
return
|
||||
}
|
||||
|
||||
var db = agents.NewDB(Tea.Root + "/data/agents.db")
|
||||
err := db.Init()
|
||||
if err != nil {
|
||||
|
||||
@@ -4,6 +4,7 @@ package agents_test
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeNode/internal/utils/agents"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
|
||||
"github.com/iwind/TeaGo/assert"
|
||||
_ "github.com/iwind/TeaGo/bootstrap"
|
||||
"testing"
|
||||
@@ -11,6 +12,10 @@ import (
|
||||
)
|
||||
|
||||
func TestParseQueue_Process(t *testing.T) {
|
||||
if !testutils.IsSingleTesting() {
|
||||
return
|
||||
}
|
||||
|
||||
var queue = agents.NewQueue()
|
||||
go queue.Start()
|
||||
time.Sleep(1 * time.Second)
|
||||
@@ -19,6 +24,10 @@ func TestParseQueue_Process(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseQueue_ParseIP(t *testing.T) {
|
||||
if !testutils.IsSingleTesting() {
|
||||
return
|
||||
}
|
||||
|
||||
var queue = agents.NewQueue()
|
||||
for _, ip := range []string{
|
||||
"192.168.1.100",
|
||||
|
||||
@@ -4,9 +4,14 @@ package clock_test
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeNode/internal/utils/clock"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestReadServer(t *testing.T) {
|
||||
if !testutils.IsSingleTesting() {
|
||||
return
|
||||
}
|
||||
|
||||
t.Log(clock.NewClockManager().ReadServer("pool.ntp.org"))
|
||||
}
|
||||
|
||||
@@ -42,12 +42,12 @@ func TestIsIPv4(t *testing.T) {
|
||||
func TestIsIPv6(t *testing.T) {
|
||||
var a = assert.NewAssertion(t)
|
||||
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"))
|
||||
a.IsTrue(utils.IsIPv6("::1"))
|
||||
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"))
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestRawTicker(t *testing.T) {
|
||||
if !testutils.IsSingleTesting() {
|
||||
return
|
||||
}
|
||||
|
||||
var ticker = time.NewTicker(2 * time.Second)
|
||||
go func() {
|
||||
for range ticker.C {
|
||||
@@ -21,6 +26,10 @@ func TestRawTicker(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTicker(t *testing.T) {
|
||||
if !testutils.IsSingleTesting() {
|
||||
return
|
||||
}
|
||||
|
||||
ticker := NewTicker(3 * time.Second)
|
||||
go func() {
|
||||
time.Sleep(10 * time.Second)
|
||||
@@ -33,6 +42,10 @@ func TestTicker(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTicker2(t *testing.T) {
|
||||
if !testutils.IsSingleTesting() {
|
||||
return
|
||||
}
|
||||
|
||||
ticker := NewTicker(1 * time.Second)
|
||||
go func() {
|
||||
time.Sleep(5 * time.Second)
|
||||
@@ -50,6 +63,10 @@ func TestTicker2(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTickerEvery(t *testing.T) {
|
||||
if !testutils.IsSingleTesting() {
|
||||
return
|
||||
}
|
||||
|
||||
i := 0
|
||||
wg := &sync.WaitGroup{}
|
||||
wg.Add(1)
|
||||
@@ -64,8 +81,11 @@ func TestTickerEvery(t *testing.T) {
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
|
||||
func TestTicker_StopTwice(t *testing.T) {
|
||||
if !testutils.IsSingleTesting() {
|
||||
return
|
||||
}
|
||||
|
||||
ticker := NewTicker(3 * time.Second)
|
||||
go func() {
|
||||
time.Sleep(10 * time.Second)
|
||||
|
||||
Reference in New Issue
Block a user