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

Commit

Permalink
gandalftest: add Repositories method 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 eff5d73 commit f6b525a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
9 changes: 8 additions & 1 deletion gandalftest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,20 @@ func (s *GandalfServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
s.muxer.ServeHTTP(w, r)
}

// Users return the list of users registered in the server.
// Users returns the list of users registered in the server.
func (s *GandalfServer) Users() []string {
s.usersLock.RLock()
defer s.usersLock.RUnlock()
return s.users
}

// Repository returns the list of repositories registered in the server.
func (s *GandalfServer) Repositories() []repository.Repository {
s.repoLock.RLock()
defer s.repoLock.RUnlock()
return s.repos
}

func (s *GandalfServer) buildMuxer() {
s.muxer = pat.New()
s.muxer.Post("/user/{name}/key", http.HandlerFunc(s.addKeys))
Expand Down
8 changes: 8 additions & 0 deletions gandalftest/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ func (s *S) TestUsers(c *check.C) {
c.Assert(server.Users(), check.DeepEquals, server.users)
}

func (s *S) TestRepositories(c *check.C) {
server, err := NewServer("127.0.0.1:0")
c.Assert(err, check.IsNil)
defer server.Stop()
server.repos = []repository.Repository{{Name: "something"}, {Name: "otherthing"}}
c.Assert(server.Repositories(), check.DeepEquals, server.repos)
}

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

0 comments on commit f6b525a

Please sign in to comment.