-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
client: fix "unix" scheme handling for some corner cases #4021
Changes from 9 commits
06c753c
b9b89fd
8fbca88
62ccdd1
e3221bd
69696f9
ecbb2d3
7472fbc
e602bd7
894d568
72a6753
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 |
---|---|---|
|
@@ -80,15 +80,16 @@ func runUnixTest(t *testing.T, address, target, expectedAuthority string, dialer | |
} | ||
} | ||
|
||
// TestUnix does end to end tests with the various supported unix target | ||
// formats, ensuring that the authority is set to localhost in every case. | ||
func (s) TestUnix(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
address string | ||
target string | ||
authority string | ||
}{ | ||
type authorityTest struct { | ||
name string | ||
address string | ||
target string | ||
authority string | ||
expectedTarget string | ||
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. Go uses "want". How about 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. Changed it to |
||
} | ||
|
||
func tests() []authorityTest { | ||
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. Use a variable not a function. Also, need a better name than OR, make this non-global and put it in 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. Made it a variable named |
||
return []authorityTest{ | ||
{ | ||
name: "UnixRelative", | ||
address: "sock.sock", | ||
|
@@ -107,8 +108,20 @@ func (s) TestUnix(t *testing.T) { | |
target: "unix:///tmp/sock.sock", | ||
authority: "localhost", | ||
}, | ||
{ | ||
name: "UnixPassthrough", | ||
address: "/tmp/sock.sock", | ||
target: "passthrough:///unix:///tmp/sock.sock", | ||
authority: "unix:///tmp/sock.sock", | ||
expectedTarget: "unix:///tmp/sock.sock", | ||
}, | ||
} | ||
for _, test := range tests { | ||
} | ||
|
||
// TestUnix does end to end tests with the various supported unix target | ||
// formats, ensuring that the authority is set as expected. | ||
func (s) TestUnix(t *testing.T) { | ||
for _, test := range tests() { | ||
t.Run(test.name, func(t *testing.T) { | ||
runUnixTest(t, test.address, test.target, test.authority, nil) | ||
}) | ||
|
@@ -119,30 +132,14 @@ func (s) TestUnix(t *testing.T) { | |
// formats, ensuring that the target sent to the dialer does NOT have the | ||
// "unix:" prefix stripped. | ||
func (s) TestUnixCustomDialer(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
address string | ||
target string | ||
authority string | ||
}{ | ||
{ | ||
name: "UnixRelative", | ||
address: "sock.sock", | ||
target: "unix:sock.sock", | ||
authority: "localhost", | ||
}, | ||
{ | ||
name: "UnixAbsolute", | ||
address: "/tmp/sock.sock", | ||
target: "unix:/tmp/sock.sock", | ||
authority: "localhost", | ||
}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
for _, test := range tests() { | ||
t.Run(test.name+"WithDialer", func(t *testing.T) { | ||
if test.expectedTarget == "" { | ||
test.expectedTarget = test.target | ||
} | ||
dialer := func(ctx context.Context, address string) (net.Conn, error) { | ||
if address != test.target { | ||
return nil, fmt.Errorf("expected target %v in custom dialer, instead got %v", test.target, address) | ||
if address != test.expectedTarget { | ||
return nil, fmt.Errorf("expected target %v in custom dialer, instead got %v", test.expectedTarget, address) | ||
} | ||
address = address[len("unix:"):] | ||
return (&net.Dialer{}).DialContext(ctx, "unix", address) | ||
|
@@ -152,6 +149,8 @@ func (s) TestUnixCustomDialer(t *testing.T) { | |
} | ||
} | ||
|
||
// TestColonPortAuthority does an end to end test with the target for grpc.Dial | ||
// being ":[port]". Ensures authority is "localhost:[port]". | ||
func (s) TestColonPortAuthority(t *testing.T) { | ||
expectedAuthority := "" | ||
var authorityMu sync.Mutex | ||
|
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.
Delete
wantWithDialer
?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.
Made this change.