1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
10 "git.arvados.org/arvados.git/lib/config"
11 "git.arvados.org/arvados.git/lib/controller/rpc"
12 "git.arvados.org/arvados.git/sdk/go/arvados"
13 "git.arvados.org/arvados.git/sdk/go/arvadostest"
14 "git.arvados.org/arvados.git/sdk/go/auth"
15 "git.arvados.org/arvados.git/sdk/go/ctxlog"
16 check "gopkg.in/check.v1"
19 var _ = check.Suite(&GroupSuite{})
21 type GroupSuite struct {
22 cluster *arvados.Cluster
24 railsSpy *arvadostest.Proxy
27 func (s *GroupSuite) TearDownSuite(c *check.C) {
28 // Undo any changes/additions to the user database so they
29 // don't affect subsequent tests.
30 arvadostest.ResetEnv()
31 c.Check(arvados.NewClientFromEnv().RequestAndDecode(nil, "POST", "database/reset", nil, nil), check.IsNil)
34 func (s *GroupSuite) SetUpTest(c *check.C) {
35 cfg, err := config.NewLoader(nil, ctxlog.TestLogger(c)).Load()
36 c.Assert(err, check.IsNil)
37 s.cluster, err = cfg.GetCluster("")
38 c.Assert(err, check.IsNil)
39 s.localdb = NewConn(s.cluster)
40 s.railsSpy = arvadostest.NewProxy(c, s.cluster.Services.RailsAPI)
41 *s.localdb.railsProxy = *rpc.NewConn(s.cluster.ClusterID, s.railsSpy.URL, true, rpc.PassthroughTokenProvider)
44 func (s *GroupSuite) TearDownTest(c *check.C) {
48 func (s *GroupSuite) setUpVocabulary(c *check.C, testVocabulary string) {
49 if testVocabulary == "" {
55 "labels": [{"label": "Importance"}, {"label": "Priority"}],
57 "IDVALIMPORTANCES1": { "labels": [{"label": "Critical"}, {"label": "Urgent"}, {"label": "High"}] },
58 "IDVALIMPORTANCES2": { "labels": [{"label": "Normal"}, {"label": "Moderate"}] },
59 "IDVALIMPORTANCES3": { "labels": [{"label": "Low"}] }
65 voc, err := arvados.NewVocabulary([]byte(testVocabulary), []string{})
66 c.Assert(err, check.IsNil)
67 s.localdb.vocabularyCache = voc
68 s.cluster.API.VocabularyPath = "foo"
71 func (s *GroupSuite) TestGroupCreateWithProperties(c *check.C) {
72 s.setUpVocabulary(c, "")
73 ctx := auth.NewContext(context.Background(), &auth.Credentials{Tokens: []string{arvadostest.ActiveTokenV2}})
77 props map[string]interface{}
80 {"Invalid prop key", map[string]interface{}{"Priority": "IDVALIMPORTANCES1"}, false},
81 {"Invalid prop value", map[string]interface{}{"IDTAGIMPORTANCES": "high"}, false},
82 {"Valid prop key & value", map[string]interface{}{"IDTAGIMPORTANCES": "IDVALIMPORTANCES1"}, true},
83 {"Empty properties", map[string]interface{}{}, true},
85 for _, tt := range tests {
86 c.Log(c.TestName()+" ", tt.name)
88 grp, err := s.localdb.GroupCreate(ctx, arvados.CreateOptions{
89 Select: []string{"uuid", "properties"},
90 Attrs: map[string]interface{}{
91 "group_class": "project",
92 "properties": tt.props,
95 c.Assert(err, check.IsNil)
96 c.Assert(grp.Properties, check.DeepEquals, tt.props)
98 c.Assert(err, check.NotNil)
103 func (s *GroupSuite) TestGroupUpdateWithProperties(c *check.C) {
104 s.setUpVocabulary(c, "")
105 ctx := auth.NewContext(context.Background(), &auth.Credentials{Tokens: []string{arvadostest.ActiveTokenV2}})
109 props map[string]interface{}
112 {"Invalid prop key", map[string]interface{}{"Priority": "IDVALIMPORTANCES1"}, false},
113 {"Invalid prop value", map[string]interface{}{"IDTAGIMPORTANCES": "high"}, false},
114 {"Valid prop key & value", map[string]interface{}{"IDTAGIMPORTANCES": "IDVALIMPORTANCES1"}, true},
115 {"Empty properties", map[string]interface{}{}, true},
117 for _, tt := range tests {
118 c.Log(c.TestName()+" ", tt.name)
119 grp, err := s.localdb.GroupCreate(ctx, arvados.CreateOptions{
120 Attrs: map[string]interface{}{
121 "group_class": "project",
124 c.Assert(err, check.IsNil)
125 grp, err = s.localdb.GroupUpdate(ctx, arvados.UpdateOptions{
127 Select: []string{"uuid", "properties"},
128 Attrs: map[string]interface{}{
129 "properties": tt.props,
132 c.Assert(err, check.IsNil)
133 c.Assert(grp.Properties, check.DeepEquals, tt.props)
135 c.Assert(err, check.NotNil)