Skip to content
This repository has been archived by the owner on Apr 26, 2021. It is now read-only.

Commit

Permalink
gandalftest: add healthcheck to the testing server
Browse files Browse the repository at this point in the history
  • Loading branch information
Francisco Souza committed Feb 10, 2015
1 parent 55d24ed commit d63c912
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions gandalftest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ func (s *GandalfServer) buildMuxer() {
s.muxer.Post("/repository", http.HandlerFunc(s.createRepository))
s.muxer.Delete("/repository/{name}", http.HandlerFunc(s.removeRepository))
s.muxer.Get("/repository/{name}", http.HandlerFunc(s.getRepository))
s.muxer.Get("/healthcheck", http.HandlerFunc(s.healthcheck))
}

func (s *GandalfServer) createUser(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -456,6 +457,10 @@ func (s *GandalfServer) listKeys(w http.ResponseWriter, r *http.Request) {
}
}

func (s *GandalfServer) healthcheck(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("WORKING"))
}

func (s *GandalfServer) findUser(name string) (userName string, index int) {
s.usersLock.RLock()
defer s.usersLock.RUnlock()
Expand Down
11 changes: 11 additions & 0 deletions gandalftest/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,17 @@ func (s *S) TestRevokeAccessMissingRepositories(c *check.C) {
c.Assert(recorder.Body.String(), check.Equals, "missing repositories\n")
}

func (s *S) TestHealthCheck(c *check.C) {
server, err := NewServer("127.0.0.1:0")
c.Assert(err, check.IsNil)
defer server.Stop()
recorder := httptest.NewRecorder()
request, _ := http.NewRequest("GET", "/healthcheck", nil)
server.ServeHTTP(recorder, request)
c.Assert(recorder.Code, check.Equals, http.StatusOK)
c.Assert(recorder.Body.String(), check.Equals, "WORKING")
}

func (s *S) TestPrepareFailure(c *check.C) {
server, err := NewServer("127.0.0.1:0")
c.Assert(err, check.IsNil)
Expand Down

0 comments on commit d63c912

Please sign in to comment.