mirror of
https://github.com/mpolden/echoip.git
synced 2025-01-12 11:17:25 +01:00
parent
b4b6207671
commit
58fd8a66fe
@ -196,7 +196,7 @@ func (s *Server) HealthHandler(w http.ResponseWriter, r *http.Request) *appError
|
|||||||
func (s *Server) PortHandler(w http.ResponseWriter, r *http.Request) *appError {
|
func (s *Server) PortHandler(w http.ResponseWriter, r *http.Request) *appError {
|
||||||
response, err := s.newPortResponse(r)
|
response, err := s.newPortResponse(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return badRequest(err).WithMessage(fmt.Sprintf("Invalid port: %d", response.Port)).AsJSON()
|
return badRequest(err).WithMessage(err.Error()).AsJSON()
|
||||||
}
|
}
|
||||||
b, err := json.Marshal(response)
|
b, err := json.Marshal(response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -130,9 +130,9 @@ func TestJSONHandlers(t *testing.T) {
|
|||||||
status int
|
status int
|
||||||
}{
|
}{
|
||||||
{s.URL, `{"ip":"127.0.0.1","ip_decimal":2130706433,"country":"Elbonia","country_eu":false,"country_iso":"EB","city":"Bornyasherk","hostname":"localhost","latitude":63.416667,"longitude":10.416667}`, 200},
|
{s.URL, `{"ip":"127.0.0.1","ip_decimal":2130706433,"country":"Elbonia","country_eu":false,"country_iso":"EB","city":"Bornyasherk","hostname":"localhost","latitude":63.416667,"longitude":10.416667}`, 200},
|
||||||
{s.URL + "/port/foo", `{"error":"Invalid port: 0"}`, 400},
|
{s.URL + "/port/foo", `{"error":"invalid port: foo"}`, 400},
|
||||||
{s.URL + "/port/0", `{"error":"Invalid port: 0"}`, 400},
|
{s.URL + "/port/0", `{"error":"invalid port: 0"}`, 400},
|
||||||
{s.URL + "/port/65537", `{"error":"Invalid port: 65537"}`, 400},
|
{s.URL + "/port/65537", `{"error":"invalid port: 65537"}`, 400},
|
||||||
{s.URL + "/port/31337", `{"ip":"127.0.0.1","port":31337,"reachable":true}`, 200},
|
{s.URL + "/port/31337", `{"ip":"127.0.0.1","port":31337,"reachable":true}`, 200},
|
||||||
{s.URL + "/foo", `{"error":"404 page not found"}`, 404},
|
{s.URL + "/foo", `{"error":"404 page not found"}`, 404},
|
||||||
{s.URL + "/health", `{"status":"OK"}`, 200},
|
{s.URL + "/health", `{"status":"OK"}`, 200},
|
||||||
|
Loading…
Reference in New Issue
Block a user