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) {
|
2020-11-09 10:44:00 +08:00
|
|
|
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)
|
|
|
|
|
|
2020-11-09 10:44:00 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|