github.com/TeaOSLab/EdgeNode@v1.3.8/internal/stats/http_request_stat_manager_test.go (about)

     1  package stats
     2  
     3  import (
     4  	iplib "github.com/TeaOSLab/EdgeCommon/pkg/iplibrary"
     5  	_ "github.com/iwind/TeaGo/bootstrap"
     6  	"github.com/iwind/TeaGo/logs"
     7  	"testing"
     8  )
     9  
    10  func TestHTTPRequestStatManager_Loop_Region(t *testing.T) {
    11  	err := iplib.InitDefault()
    12  	if err != nil {
    13  		t.Fatal(err)
    14  	}
    15  
    16  	var manager = NewHTTPRequestStatManager()
    17  	manager.AddRemoteAddr(11, "202.196.0.20", 0, false)
    18  	manager.AddRemoteAddr(11, "202.196.0.20", 0, false) // 重复添加一个测试相加
    19  	manager.AddRemoteAddr(11, "8.8.8.8", 0, false)
    20  
    21  	/**for i := 0; i < 100; i++ {
    22  		manager.AddRemoteAddr(11, strconv.Itoa(rands.Int(10, 250))+"."+strconv.Itoa(rands.Int(10, 250))+"."+strconv.Itoa(rands.Int(10, 250))+".8")
    23  	}**/
    24  	err = manager.Loop()
    25  	if err != nil {
    26  		t.Fatal(err)
    27  	}
    28  	logs.PrintAsJSON(manager.cityMap, t)
    29  	logs.PrintAsJSON(manager.providerMap, t)
    30  
    31  	err = manager.Upload()
    32  	if err != nil {
    33  		t.Fatal(err)
    34  	}
    35  	t.Log("ok")
    36  }
    37  
    38  func TestHTTPRequestStatManager_Loop_UserAgent(t *testing.T) {
    39  	var manager = NewHTTPRequestStatManager()
    40  	manager.AddUserAgent(1, "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36", "")
    41  	manager.AddUserAgent(1, "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36", "")
    42  	manager.AddUserAgent(1, "Mozilla/5.0 (Macintosh; Intel Mac OS X 11) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76 Safari/537.36", "")
    43  	manager.AddUserAgent(1, "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:49.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36", "")
    44  	manager.AddUserAgent(1, "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko", "")
    45  	err := manager.Loop()
    46  	if err != nil {
    47  		t.Fatal(err)
    48  	}
    49  	logs.PrintAsJSON(manager.systemMap, t)
    50  	logs.PrintAsJSON(manager.browserMap, t)
    51  
    52  	err = manager.Upload()
    53  	if err != nil {
    54  		t.Fatal(err)
    55  	}
    56  	t.Log("ok")
    57  }