-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose response HTTP status code in errors
For various operations involving HTTP requests against the Eureka server, allow callers to interpret surfaced failures by way of inspecting the HTTP response's status code.
- Loading branch information
Showing
4 changed files
with
92 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package fargo | ||
|
||
// MIT Licensed (see README.md) - Copyright (c) 2013 Hudl <@Hudl> | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
) | ||
|
||
func TestHTTPResponseStatusCode(t *testing.T) { | ||
tests := []struct { | ||
input error | ||
present bool | ||
code int | ||
}{ | ||
{nil, false, 0}, | ||
{errors.New("other"), false, 0}, | ||
{&unsuccessfulHTTPResponse{404, "missing"}, true, 404}, | ||
} | ||
for _, test := range tests { | ||
code, present := HTTPResponseStatusCode(test.input) | ||
if present { | ||
if !test.present { | ||
t.Errorf("input %v: want absent, got code %d", test.input, code) | ||
continue | ||
} | ||
if code != test.code { | ||
t.Errorf("input %v: want %d, got %d", test.input, test.code, code) | ||
} | ||
} else if test.present { | ||
t.Errorf("input %v: want code %d, got absent", test.input, test.code) | ||
} | ||
} | ||
} |
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