From 30f3cb238661e091d9efd7e463d6c18a505ab16b Mon Sep 17 00:00:00 2001 From: Yuce Tekol Date: Thu, 12 Oct 2017 15:52:36 +0300 Subject: [PATCH] Remove URI error, URIFromAddress --- uri.go | 19 +------------------ uri_test.go | 39 +-------------------------------------- 2 files changed, 2 insertions(+), 56 deletions(-) diff --git a/uri.go b/uri.go index f91db4243..de6e4bae6 100644 --- a/uri.go +++ b/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. diff --git a/uri_test.go b/uri_test.go index ca664fe15..33ccd35f9 100644 --- a/uri_test.go +++ b/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") - } } }