Skip to content
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

Fixes port number parsing bug #6

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func parseConnectUrl(connectUrl string) (*connectArgs, error) {
return nil, err
}

parts := strings.Split(u.Host, ".")
parts := strings.Split(u.Hostname(), ".")

serviceName := parts[0]

Expand Down
38 changes: 37 additions & 1 deletion dispatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import (
const testCtxKey key = "testkey"

func newTestDispatcher() *Dispatcher {
d, _ := NewDispatcher("kubernetes://my-service.my-namespace",
d, _ := NewDispatcher(
"kubernetes://my-service.my-namespace",
WithKubernetesClientset(fake.NewSimpleClientset()),
WithDialOptions(
grpc.WithTransportCredentials(insecure.NewCredentials()),
Expand All @@ -38,6 +39,41 @@ func newTestDispatcher() *Dispatcher {
return d
}

func TestParseConnectUrl(t *testing.T) {
tests := []struct {
name string
setUrl string
wantNamespace string
wantServiceName string
wantPort string
}{
{
"default port",
"kubernetes://my-service.my-namespace",
"my-namespace",
"my-service",
"50051",
},
{
"custom port number",
"kubernetes://my-service.my-namespace:1234",
"my-namespace",
"my-service",
"1234",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
args, err := parseConnectUrl(tt.setUrl)
require.Nil(t, err)
require.Equal(t, tt.wantNamespace, args.Namespace)
require.Equal(t, tt.wantServiceName, args.ServiceName)
require.Equal(t, tt.wantPort, args.Port)
})
}
}

func TestDispatcherUpdateState(t *testing.T) {
initialIps := []string{"ip1", "ip2"}

Expand Down