github.com/TeaOSLab/EdgeNode@v1.3.8/internal/waf/checkpoints/response_body_test.go (about)

     1  package checkpoints
     2  
     3  import (
     4  	"bytes"
     5  	"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
     6  	"io"
     7  	"net/http"
     8  	"testing"
     9  )
    10  
    11  func TestResponseBodyCheckpoint_ResponseValue(t *testing.T) {
    12  	resp := requests.NewResponse(new(http.Response))
    13  	resp.StatusCode = 200
    14  	resp.Header = http.Header{}
    15  	resp.Header.Set("Hello", "World")
    16  	resp.Body = io.NopCloser(bytes.NewBuffer([]byte("Hello, World")))
    17  
    18  	checkpoint := new(ResponseBodyCheckpoint)
    19  	t.Log(checkpoint.ResponseValue(nil, resp, "", nil, 1))
    20  	t.Log(checkpoint.ResponseValue(nil, resp, "", nil, 1))
    21  	t.Log(checkpoint.ResponseValue(nil, resp, "", nil, 1))
    22  	t.Log(checkpoint.ResponseValue(nil, resp, "", nil, 1))
    23  
    24  	data, err := io.ReadAll(resp.Body)
    25  	if err != nil {
    26  		t.Fatal(err)
    27  	}
    28  	t.Log("after read:", string(data))
    29  }