github.com/TeaOSLab/EdgeNode@v1.3.8/internal/nodes/http_request_test.go (about)

     1  package nodes
     2  
     3  import (
     4  	"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
     5  	"github.com/iwind/TeaGo/assert"
     6  	"net/http"
     7  	"runtime"
     8  	"testing"
     9  )
    10  
    11  func TestHTTPRequest_RedirectToHTTPS(t *testing.T) {
    12  	var a = assert.NewAssertion(t)
    13  	{
    14  		rawReq, err := http.NewRequest(http.MethodGet, "/", nil)
    15  		if err != nil {
    16  			t.Fatal(err)
    17  		}
    18  		var req = &HTTPRequest{
    19  			RawReq:    rawReq,
    20  			RawWriter: NewEmptyResponseWriter(nil),
    21  			ReqServer: &serverconfigs.ServerConfig{
    22  				IsOn: true,
    23  				Web: &serverconfigs.HTTPWebConfig{
    24  					IsOn:            true,
    25  					RedirectToHttps: &serverconfigs.HTTPRedirectToHTTPSConfig{},
    26  				},
    27  			},
    28  		}
    29  		req.init()
    30  		req.Do()
    31  
    32  		a.IsBool(req.web.RedirectToHttps.IsOn == false)
    33  	}
    34  	{
    35  		rawReq, err := http.NewRequest(http.MethodGet, "/", nil)
    36  		if err != nil {
    37  			t.Fatal(err)
    38  		}
    39  		var req = &HTTPRequest{
    40  			RawReq:    rawReq,
    41  			RawWriter: NewEmptyResponseWriter(nil),
    42  			ReqServer: &serverconfigs.ServerConfig{
    43  				IsOn: true,
    44  				Web: &serverconfigs.HTTPWebConfig{
    45  					IsOn: true,
    46  					RedirectToHttps: &serverconfigs.HTTPRedirectToHTTPSConfig{
    47  						IsOn: true,
    48  					},
    49  				},
    50  			},
    51  		}
    52  		req.init()
    53  		req.Do()
    54  		a.IsBool(req.web.RedirectToHttps.IsOn == true)
    55  	}
    56  }
    57  
    58  func TestHTTPRequest_Memory(t *testing.T) {
    59  	var stat1 = &runtime.MemStats{}
    60  	runtime.ReadMemStats(stat1)
    61  
    62  	var requests = []*HTTPRequest{}
    63  	for i := 0; i < 1_000_000; i++ {
    64  		requests = append(requests, &HTTPRequest{})
    65  	}
    66  
    67  	var stat2 = &runtime.MemStats{}
    68  	runtime.ReadMemStats(stat2)
    69  	t.Log((stat2.HeapInuse-stat1.HeapInuse)/1024/1024, "MB,")
    70  	t.Log(len(requests))
    71  }