github.com/Asutorufa/yuhaiin@v0.3.6-0.20240502055049-7984da7023a0/pkg/node/node_test.go (about)

     1  package node
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  
     7  	"github.com/Asutorufa/yuhaiin/pkg/protos/node"
     8  	"github.com/Asutorufa/yuhaiin/pkg/protos/node/point"
     9  	"github.com/Asutorufa/yuhaiin/pkg/protos/node/protocol"
    10  	"github.com/Asutorufa/yuhaiin/pkg/protos/node/subscribe"
    11  	pt "github.com/Asutorufa/yuhaiin/pkg/protos/node/tag"
    12  	"github.com/Asutorufa/yuhaiin/pkg/utils/jsondb"
    13  )
    14  
    15  func TestDelete(t *testing.T) {
    16  	a := []string{"a", "b", "c"}
    17  
    18  	for i := range a {
    19  		if a[i] != "b" {
    20  			continue
    21  		}
    22  
    23  		t.Log(i, a[:i], a[i:])
    24  		a = append(a[:i], a[i+1:]...)
    25  		break
    26  	}
    27  
    28  	t.Log(a)
    29  }
    30  
    31  func TestProtoMsgType(t *testing.T) {
    32  	p := &protocol.Protocol{
    33  		Protocol: &protocol.Protocol_None{},
    34  	}
    35  
    36  	t.Log(reflect.TypeOf(p.GetProtocol()) == reflect.TypeOf(&protocol.Protocol_None{}))
    37  }
    38  
    39  func TestMergeDefault(t *testing.T) {
    40  	defaultNode := &node.Node{
    41  		Tcp:   &point.Point{},
    42  		Udp:   &point.Point{},
    43  		Links: map[string]*subscribe.Link{},
    44  		Manager: &node.Manager{
    45  			GroupsV2: map[string]*node.Nodes{},
    46  			Nodes:    map[string]*point.Point{},
    47  			Tags:     map[string]*pt.Tags{},
    48  		},
    49  	}
    50  
    51  	src := &node.Node{}
    52  
    53  	jsondb.MergeDefault(src.ProtoReflect(), defaultNode.ProtoReflect())
    54  
    55  	t.Log(src.Links == nil, src.Manager.GroupsV2 == nil)
    56  }