From f6b525a2a7b19f6f09e006a35332e7c254b6ab8c Mon Sep 17 00:00:00 2001 From: Francisco Souza Date: Tue, 10 Feb 2015 18:10:48 -0200 Subject: [PATCH] gandalftest: add Repositories method to the testing server --- gandalftest/server.go | 9 ++++++++- gandalftest/server_test.go | 8 ++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/gandalftest/server.go b/gandalftest/server.go index 1ae408a..1c2fbba 100644 --- a/gandalftest/server.go +++ b/gandalftest/server.go @@ -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)) diff --git a/gandalftest/server_test.go b/gandalftest/server_test.go index 39bb9d6..458a685 100644 --- a/gandalftest/server_test.go +++ b/gandalftest/server_test.go @@ -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)