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

     1  package iplibrary
     2  
     3  import (
     4  	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
     5  	"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
     6  	"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
     7  	"testing"
     8  )
     9  
    10  func TestHTTPAPIAction_AddItem(t *testing.T) {
    11  	if !testutils.IsSingleTesting() {
    12  		return
    13  	}
    14  
    15  	var action = NewHTTPAPIAction()
    16  	action.config = &firewallconfigs.FirewallActionHTTPAPIConfig{
    17  		URL:            "http://127.0.0.1:2345/post",
    18  		TimeoutSeconds: 0,
    19  	}
    20  	err := action.AddItem(IPListTypeBlack, &pb.IPItem{
    21  		Type:   "ipv4",
    22  		Id:     1,
    23  		IpFrom: "192.168.1.100",
    24  	})
    25  	if err != nil {
    26  		t.Fatal(err)
    27  	}
    28  	t.Log("ok")
    29  }
    30  
    31  func TestHTTPAPIAction_DeleteItem(t *testing.T) {
    32  	if !testutils.IsSingleTesting() {
    33  		return
    34  	}
    35  
    36  	var action = NewHTTPAPIAction()
    37  	action.config = &firewallconfigs.FirewallActionHTTPAPIConfig{
    38  		URL:            "http://127.0.0.1:2345/post",
    39  		TimeoutSeconds: 0,
    40  	}
    41  	err := action.DeleteItem(IPListTypeBlack, &pb.IPItem{
    42  		Type:   "ipv4",
    43  		Id:     1,
    44  		IpFrom: "192.168.1.100",
    45  	})
    46  	if err != nil {
    47  		t.Fatal(err)
    48  	}
    49  	t.Log("ok")
    50  }