mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 18:35:44 +03:00
Added a test for the clients stats endpoint
This commit is contained in:
@@ -6,6 +6,10 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const (
|
||||
invalidSinceErrPrefix = "can't read the since query parameter"
|
||||
)
|
||||
|
||||
func (s *HTTPServer) ClientStatsRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
||||
if s.agent.client == nil {
|
||||
return nil, clientNotRunning
|
||||
@@ -18,7 +22,7 @@ func (s *HTTPServer) ClientStatsRequest(resp http.ResponseWriter, req *http.Requ
|
||||
ts = true
|
||||
since, err = strconv.Atoi(sinceTime)
|
||||
if err != nil {
|
||||
return nil, CodedError(400, fmt.Sprintf("can't read the since query parameter: %v", err))
|
||||
return nil, CodedError(400, fmt.Sprintf("%s: %v", invalidSinceErrPrefix, err))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
23
command/agent/stats_endpoint_test.go
Normal file
23
command/agent/stats_endpoint_test.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestClientStatsRequest(t *testing.T) {
|
||||
httpTest(t, nil, func(s *TestServer) {
|
||||
req, err := http.NewRequest("GET", "/v1/client/stats/?since=foo", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
respW := httptest.NewRecorder()
|
||||
_, err = s.Server.ClientStatsRequest(respW, req)
|
||||
if !strings.ContainsAny(err.Error(), invalidSinceErrPrefix) {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user