github.com/TeaOSLab/EdgeNode@v1.3.8/internal/iplibrary/action_script_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  	"time"
     9  )
    10  
    11  func TestScriptAction_AddItem(t *testing.T) {
    12  	if !testutils.IsSingleTesting() {
    13  		return
    14  	}
    15  
    16  	action := NewScriptAction()
    17  	action.config = &firewallconfigs.FirewallActionScriptConfig{
    18  		Path: "/tmp/ip-item.sh",
    19  		Cwd:  "",
    20  		Args: nil,
    21  	}
    22  	err := action.AddItem(IPListTypeBlack, &pb.IPItem{
    23  		Type:      "ipv4",
    24  		Id:        1,
    25  		IpFrom:    "192.168.1.100",
    26  		ExpiredAt: time.Now().Unix(),
    27  	})
    28  	if err != nil {
    29  		t.Fatal(err)
    30  	}
    31  	t.Log("ok")
    32  }
    33  
    34  func TestScriptAction_DeleteItem(t *testing.T) {
    35  	if !testutils.IsSingleTesting() {
    36  		return
    37  	}
    38  
    39  	action := NewScriptAction()
    40  	action.config = &firewallconfigs.FirewallActionScriptConfig{
    41  		Path: "/tmp/ip-item.sh",
    42  		Cwd:  "",
    43  		Args: nil,
    44  	}
    45  	err := action.DeleteItem(IPListTypeBlack, &pb.IPItem{
    46  		Type:      "ipv4",
    47  		Id:        1,
    48  		IpFrom:    "192.168.1.100",
    49  		ExpiredAt: time.Now().Unix(),
    50  	})
    51  	if err != nil {
    52  		t.Fatal(err)
    53  	}
    54  	t.Log("ok")
    55  }