Skip to content

Commit

Permalink
Fixes port number parsing bug (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
amorey authored Sep 17, 2024
1 parent e93219f commit 903e85f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
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

0 comments on commit 903e85f

Please sign in to comment.