Merge branch '20229-doc-inspect-requests'
[arvados.git] / lib / controller / localdb / group_test.go
index 78150c95527dc0f66ed6187bd64e93c7aef428c8..7de36e1c58e38b6c5ca7389ab6d75dfd819f7a43 100644 (file)
@@ -5,69 +5,20 @@
 package localdb
 
 import (
-       "context"
-
-       "git.arvados.org/arvados.git/lib/config"
-       "git.arvados.org/arvados.git/lib/controller/rpc"
+       "git.arvados.org/arvados.git/lib/ctrlctx"
        "git.arvados.org/arvados.git/sdk/go/arvados"
        "git.arvados.org/arvados.git/sdk/go/arvadostest"
-       "git.arvados.org/arvados.git/sdk/go/auth"
-       "git.arvados.org/arvados.git/sdk/go/ctxlog"
        check "gopkg.in/check.v1"
 )
 
 var _ = check.Suite(&GroupSuite{})
 
 type GroupSuite struct {
-       cluster  *arvados.Cluster
-       localdb  *Conn
-       railsSpy *arvadostest.Proxy
-}
-
-func (s *GroupSuite) SetUpSuite(c *check.C) {
-       cfg, err := config.NewLoader(nil, ctxlog.TestLogger(c)).Load()
-       c.Assert(err, check.IsNil)
-       s.cluster, err = cfg.GetCluster("")
-       c.Assert(err, check.IsNil)
-       s.localdb = NewConn(s.cluster)
-       s.railsSpy = arvadostest.NewProxy(c, s.cluster.Services.RailsAPI)
-       *s.localdb.railsProxy = *rpc.NewConn(s.cluster.ClusterID, s.railsSpy.URL, true, rpc.PassthroughTokenProvider)
-}
-
-func (s *GroupSuite) TearDownSuite(c *check.C) {
-       s.railsSpy.Close()
-       // Undo any changes/additions to the user database so they
-       // don't affect subsequent tests.
-       arvadostest.ResetEnv()
-       c.Check(arvados.NewClientFromEnv().RequestAndDecode(nil, "POST", "database/reset", nil, nil), check.IsNil)
-}
-
-func (s *GroupSuite) setUpVocabulary(c *check.C, testVocabulary string) {
-       if testVocabulary == "" {
-               testVocabulary = `{
-                       "strict_tags": false,
-                       "tags": {
-                               "IDTAGIMPORTANCES": {
-                                       "strict": true,
-                                       "labels": [{"label": "Importance"}, {"label": "Priority"}],
-                                       "values": {
-                                               "IDVALIMPORTANCES1": { "labels": [{"label": "Critical"}, {"label": "Urgent"}, {"label": "High"}] },
-                                               "IDVALIMPORTANCES2": { "labels": [{"label": "Normal"}, {"label": "Moderate"}] },
-                                               "IDVALIMPORTANCES3": { "labels": [{"label": "Low"}] }
-                                       }
-                               }
-                       }
-               }`
-       }
-       voc, err := arvados.NewVocabulary([]byte(testVocabulary), []string{})
-       c.Assert(err, check.IsNil)
-       s.localdb.vocabularyCache = voc
-       s.cluster.API.VocabularyPath = "foo"
+       localdbSuite
 }
 
 func (s *GroupSuite) TestGroupCreateWithProperties(c *check.C) {
        s.setUpVocabulary(c, "")
-       ctx := auth.NewContext(context.Background(), &auth.Credentials{Tokens: []string{arvadostest.ActiveTokenV2}})
 
        tests := []struct {
                name    string
@@ -82,7 +33,7 @@ func (s *GroupSuite) TestGroupCreateWithProperties(c *check.C) {
        for _, tt := range tests {
                c.Log(c.TestName()+" ", tt.name)
 
-               grp, err := s.localdb.GroupCreate(ctx, arvados.CreateOptions{
+               grp, err := s.localdb.GroupCreate(s.userctx, arvados.CreateOptions{
                        Select: []string{"uuid", "properties"},
                        Attrs: map[string]interface{}{
                                "group_class": "project",
@@ -99,7 +50,6 @@ func (s *GroupSuite) TestGroupCreateWithProperties(c *check.C) {
 
 func (s *GroupSuite) TestGroupUpdateWithProperties(c *check.C) {
        s.setUpVocabulary(c, "")
-       ctx := auth.NewContext(context.Background(), &auth.Credentials{Tokens: []string{arvadostest.ActiveTokenV2}})
 
        tests := []struct {
                name    string
@@ -113,13 +63,13 @@ func (s *GroupSuite) TestGroupUpdateWithProperties(c *check.C) {
        }
        for _, tt := range tests {
                c.Log(c.TestName()+" ", tt.name)
-               grp, err := s.localdb.GroupCreate(ctx, arvados.CreateOptions{
+               grp, err := s.localdb.GroupCreate(s.userctx, arvados.CreateOptions{
                        Attrs: map[string]interface{}{
                                "group_class": "project",
                        },
                })
                c.Assert(err, check.IsNil)
-               grp, err = s.localdb.GroupUpdate(ctx, arvados.UpdateOptions{
+               grp, err = s.localdb.GroupUpdate(s.userctx, arvados.UpdateOptions{
                        UUID:   grp.UUID,
                        Select: []string{"uuid", "properties"},
                        Attrs: map[string]interface{}{
@@ -135,9 +85,9 @@ func (s *GroupSuite) TestGroupUpdateWithProperties(c *check.C) {
 }
 
 func (s *GroupSuite) TestCanWriteCanManageResponses(c *check.C) {
-       ctxUser1 := auth.NewContext(context.Background(), &auth.Credentials{Tokens: []string{arvadostest.ActiveTokenV2}})
-       ctxUser2 := auth.NewContext(context.Background(), &auth.Credentials{Tokens: []string{arvadostest.SpectatorToken}})
-       ctxAdmin := auth.NewContext(context.Background(), &auth.Credentials{Tokens: []string{arvadostest.AdminToken}})
+       ctxUser1 := ctrlctx.NewWithToken(s.ctx, s.cluster, arvadostest.ActiveTokenV2)
+       ctxUser2 := ctrlctx.NewWithToken(s.ctx, s.cluster, arvadostest.SpectatorToken)
+       ctxAdmin := ctrlctx.NewWithToken(s.ctx, s.cluster, arvadostest.AdminToken)
        project, err := s.localdb.GroupCreate(ctxUser1, arvados.CreateOptions{
                Attrs: map[string]interface{}{
                        "group_class": "project",