21700: Install Bundler system-wide in Rails postinst
[arvados.git] / lib / controller / localdb / link_test.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package localdb
6
7 import (
8         "git.arvados.org/arvados.git/sdk/go/arvados"
9         "git.arvados.org/arvados.git/sdk/go/arvadostest"
10         check "gopkg.in/check.v1"
11 )
12
13 var _ = check.Suite(&LinkSuite{})
14
15 type LinkSuite struct {
16         localdbSuite
17 }
18
19 func (s *LinkSuite) TestLinkCreateWithProperties(c *check.C) {
20         s.setUpVocabulary(c, "")
21
22         tests := []struct {
23                 name    string
24                 props   map[string]interface{}
25                 success bool
26         }{
27                 {"Invalid prop key", map[string]interface{}{"Priority": "IDVALIMPORTANCES1"}, false},
28                 {"Invalid prop value", map[string]interface{}{"IDTAGIMPORTANCES": "high"}, false},
29                 {"Valid prop key & value", map[string]interface{}{"IDTAGIMPORTANCES": "IDVALIMPORTANCES1"}, true},
30                 {"Empty properties", map[string]interface{}{}, true},
31         }
32         for _, tt := range tests {
33                 c.Log(c.TestName()+" ", tt.name)
34
35                 lnk, err := s.localdb.LinkCreate(s.userctx, arvados.CreateOptions{
36                         Select: []string{"uuid", "properties"},
37                         Attrs: map[string]interface{}{
38                                 "link_class": "star",
39                                 "tail_uuid":  "zzzzz-j7d0g-publicfavorites",
40                                 "head_uuid":  arvadostest.FooCollection,
41                                 "properties": tt.props,
42                         }})
43                 if tt.success {
44                         c.Assert(err, check.IsNil)
45                         c.Assert(lnk.Properties, check.DeepEquals, tt.props)
46                 } else {
47                         c.Assert(err, check.NotNil)
48                 }
49         }
50 }
51
52 func (s *LinkSuite) TestLinkUpdateWithProperties(c *check.C) {
53         s.setUpVocabulary(c, "")
54
55         tests := []struct {
56                 name    string
57                 props   map[string]interface{}
58                 success bool
59         }{
60                 {"Invalid prop key", map[string]interface{}{"Priority": "IDVALIMPORTANCES1"}, false},
61                 {"Invalid prop value", map[string]interface{}{"IDTAGIMPORTANCES": "high"}, false},
62                 {"Valid prop key & value", map[string]interface{}{"IDTAGIMPORTANCES": "IDVALIMPORTANCES1"}, true},
63                 {"Empty properties", map[string]interface{}{}, true},
64         }
65         for _, tt := range tests {
66                 c.Log(c.TestName()+" ", tt.name)
67                 lnk, err := s.localdb.LinkCreate(s.userctx, arvados.CreateOptions{
68                         Attrs: map[string]interface{}{
69                                 "link_class": "star",
70                                 "tail_uuid":  "zzzzz-j7d0g-publicfavorites",
71                                 "head_uuid":  arvadostest.FooCollection,
72                         },
73                 })
74                 c.Assert(err, check.IsNil)
75                 lnk, err = s.localdb.LinkUpdate(s.userctx, arvados.UpdateOptions{
76                         UUID:   lnk.UUID,
77                         Select: []string{"uuid", "properties"},
78                         Attrs: map[string]interface{}{
79                                 "properties": tt.props,
80                         }})
81                 if tt.success {
82                         c.Assert(err, check.IsNil)
83                         c.Assert(lnk.Properties, check.DeepEquals, tt.props)
84                 } else {
85                         c.Assert(err, check.NotNil)
86                 }
87         }
88 }