1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
13 "git.arvados.org/arvados.git/sdk/go/arvados"
14 "git.arvados.org/arvados.git/sdk/go/arvadostest"
15 "git.arvados.org/arvados.git/sdk/go/ctxlog"
16 "github.com/sirupsen/logrus"
17 check "gopkg.in/check.v1"
20 // Gocheck boilerplate
21 func Test(t *testing.T) {
25 var _ = check.Suite(&RPCSuite{})
30 contextKeyTestTokens key = iota
33 type RPCSuite struct {
34 log logrus.FieldLogger
39 func (s *RPCSuite) SetUpTest(c *check.C) {
40 ctx := ctxlog.Context(context.Background(), ctxlog.TestLogger(c))
41 s.ctx = context.WithValue(ctx, contextKeyTestTokens, []string{arvadostest.ActiveToken})
42 s.conn = NewConn("zzzzz", &url.URL{Scheme: "https", Host: os.Getenv("ARVADOS_TEST_API_HOST")}, true, func(ctx context.Context) ([]string, error) {
43 tokens, _ := ctx.Value(contextKeyTestTokens).([]string)
48 func (s *RPCSuite) TestLogin(c *check.C) {
49 s.ctx = context.Background()
50 opts := arvados.LoginOptions{
51 ReturnTo: "https://foo.example.com/bar",
53 resp, err := s.conn.Login(s.ctx, opts)
54 c.Check(err, check.IsNil)
55 c.Check(resp.RedirectLocation, check.Equals, "/auth/joshid?return_to="+url.QueryEscape(","+opts.ReturnTo))
58 func (s *RPCSuite) TestLogout(c *check.C) {
59 s.ctx = context.Background()
60 opts := arvados.LogoutOptions{
61 ReturnTo: "https://foo.example.com/bar",
63 resp, err := s.conn.Logout(s.ctx, opts)
64 c.Check(err, check.IsNil)
65 c.Check(resp.RedirectLocation, check.Equals, "http://localhost:3002/users/sign_out?redirect_uri="+url.QueryEscape(opts.ReturnTo))
68 func (s *RPCSuite) TestCollectionCreate(c *check.C) {
69 coll, err := s.conn.CollectionCreate(s.ctx, arvados.CreateOptions{Attrs: map[string]interface{}{
70 "owner_uuid": arvadostest.ActiveUserUUID,
71 "portable_data_hash": "d41d8cd98f00b204e9800998ecf8427e+0",
73 c.Check(err, check.IsNil)
74 c.Check(coll.UUID, check.HasLen, 27)
77 func (s *RPCSuite) TestSpecimenCRUD(c *check.C) {
78 sp, err := s.conn.SpecimenCreate(s.ctx, arvados.CreateOptions{Attrs: map[string]interface{}{
79 "owner_uuid": arvadostest.ActiveUserUUID,
80 "properties": map[string]string{"foo": "bar"},
82 c.Check(err, check.IsNil)
83 c.Check(sp.UUID, check.HasLen, 27)
84 c.Check(sp.Properties, check.HasLen, 1)
85 c.Check(sp.Properties["foo"], check.Equals, "bar")
87 spGet, err := s.conn.SpecimenGet(s.ctx, arvados.GetOptions{UUID: sp.UUID})
88 c.Check(err, check.IsNil)
89 c.Check(spGet.UUID, check.Equals, sp.UUID)
90 c.Check(spGet.Properties["foo"], check.Equals, "bar")
92 spList, err := s.conn.SpecimenList(s.ctx, arvados.ListOptions{Limit: -1, Filters: []arvados.Filter{{"uuid", "=", sp.UUID}}})
93 c.Check(err, check.IsNil)
94 c.Check(spList.ItemsAvailable, check.Equals, 1)
95 c.Assert(spList.Items, check.HasLen, 1)
96 c.Check(spList.Items[0].UUID, check.Equals, sp.UUID)
97 c.Check(spList.Items[0].Properties["foo"], check.Equals, "bar")
99 anonCtx := context.WithValue(context.Background(), contextKeyTestTokens, []string{arvadostest.AnonymousToken})
100 spList, err = s.conn.SpecimenList(anonCtx, arvados.ListOptions{Limit: -1, Filters: []arvados.Filter{{"uuid", "=", sp.UUID}}})
101 c.Check(err, check.IsNil)
102 c.Check(spList.ItemsAvailable, check.Equals, 0)
103 c.Check(spList.Items, check.HasLen, 0)
105 spDel, err := s.conn.SpecimenDelete(s.ctx, arvados.DeleteOptions{UUID: sp.UUID})
106 c.Check(err, check.IsNil)
107 c.Check(spDel.UUID, check.Equals, sp.UUID)