Files
EdgeAPI/internal/db/models/ip_list_dao_test.go

81 lines
1.3 KiB
Go
Raw Permalink Normal View History

2020-11-07 19:40:24 +08:00
package models
import (
2023-09-13 17:16:00 +08:00
"errors"
2020-11-07 19:40:24 +08:00
"runtime"
"testing"
2024-07-27 14:15:25 +08:00
_ "github.com/go-sql-driver/mysql"
"github.com/iwind/TeaGo/dbs"
2020-11-07 19:40:24 +08:00
)
func TestIPListDAO_IncreaseVersion(t *testing.T) {
dbs.NotifyReady()
2021-01-10 17:34:35 +08:00
var tx *dbs.Tx
2020-11-07 19:40:24 +08:00
dao := NewIPListDAO()
2021-01-10 17:34:35 +08:00
version, err := dao.IncreaseVersion(tx)
2020-11-07 19:40:24 +08:00
if err != nil {
t.Fatal(err)
}
t.Log("version:", version)
}
2022-06-15 19:22:33 +08:00
func TestIPListDAO_CheckUserIPList(t *testing.T) {
dbs.NotifyReady()
var tx *dbs.Tx
{
err := NewIPListDAO().CheckUserIPList(tx, 1, 100)
2023-09-13 17:16:00 +08:00
if err != nil && errors.Is(err, ErrNotFound) {
2022-06-15 19:22:33 +08:00
t.Log("not found")
} else {
t.Log(err)
}
}
{
err := NewIPListDAO().CheckUserIPList(tx, 1, 85)
2023-09-13 17:16:00 +08:00
if err != nil && errors.Is(err, ErrNotFound) {
2022-06-15 19:22:33 +08:00
t.Log("not found")
} else {
t.Log(err)
}
}
{
err := NewIPListDAO().CheckUserIPList(tx, 1, 17)
2023-09-13 17:16:00 +08:00
if err != nil && errors.Is(err, ErrNotFound) {
2022-06-15 19:22:33 +08:00
t.Log("not found")
} else {
t.Log(err)
}
}
}
2023-09-13 17:16:00 +08:00
func TestIPListDAO_NotifyUpdate(t *testing.T) {
dbs.NotifyReady()
var dao = NewIPListDAO()
var tx *dbs.Tx
err := dao.NotifyUpdate(tx, 104, NodeTaskTypeIPListDeleted)
if err != nil {
t.Fatal(err)
}
}
2020-11-07 19:40:24 +08:00
func BenchmarkIPListDAO_IncreaseVersion(b *testing.B) {
runtime.GOMAXPROCS(1)
dbs.NotifyReady()
2021-01-10 17:34:35 +08:00
var tx *dbs.Tx
2020-11-07 19:40:24 +08:00
dao := NewIPListDAO()
for i := 0; i < b.N; i++ {
2021-01-10 17:34:35 +08:00
_, _ = dao.IncreaseVersion(tx)
2020-11-07 19:40:24 +08:00
}
}