diff --git a/internal/http/reason.go b/internal/http/reason.go index 417f8da..c27cae5 100644 --- a/internal/http/reason.go +++ b/internal/http/reason.go @@ -21,19 +21,10 @@ import ( "errors" "io/ioutil" "net/http" - "strings" "github.com/BBVA/kapow/internal/server/srverrors" ) -// GetReason returns the reason phrase part of an HTTP response -func GetReason(r *http.Response) string { - if i := strings.IndexByte(r.Status, ' '); i != -1 { - return r.Status[i+1:] - } - return "" -} - // GetReasonFromBody returns the reason phrase embedded within the JSON error // body, or an error if no reason can be extracted func GetReasonFromBody(r *http.Response) (string, error) { diff --git a/internal/http/reason_test.go b/internal/http/reason_test.go index 6281fad..2b492ed 100644 --- a/internal/http/reason_test.go +++ b/internal/http/reason_test.go @@ -23,48 +23,6 @@ import ( "testing" ) -func TestEmptyReasonWhenEmptyString(t *testing.T) { - r := &nethttp.Response{Status: ""} - if GetReason(r) != "" { - t.Errorf("We consider an empty status line to have an empty reason") - } -} - -func TestEmptyReasonWhenOnlyCode(t *testing.T) { - r := &nethttp.Response{Status: "200"} - if GetReason(r) != "" { - t.Errorf("We consider an status line with just the status code to have an empty reason") - } -} - -func TestEmptyReasonWhenOnlyCodePlusSpace(t *testing.T) { - r := &nethttp.Response{Status: "200 "} - if GetReason(r) != "" { - t.Errorf("We consider an status line with just the status code to have an empty reason") - } -} - -func TestReasonOfOneWord(t *testing.T) { - r := &nethttp.Response{Status: "200 FOO"} - if GetReason(r) != "FOO" { - t.Errorf("Unexpected reason found") - } -} - -func TestReasonOfMultipleWords(t *testing.T) { - r := &nethttp.Response{Status: "200 FOO BAR BAZ"} - if GetReason(r) != "FOO BAR BAZ" { - t.Errorf("Unexpected reason found") - } -} - -func TestBehaveWithOddSizeStatusCode(t *testing.T) { - r := &nethttp.Response{Status: "2 FOO BAR BAZ"} - if GetReason(r) != "FOO BAR BAZ" { - t.Errorf("Unexpected reason found") - } -} - func TestGetReasonFromBodyExtractsReasonFromJSON(t *testing.T) { r := &nethttp.Response{ Status: "200 OK",