ClientConn: add Target() returning target string (#2233)

This commit is contained in:
lyuxuan 2018-07-23 16:19:11 -07:00 committed by GitHub
parent 445634bdcc
commit 980d9e0348
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -580,6 +580,12 @@ func (cc *ClientConn) ChannelzMetric() *channelz.ChannelInternalMetric {
}
}
// Target returns the target string of the ClientConn.
// This is an EXPERIMENTAL API.
func (cc *ClientConn) Target() string {
return cc.target
}
func (cc *ClientConn) incrCallsStarted() {
cc.czmu.Lock()
cc.callsStarted++

View File

@ -689,3 +689,15 @@ func TestDisableServiceConfigOption(t *testing.T) {
t.Fatalf("want: method (\"/foo/bar/\") config to be empty, got: %v", m)
}
}
func TestGetClientConnTarget(t *testing.T) {
addr := "nonexist:///non.existent"
cc, err := Dial(addr, WithInsecure())
if err != nil {
t.Fatalf("Dial(%s, _) = _, %v, want _, <nil>", addr, err)
}
defer cc.Close()
if cc.Target() != addr {
t.Fatalf("Target() = %s, want %s", cc.Target(), addr)
}
}