github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/tm2/pkg/os/net_test.go (about)

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