Skip to content

Commit

Permalink
passthrough: return error if endpoint is empty and opt.Dialer is nil …
Browse files Browse the repository at this point in the history
…when building passthrough resolver
  • Loading branch information
huangchong94 committed Oct 19, 2022
1 parent 36e4810 commit cb62a9e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 7 additions & 1 deletion clientconn_parsed_target_test.go
Expand Up @@ -40,7 +40,6 @@ func (s) TestParsedTarget_Success_WithoutCustomDialer(t *testing.T) {
wantParsed resolver.Target
}{
// No scheme is specified.
{target: "", badScheme: true, wantParsed: resolver.Target{Scheme: defScheme, Authority: "", Endpoint: ""}},
{target: "://", badScheme: true, wantParsed: resolver.Target{Scheme: defScheme, Authority: "", Endpoint: "://"}},
{target: ":///", badScheme: true, wantParsed: resolver.Target{Scheme: defScheme, Authority: "", Endpoint: ":///"}},
{target: "://a/", badScheme: true, wantParsed: resolver.Target{Scheme: defScheme, Authority: "", Endpoint: "://a/"}},
Expand Down Expand Up @@ -110,6 +109,7 @@ func (s) TestParsedTarget_Success_WithoutCustomDialer(t *testing.T) {

func (s) TestParsedTarget_Failure_WithoutCustomDialer(t *testing.T) {
targets := []string{
"",
"unix://a/b/c",
"unix://authority",
"unix-abstract://authority/a/b/c",
Expand Down Expand Up @@ -179,6 +179,12 @@ func (s) TestParsedTarget_WithCustomDialer(t *testing.T) {
wantParsed: resolver.Target{Scheme: defScheme, Authority: "", Endpoint: "/unix/socket/address"},
wantDialerAddress: "/unix/socket/address",
},
{
target: "",
badScheme: true,
wantParsed: resolver.Target{Scheme: defScheme, Authority: "", Endpoint: ""},
wantDialerAddress: "",
},
{
target: "passthrough://a.server.com/google.com",
wantParsed: resolver.Target{Scheme: "passthrough", Authority: "a.server.com", Endpoint: "google.com"},
Expand Down
9 changes: 8 additions & 1 deletion internal/resolver/passthrough/passthrough.go
Expand Up @@ -20,13 +20,20 @@
// name without scheme back to gRPC as resolved address.
package passthrough

import "google.golang.org/grpc/resolver"
import (
"errors"

"google.golang.org/grpc/resolver"
)

const scheme = "passthrough"

type passthroughBuilder struct{}

func (*passthroughBuilder) Build(target resolver.Target, cc resolver.ClientConn, opts resolver.BuildOptions) (resolver.Resolver, error) {
if target.Endpoint == "" && opts.Dialer == nil {
return nil, errors.New("passthrough resolver:missing address")
}
r := &passthroughResolver{
target: target,
cc: cc,
Expand Down

0 comments on commit cb62a9e

Please sign in to comment.