20140: Accept wildcards in TrustedClients.
[arvados.git] / lib / controller / localdb / container_request_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         check "gopkg.in/check.v1"
10 )
11
12 var _ = check.Suite(&ContainerRequestSuite{})
13
14 type ContainerRequestSuite struct {
15         localdbSuite
16 }
17
18 func (s *ContainerRequestSuite) TestCRCreateWithProperties(c *check.C) {
19         s.setUpVocabulary(c, "")
20
21         tests := []struct {
22                 name    string
23                 props   map[string]interface{}
24                 success bool
25         }{
26                 {"Invalid prop key", map[string]interface{}{"Priority": "IDVALIMPORTANCES1"}, false},
27                 {"Invalid prop value", map[string]interface{}{"IDTAGIMPORTANCES": "high"}, false},
28                 {"Valid prop key & value", map[string]interface{}{"IDTAGIMPORTANCES": "IDVALIMPORTANCES1"}, true},
29                 {"Empty properties", map[string]interface{}{}, true},
30         }
31         for _, tt := range tests {
32                 c.Log(c.TestName()+" ", tt.name)
33
34                 cnt, err := s.localdb.ContainerRequestCreate(s.userctx, arvados.CreateOptions{
35                         Select: []string{"uuid", "properties"},
36                         Attrs: map[string]interface{}{
37                                 "command":         []string{"echo", "foo"},
38                                 "container_image": "arvados/apitestfixture:latest",
39                                 "cwd":             "/tmp",
40                                 "environment":     map[string]string{},
41                                 "mounts": map[string]interface{}{
42                                         "/out": map[string]interface{}{
43                                                 "kind":     "tmp",
44                                                 "capacity": 1000000,
45                                         },
46                                 },
47                                 "output_path": "/out",
48                                 "runtime_constraints": map[string]interface{}{
49                                         "vcpus": 1,
50                                         "ram":   2,
51                                 },
52                                 "properties": tt.props,
53                         }})
54                 if tt.success {
55                         c.Assert(err, check.IsNil)
56                         c.Assert(cnt.Properties, check.DeepEquals, tt.props)
57                 } else {
58                         c.Assert(err, check.NotNil)
59                 }
60         }
61 }
62
63 func (s *ContainerRequestSuite) TestCRUpdateWithProperties(c *check.C) {
64         s.setUpVocabulary(c, "")
65
66         tests := []struct {
67                 name    string
68                 props   map[string]interface{}
69                 success bool
70         }{
71                 {"Invalid prop key", map[string]interface{}{"Priority": "IDVALIMPORTANCES1"}, false},
72                 {"Invalid prop value", map[string]interface{}{"IDTAGIMPORTANCES": "high"}, false},
73                 {"Valid prop key & value", map[string]interface{}{"IDTAGIMPORTANCES": "IDVALIMPORTANCES1"}, true},
74                 {"Empty properties", map[string]interface{}{}, true},
75         }
76         for _, tt := range tests {
77                 c.Log(c.TestName()+" ", tt.name)
78                 cnt, err := s.localdb.ContainerRequestCreate(s.userctx, arvados.CreateOptions{
79                         Attrs: map[string]interface{}{
80                                 "command":         []string{"echo", "foo"},
81                                 "container_image": "arvados/apitestfixture:latest",
82                                 "cwd":             "/tmp",
83                                 "environment":     map[string]string{},
84                                 "mounts": map[string]interface{}{
85                                         "/out": map[string]interface{}{
86                                                 "kind":     "tmp",
87                                                 "capacity": 1000000,
88                                         },
89                                 },
90                                 "output_path": "/out",
91                                 "runtime_constraints": map[string]interface{}{
92                                         "vcpus": 1,
93                                         "ram":   2,
94                                 },
95                         },
96                 })
97                 c.Assert(err, check.IsNil)
98                 cnt, err = s.localdb.ContainerRequestUpdate(s.userctx, arvados.UpdateOptions{
99                         UUID:   cnt.UUID,
100                         Select: []string{"uuid", "properties"},
101                         Attrs: map[string]interface{}{
102                                 "properties": tt.props,
103                         }})
104                 if tt.success {
105                         c.Assert(err, check.IsNil)
106                         c.Assert(cnt.Properties, check.DeepEquals, tt.props)
107                 } else {
108                         c.Assert(err, check.NotNil)
109                 }
110         }
111 }