Add /chronograf/v1/ping endpoint for server status

pull/1119/head
Chris Goller 2017-03-30 16:31:48 -05:00
parent 890b3829da
commit d57ebc65ab
3 changed files with 36 additions and 0 deletions

View File

@ -55,6 +55,8 @@ func NewMux(opts MuxOpts, service Service) http.Handler {
router.GET("/docs", Redoc("/swagger.json"))
/* API */
router.GET("/chronograf/v1/ping", service.Ping)
// Sources
router.GET("/chronograf/v1/sources", service.Sources)
router.POST("/chronograf/v1/sources", service.NewSource)

12
server/ping.go Normal file
View File

@ -0,0 +1,12 @@
package server
import "net/http"
// Ping responds with HTTP status 204 (no content) and if auth is available
// refreshes the token within the cookie.
func (h *Service) Ping(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNoContent)
if h.UseAuth {
// TODO: refresh token
}
}

22
server/ping_test.go Normal file
View File

@ -0,0 +1,22 @@
package server
import (
"net/http"
"net/http/httptest"
"testing"
)
func TestPingStatus(t *testing.T) {
req := httptest.NewRequest("GET", "http://hoverboards.com", nil)
w := httptest.NewRecorder()
srv := Service{}
srv.Ping(w, req)
resp := w.Result()
if resp.StatusCode != http.StatusNoContent {
t.Errorf("TestPingStatus got status code %d want %d", resp.StatusCode, http.StatusNoContent)
}
}
func TestPingTokenRefresh(t *testing.T) {
}