github.com/TeaOSLab/EdgeNode@v1.3.8/internal/iplibrary/manager_ip_list_test.go (about)

     1  package iplibrary_test
     2  
     3  import (
     4  	"github.com/TeaOSLab/EdgeCommon/pkg/iputils"
     5  	"github.com/TeaOSLab/EdgeNode/internal/iplibrary"
     6  	"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
     7  	"github.com/iwind/TeaGo/logs"
     8  	"testing"
     9  	"time"
    10  )
    11  
    12  func TestIPListManager_init(t *testing.T) {
    13  	if !testutils.IsSingleTesting() {
    14  		return
    15  	}
    16  
    17  	var manager = iplibrary.NewIPListManager()
    18  	manager.Init()
    19  	t.Log(manager.ListMap())
    20  	t.Log(iplibrary.SharedServerListManager.BlackMap())
    21  	logs.PrintAsJSON(iplibrary.GlobalBlackIPList.SortedRangeItems(), t)
    22  }
    23  
    24  func TestIPListManager_check(t *testing.T) {
    25  	if !testutils.IsSingleTesting() {
    26  		return
    27  	}
    28  
    29  	var manager = iplibrary.NewIPListManager()
    30  	manager.Init()
    31  
    32  	var before = time.Now()
    33  	defer func() {
    34  		t.Log(time.Since(before).Seconds()*1000, "ms")
    35  	}()
    36  	t.Log(iplibrary.SharedServerListManager.FindBlackList(23, true).Contains(iputils.ToBytes("127.0.0.2")))
    37  	t.Log(iplibrary.GlobalBlackIPList.Contains(iputils.ToBytes("127.0.0.6")))
    38  }
    39  
    40  func TestIPListManager_loop(t *testing.T) {
    41  	if !testutils.IsSingleTesting() {
    42  		return
    43  	}
    44  
    45  	var manager = iplibrary.NewIPListManager()
    46  	manager.Start()
    47  	err := manager.Loop()
    48  	if err != nil {
    49  		t.Fatal(err)
    50  	}
    51  }