-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove deprecated dependencies (#1837)
* fix: remove deprecated dependencies * backup * fix test error
- Loading branch information
Showing
11 changed files
with
154 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package targets | ||
|
||
import ( | ||
"strings" | ||
|
||
"google.golang.org/grpc/resolver" | ||
) | ||
|
||
const slashSeparator = "/" | ||
|
||
// GetAuthority returns the authority of the target. | ||
func GetAuthority(target resolver.Target) string { | ||
return target.URL.Host | ||
} | ||
|
||
// GetEndpoints returns the endpoints from the given target. | ||
func GetEndpoints(target resolver.Target) string { | ||
return strings.Trim(target.URL.Path, slashSeparator) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package targets | ||
|
||
import ( | ||
"net/url" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"google.golang.org/grpc/resolver" | ||
) | ||
|
||
func TestGetAuthority(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
url string | ||
want string | ||
}{ | ||
{ | ||
name: "test", | ||
url: "direct://my_authority/localhost", | ||
want: "my_authority", | ||
}, | ||
{ | ||
name: "test with port", | ||
url: "direct://my_authority/localhost:8080", | ||
want: "my_authority", | ||
}, | ||
{ | ||
name: "test with multiple hosts", | ||
url: "direct://my_authority1,my_authority2/localhost,localhost", | ||
want: "my_authority1,my_authority2", | ||
}, | ||
{ | ||
name: "test with multiple hosts with port", | ||
url: "direct://my_authority1:3000,my_authority2:3001/localhost:8080,localhost:8081", | ||
want: "my_authority1:3000,my_authority2:3001", | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
uri, err := url.Parse(test.url) | ||
assert.Nil(t, err) | ||
target := resolver.Target{ | ||
URL: *uri, | ||
} | ||
assert.Equal(t, test.want, GetAuthority(target)) | ||
}) | ||
} | ||
} | ||
|
||
func TestGetEndpoints(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
url string | ||
want string | ||
}{ | ||
{ | ||
name: "test", | ||
url: "direct:///localhost", | ||
want: "localhost", | ||
}, | ||
{ | ||
name: "test with port", | ||
url: "direct:///localhost:8080", | ||
want: "localhost:8080", | ||
}, | ||
{ | ||
name: "test with multiple hosts", | ||
url: "direct:///localhost,localhost", | ||
want: "localhost,localhost", | ||
}, | ||
{ | ||
name: "test with multiple hosts with port", | ||
url: "direct:///localhost:8080,localhost:8081", | ||
want: "localhost:8080,localhost:8081", | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
uri, err := url.Parse(test.url) | ||
assert.Nil(t, err) | ||
target := resolver.Target{ | ||
URL: *uri, | ||
} | ||
assert.Equal(t, test.want, GetEndpoints(target)) | ||
}) | ||
} | ||
} |