github.com/yacovm/fabric@v2.0.0-alpha.0.20191128145320-c5d4087dc723+incompatible/common/util/net_test.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package util
     8  
     9  import (
    10  	"context"
    11  	"testing"
    12  
    13  	"github.com/stretchr/testify/assert"
    14  	"google.golang.org/grpc/peer"
    15  )
    16  
    17  type addr struct {
    18  }
    19  
    20  func (*addr) Network() string {
    21  	return ""
    22  }
    23  
    24  func (*addr) String() string {
    25  	return "1.2.3.4:5000"
    26  }
    27  
    28  func TestExtractAddress(t *testing.T) {
    29  	ctx := context.Background()
    30  	assert.Zero(t, ExtractRemoteAddress(ctx))
    31  
    32  	ctx = peer.NewContext(ctx, &peer.Peer{
    33  		Addr: &addr{},
    34  	})
    35  	assert.Equal(t, "1.2.3.4:5000", ExtractRemoteAddress(ctx))
    36  }