github.com/pure-x-eth/consensus_tm@v0.0.0-20230502163723-e3c2ff987250/libs/net/net_test.go (about)

     1  package net
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestProtocolAndAddress(t *testing.T) {
    10  
    11  	cases := []struct {
    12  		fullAddr string
    13  		proto    string
    14  		addr     string
    15  	}{
    16  		{
    17  			"tcp://mydomain:80",
    18  			"tcp",
    19  			"mydomain:80",
    20  		},
    21  		{
    22  			"mydomain:80",
    23  			"tcp",
    24  			"mydomain:80",
    25  		},
    26  		{
    27  			"unix://mydomain:80",
    28  			"unix",
    29  			"mydomain:80",
    30  		},
    31  	}
    32  
    33  	for _, c := range cases {
    34  		proto, addr := ProtocolAndAddress(c.fullAddr)
    35  		assert.Equal(t, proto, c.proto)
    36  		assert.Equal(t, addr, c.addr)
    37  	}
    38  }