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

     1  // Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
     2  
     3  package waf_test
     4  
     5  import (
     6  	"github.com/TeaOSLab/EdgeNode/internal/waf"
     7  	"github.com/iwind/TeaGo/types"
     8  	"testing"
     9  	"time"
    10  )
    11  
    12  func TestInfoArg_Encode(t *testing.T) {
    13  	var info = &waf.InfoArg{
    14  		ActionId:         1,
    15  		Timestamp:        time.Now().Unix(),
    16  		URL:              "https://example.com/hello",
    17  		PolicyId:         2,
    18  		GroupId:          3,
    19  		SetId:            4,
    20  		UseLocalFirewall: true,
    21  		Scope:            "global",
    22  	}
    23  
    24  	encodedString, err := info.Encode()
    25  	if err != nil {
    26  		t.Fatal(err)
    27  	}
    28  	t.Log("["+types.String(len(encodedString))+"]", encodedString)
    29  
    30  	{
    31  		urlEncodedString, encodeErr := info.URLEncoded()
    32  		if encodeErr != nil {
    33  			t.Fatal(encodeErr)
    34  		}
    35  		t.Log("["+types.String(len(urlEncodedString))+"]", urlEncodedString)
    36  	}
    37  
    38  	var info2 = &waf.InfoArg{}
    39  	err = info2.Decode(encodedString)
    40  	if err != nil {
    41  		t.Fatal(err)
    42  	}
    43  	t.Logf("%+v", info2)
    44  }