1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
13 "git.arvados.org/arvados.git/lib/config"
14 "git.arvados.org/arvados.git/sdk/go/arvados"
15 "git.arvados.org/arvados.git/sdk/go/arvadostest"
16 "git.arvados.org/arvados.git/sdk/go/ctxlog"
17 "github.com/sirupsen/logrus"
18 check "gopkg.in/check.v1"
21 // Gocheck boilerplate
22 func Test(t *testing.T) {
26 var _ = check.Suite(&RPCSuite{})
31 contextKeyTestTokens key = iota
34 type RPCSuite struct {
35 log logrus.FieldLogger
40 func (s *RPCSuite) SetUpTest(c *check.C) {
41 ctx := ctxlog.Context(context.Background(), ctxlog.TestLogger(c))
42 s.ctx = context.WithValue(ctx, contextKeyTestTokens, []string{arvadostest.ActiveToken})
45 func (s *RPCSuite) setupConn(c *check.C, host string) {
46 s.conn = NewConn("zzzzz", &url.URL{Scheme: "https", Host: host}, true, func(ctx context.Context) ([]string, error) {
47 tokens, _ := ctx.Value(contextKeyTestTokens).([]string)
52 func (s *RPCSuite) workbench2URL(c *check.C) string {
53 loader := config.NewLoader(nil, s.log)
54 cfg, err := loader.Load()
55 c.Assert(err, check.IsNil)
56 cluster, err := cfg.GetCluster("")
57 c.Assert(err, check.IsNil)
58 return cluster.Services.Workbench2.ExternalURL.String()
61 func (s *RPCSuite) TestRailsLogin404(c *check.C) {
62 s.setupConn(c, os.Getenv("ARVADOS_TEST_API_HOST"))
63 s.ctx = context.Background()
64 opts := arvados.LoginOptions{
65 ReturnTo: "https://foo.example.com/bar",
67 _, err := s.conn.Login(s.ctx, opts)
68 c.Check(err.(*arvados.TransactionError).StatusCode, check.Equals, 404)
71 func (s *RPCSuite) TestRailsLogout404(c *check.C) {
72 s.setupConn(c, os.Getenv("ARVADOS_TEST_API_HOST"))
73 s.ctx = context.Background()
74 opts := arvados.LogoutOptions{
75 ReturnTo: "https://foo.example.com/bar",
77 _, err := s.conn.Logout(s.ctx, opts)
78 c.Check(err.(*arvados.TransactionError).StatusCode, check.Equals, 404)
81 func (s *RPCSuite) TestControllerLogout(c *check.C) {
82 s.setupConn(c, os.Getenv("ARVADOS_API_HOST"))
83 s.ctx = context.Background()
84 url := s.workbench2URL(c)
85 opts := arvados.LogoutOptions{
88 resp, err := s.conn.Logout(s.ctx, opts)
89 c.Check(err, check.IsNil)
90 c.Check(resp.RedirectLocation, check.Equals, url)
93 func (s *RPCSuite) TestCollectionCreate(c *check.C) {
94 s.setupConn(c, os.Getenv("ARVADOS_TEST_API_HOST"))
95 coll, err := s.conn.CollectionCreate(s.ctx, arvados.CreateOptions{Attrs: map[string]interface{}{
96 "owner_uuid": arvadostest.ActiveUserUUID,
97 "portable_data_hash": "d41d8cd98f00b204e9800998ecf8427e+0",
99 c.Check(err, check.IsNil)
100 c.Check(coll.UUID, check.HasLen, 27)
103 func (s *RPCSuite) TestGroupCRUD(c *check.C) {
104 s.setupConn(c, os.Getenv("ARVADOS_TEST_API_HOST"))
105 sp, err := s.conn.GroupCreate(s.ctx, arvados.CreateOptions{Attrs: map[string]interface{}{
106 "group_class": "project",
107 "owner_uuid": arvadostest.ActiveUserUUID,
108 "properties": map[string]string{"foo": "bar"},
110 c.Check(err, check.IsNil)
111 c.Check(sp.UUID, check.HasLen, 27)
112 c.Check(sp.Properties, check.HasLen, 1)
113 c.Check(sp.Properties["foo"], check.Equals, "bar")
115 spGet, err := s.conn.GroupGet(s.ctx, arvados.GetOptions{UUID: sp.UUID})
116 c.Check(err, check.IsNil)
117 c.Check(spGet.UUID, check.Equals, sp.UUID)
118 c.Check(spGet.Properties["foo"], check.Equals, "bar")
120 spList, err := s.conn.GroupList(s.ctx, arvados.ListOptions{Limit: -1, Filters: []arvados.Filter{{"uuid", "=", sp.UUID}}})
121 c.Check(err, check.IsNil)
122 c.Check(spList.ItemsAvailable, check.Equals, 1)
123 c.Assert(spList.Items, check.HasLen, 1)
124 c.Check(spList.Items[0].UUID, check.Equals, sp.UUID)
125 c.Check(spList.Items[0].Properties["foo"], check.Equals, "bar")
127 anonCtx := context.WithValue(context.Background(), contextKeyTestTokens, []string{arvadostest.AnonymousToken})
128 spList, err = s.conn.GroupList(anonCtx, arvados.ListOptions{Limit: -1, Filters: []arvados.Filter{{"uuid", "=", sp.UUID}}})
129 c.Check(err, check.IsNil)
130 c.Check(spList.ItemsAvailable, check.Equals, 0)
131 c.Check(spList.Items, check.HasLen, 0)
133 spDel, err := s.conn.GroupDelete(s.ctx, arvados.DeleteOptions{UUID: sp.UUID})
134 c.Check(err, check.IsNil)
135 c.Check(spDel.UUID, check.Equals, sp.UUID)