12018: Added API server start/stop calls to test suite.
authorLucas Di Pentima <ldipentima@veritasgenetics.com>
Tue, 31 Oct 2017 21:07:01 +0000 (18:07 -0300)
committerLucas Di Pentima <ldipentima@veritasgenetics.com>
Tue, 31 Oct 2017 21:07:01 +0000 (18:07 -0300)
Removed manual database cleanup in favour of using the database
reset endpoint after every test run.
Moved tool config set up code from the suite set up call to the test
set up, because the database get reset to fixture state after every
test run.

Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <ldipentima@veritasgenetics.com>

tools/arv-sync-groups/arv-sync-groups_test.go

index 81ae0beb81277091d4e676f75e59df65635bc625..e776648a803736581dcb61724631ac844cdca68f 100644 (file)
@@ -27,6 +27,14 @@ type TestSuite struct {
 }
 
 func (s *TestSuite) SetUpSuite(c *C) {
+       arvadostest.StartAPI()
+}
+
+func (s *TestSuite) TearDownSuite(c *C) {
+       arvadostest.StopAPI()
+}
+
+func (s *TestSuite) SetUpTest(c *C) {
        ac := arvados.NewClientFromEnv()
        u, err := ac.CurrentUser()
        c.Assert(err, IsNil)
@@ -77,61 +85,10 @@ func (s *TestSuite) SetUpSuite(c *C) {
 
 // Clean any membership link and remote group created by the test
 func (s *TestSuite) TearDownTest(c *C) {
-       gl := arvados.GroupList{}
-       params := arvados.ResourceListParams{
-               Filters: []arvados.Filter{{
-                       Attr:     "group_class",
-                       Operator: "=",
-                       Operand:  "role",
-               }, {
-                       Attr:     "owner_uuid",
-                       Operator: "=",
-                       Operand:  s.cfg.ParentGroupUUID,
-               }},
-       }
-       err := s.cfg.Client.RequestAndDecode(&gl, "GET", "/arvados/v1/groups", nil, params)
+       var dst interface{}
+       // Reset database to fixture state after every test run.
+       err := s.cfg.Client.RequestAndDecode(&dst, "POST", "/database/reset", nil, nil)
        c.Assert(err, IsNil)
-       for _, group := range gl.Items {
-               ll := arvados.LinkList{}
-               // Delete user->group links
-               params = arvados.ResourceListParams{
-                       Filters: []arvados.Filter{{
-                               Attr:     "link_class",
-                               Operator: "=",
-                               Operand:  "permission",
-                       }, {
-                               Attr:     "head_uuid",
-                               Operator: "=",
-                               Operand:  group.UUID,
-                       }},
-               }
-               err = s.cfg.Client.RequestAndDecode(&ll, "GET", "/arvados/v1/links", nil, params)
-               c.Assert(err, IsNil)
-               for _, link := range ll.Items {
-                       err = DeleteLink(s.cfg, link.UUID)
-                       c.Assert(err, IsNil)
-               }
-               // Delete group->user links
-               params = arvados.ResourceListParams{
-                       Filters: []arvados.Filter{{
-                               Attr:     "link_class",
-                               Operator: "=",
-                               Operand:  "permission",
-                       }, {
-                               Attr:     "tail_uuid",
-                               Operator: "=",
-                               Operand:  group.UUID,
-                       }},
-               }
-               s.cfg.Client.RequestAndDecode(&ll, "GET", "/arvados/v1/links", nil, params)
-               for _, link := range ll.Items {
-                       err = DeleteLink(s.cfg, link.UUID)
-                       c.Assert(err, IsNil)
-               }
-               // Delete group
-               err = s.cfg.Client.RequestAndDecode(&arvados.Group{}, "DELETE", "/arvados/v1/groups/"+group.UUID, nil, nil)
-               c.Assert(err, IsNil)
-       }
 }
 
 var _ = Suite(&TestSuite{})