mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-10-08 20:07:51 +00:00
Remove URI error, URIFromAddress
This commit is contained in:
parent
e223ec3f9a
commit
30f3cb2386
2 changed files with 2 additions and 56 deletions
19
uri.go
19
uri.go
|
|
@ -43,7 +43,6 @@ type URI struct {
|
|||
scheme string
|
||||
host string
|
||||
port uint16
|
||||
error error
|
||||
}
|
||||
|
||||
// DefaultURI creates and returns the default URI.
|
||||
|
|
@ -70,17 +69,11 @@ func NewURIFromHostPort(host string, port uint16) (*URI, error) {
|
|||
func NewURIFromAddress(address string) (*URI, error) {
|
||||
uri, err := parseAddress(address)
|
||||
if err != nil {
|
||||
return &URI{error: err}, err
|
||||
return nil, err
|
||||
}
|
||||
return uri, err
|
||||
}
|
||||
|
||||
// URIFromAddress creates a URI from the given address.
|
||||
func URIFromAddress(host string) *URI {
|
||||
uri, _ := NewURIFromAddress(host)
|
||||
return uri
|
||||
}
|
||||
|
||||
// Scheme returns the scheme of this URI.
|
||||
func (u *URI) Scheme() string {
|
||||
return u.scheme
|
||||
|
|
@ -151,16 +144,6 @@ func (u URI) Equals(other *URI) bool {
|
|||
u.port == other.port
|
||||
}
|
||||
|
||||
// Error returns the error if this URI has one.
|
||||
func (u *URI) Error() error {
|
||||
return u.error
|
||||
}
|
||||
|
||||
// Valid returns true if this is a valid URI.
|
||||
func (u *URI) Valid() bool {
|
||||
return u != nil && u.error == nil
|
||||
}
|
||||
|
||||
// The following methods are required to implement pflag Value interface.
|
||||
|
||||
// Set sets the time quantum value.
|
||||
|
|
|
|||
39
uri_test.go
39
uri_test.go
|
|
@ -60,53 +60,16 @@ func TestNewURIFromAddress(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("Can't parse address: %s, %s", item.address, err)
|
||||
}
|
||||
if uri.Error() != nil {
|
||||
t.Fatalf("Valid addresses shouldn't have attached errors")
|
||||
}
|
||||
if !uri.Valid() {
|
||||
t.Fatalf("Valid() should return true for valid addresses")
|
||||
}
|
||||
compare(t, uri, item.scheme, item.host, item.port)
|
||||
}
|
||||
}
|
||||
|
||||
func TestURIFromAddress(t *testing.T) {
|
||||
for _, item := range validFixture() {
|
||||
uri := URIFromAddress(item.address)
|
||||
if uri.Error() != nil {
|
||||
t.Fatalf("Can't parse address: %s, %s", item.address, uri.Error())
|
||||
}
|
||||
if !uri.Valid() {
|
||||
t.Fatalf("Valid() should return true for valid addresses")
|
||||
}
|
||||
compare(t, uri, item.scheme, item.host, item.port)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewURIFromAddressInvalidAddress(t *testing.T) {
|
||||
for _, addr := range invalidFixture() {
|
||||
uri, err := NewURIFromAddress(addr)
|
||||
_, err := NewURIFromAddress(addr)
|
||||
if err == nil {
|
||||
t.Fatalf("Invalid address should return an error: %s", addr)
|
||||
}
|
||||
if uri.Error() == nil {
|
||||
t.Fatalf("Invalid addreseses should have attached errors")
|
||||
}
|
||||
if uri.Valid() {
|
||||
t.Fatalf("Valid() should return false for invalid addresses")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestURIFromAddressInvalidAddress(t *testing.T) {
|
||||
for _, addr := range invalidFixture() {
|
||||
uri := URIFromAddress(addr)
|
||||
if uri.Error() == nil {
|
||||
t.Fatalf("Invalid address should return an error: %s", addr)
|
||||
}
|
||||
if uri.Valid() {
|
||||
t.Fatalf("Valid() should return false for invalid addresses")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue