Commit 798bf369 authored by Janos Guljas's avatar Janos Guljas

fix api pingpong peer address parse error handling and add test for it

parent 13f6f727
......@@ -25,8 +25,9 @@ func (s *server) pingpongHandler(w http.ResponseWriter, r *http.Request) {
address, err := swarm.ParseHexAddress(peerID)
if err != nil {
s.Logger.Debugf("pingpong: ping %s: %v", peerID, err)
s.Logger.Debugf("pingpong: parse peer address %s: %v", peerID, err)
jsonhttp.BadRequest(w, "invalid peer address")
return
}
rtt, err := s.Pingpong.Ping(ctx, address, "hey", "there", ",", "how are", "you", "?")
......
......@@ -54,6 +54,13 @@ func TestPingpong(t *testing.T) {
})
})
t.Run("invalid peer address", func(t *testing.T) {
jsonhttptest.ResponseDirect(t, client, http.MethodPost, "/pingpong/invalid-address", nil, http.StatusBadRequest, jsonhttp.StatusResponse{
Code: http.StatusBadRequest,
Message: "invalid peer address",
})
})
t.Run("error", func(t *testing.T) {
jsonhttptest.ResponseDirect(t, client, http.MethodPost, "/pingpong/"+errorPeerID.String(), nil, http.StatusInternalServerError, jsonhttp.StatusResponse{
Code: http.StatusInternalServerError,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment