New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
grpc: Canonicalize string returned by ClientConn.Target() and resolver.Address.String() #6923
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -808,15 +808,39 @@ func (s) TestMethodConfigDefaultService(t *testing.T) { | |
} | ||
} | ||
|
||
func (s) TestGetClientConnTarget(t *testing.T) { | ||
addr := "nonexist:///non.existent" | ||
cc, err := Dial(addr, WithTransportCredentials(insecure.NewCredentials())) | ||
if err != nil { | ||
t.Fatalf("Dial(%s, _) = _, %v, want _, <nil>", addr, err) | ||
func (s) TestClientConn_Target(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
addr string | ||
targetWant string | ||
}{ | ||
{ | ||
name: "normal-case", | ||
addr: "dns://a.server.com/google.com", | ||
targetWant: "dns://a.server.com/google.com", | ||
}, | ||
{ | ||
name: "canonicalized-target-not-specified", | ||
addr: "no.scheme", | ||
targetWant: "passthrough:///no.scheme", | ||
}, | ||
{ | ||
name: "canonicalized-target-nonexistent", | ||
addr: "nonexist:///non.existent", | ||
targetWant: "passthrough:///nonexist:///non.existent", | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
} | ||
defer cc.Close() | ||
if cc.Target() != addr { | ||
t.Fatalf("Target() = %s, want %s", cc.Target(), addr) | ||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
cc, err := Dial(test.addr, WithTransportCredentials(insecure.NewCredentials())) | ||
if err != nil { | ||
t.Fatalf("Dial(%s, _) = _, %v, want _, <nil>", test.addr, err) | ||
} | ||
defer cc.Close() | ||
if cc.Target() != test.targetWant { | ||
t.Fatalf("Target() = %s, want %s", cc.Target(), test.targetWant) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -283,7 +283,7 @@ func (t Target) Endpoint() string { | |
|
||
// String returns a string representation of Target. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add "canonical". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
func (t Target) String() string { | ||
return t.URL.String() | ||
return t.URL.Scheme + "://" + t.URL.Host + "/" + t.Endpoint() | ||
} | ||
|
||
// Builder creates a resolver that will be used to watch name resolution updates. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use "canonical" since "canonicalize" isn't a word.
Target returns the canonical target string...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done haha.