github.com/Uhtred009/v2ray-core-1@v4.31.2+incompatible/proxy/vmess/encoding/commands_test.go (about)

     1  package encoding_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/google/go-cmp/cmp"
     7  
     8  	"v2ray.com/core/common"
     9  	"v2ray.com/core/common/buf"
    10  	"v2ray.com/core/common/protocol"
    11  	"v2ray.com/core/common/uuid"
    12  	. "v2ray.com/core/proxy/vmess/encoding"
    13  )
    14  
    15  func TestSwitchAccount(t *testing.T) {
    16  	sa := &protocol.CommandSwitchAccount{
    17  		Port:     1234,
    18  		ID:       uuid.New(),
    19  		AlterIds: 1024,
    20  		Level:    128,
    21  		ValidMin: 16,
    22  	}
    23  
    24  	buffer := buf.New()
    25  	common.Must(MarshalCommand(sa, buffer))
    26  
    27  	cmd, err := UnmarshalCommand(1, buffer.BytesFrom(2))
    28  	common.Must(err)
    29  
    30  	sa2, ok := cmd.(*protocol.CommandSwitchAccount)
    31  	if !ok {
    32  		t.Fatal("failed to convert command to CommandSwitchAccount")
    33  	}
    34  	if r := cmp.Diff(sa2, sa); r != "" {
    35  		t.Error(r)
    36  	}
    37  }