github.com/yandex/pandora@v0.5.32/components/guns/grpc/core_test.go (about)

     1  package grpc
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  )
     8  
     9  func Test_replacePort(t *testing.T) {
    10  	tests := []struct {
    11  		name string
    12  		host string
    13  		port int64
    14  		want string
    15  	}{
    16  		{
    17  			name: "zero port",
    18  			host: "[2a02:6b8:c02:901:0:fc5f:9a6c:4]:8888",
    19  			port: 0,
    20  			want: "[2a02:6b8:c02:901:0:fc5f:9a6c:4]:8888",
    21  		},
    22  		{
    23  			name: "replace ipv6",
    24  			host: "[2a02:6b8:c02:901:0:fc5f:9a6c:4]:8888",
    25  			port: 9999,
    26  			want: "[2a02:6b8:c02:901:0:fc5f:9a6c:4]:9999",
    27  		},
    28  		{
    29  			name: "add port to ipv6",
    30  			host: "[2a02:6b8:c02:901:0:fc5f:9a6c:4]",
    31  			port: 9999,
    32  			want: "[2a02:6b8:c02:901:0:fc5f:9a6c:4]:9999",
    33  		},
    34  		{
    35  			name: "replace ipv4",
    36  			host: "127.0.0.1:8888",
    37  			port: 9999,
    38  			want: "127.0.0.1:9999",
    39  		},
    40  		{
    41  			name: "replace host",
    42  			host: "localhost:8888",
    43  			port: 9999,
    44  			want: "localhost:9999",
    45  		},
    46  		{
    47  			name: "add port",
    48  			host: "localhost",
    49  			port: 9999,
    50  			want: "localhost:9999",
    51  		},
    52  	}
    53  	for _, tt := range tests {
    54  		t.Run(tt.name, func(t *testing.T) {
    55  			got := replacePort(tt.host, tt.port)
    56  			require.Equal(t, tt.want, got)
    57  		})
    58  	}
    59  }