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 _, err := s.conn.Login(s.ctx, opts)
54 c.Check(err.(*arvados.TransactionError).StatusCode, check.Equals, 404)
57 func (s *RPCSuite) TestLogout(c *check.C) {
58 s.ctx = context.Background()
59 opts := arvados.LogoutOptions{
60 ReturnTo: "https://foo.example.com/bar",
62 resp, err := s.conn.Logout(s.ctx, opts)
63 c.Check(err, check.IsNil)
64 c.Check(resp.RedirectLocation, check.Equals, opts.ReturnTo)
67 func (s *RPCSuite) TestCollectionCreate(c *check.C) {
68 coll, err := s.conn.CollectionCreate(s.ctx, arvados.CreateOptions{Attrs: map[string]interface{}{
69 "owner_uuid": arvadostest.ActiveUserUUID,
70 "portable_data_hash": "d41d8cd98f00b204e9800998ecf8427e+0",
72 c.Check(err, check.IsNil)
73 c.Check(coll.UUID, check.HasLen, 27)
76 func (s *RPCSuite) TestSpecimenCRUD(c *check.C) {
77 sp, err := s.conn.SpecimenCreate(s.ctx, arvados.CreateOptions{Attrs: map[string]interface{}{
78 "owner_uuid": arvadostest.ActiveUserUUID,
79 "properties": map[string]string{"foo": "bar"},
81 c.Check(err, check.IsNil)
82 c.Check(sp.UUID, check.HasLen, 27)
83 c.Check(sp.Properties, check.HasLen, 1)
84 c.Check(sp.Properties["foo"], check.Equals, "bar")
86 spGet, err := s.conn.SpecimenGet(s.ctx, arvados.GetOptions{UUID: sp.UUID})
87 c.Check(err, check.IsNil)
88 c.Check(spGet.UUID, check.Equals, sp.UUID)
89 c.Check(spGet.Properties["foo"], check.Equals, "bar")
91 spList, err := s.conn.SpecimenList(s.ctx, arvados.ListOptions{Limit: -1, Filters: []arvados.Filter{{"uuid", "=", sp.UUID}}})
92 c.Check(err, check.IsNil)
93 c.Check(spList.ItemsAvailable, check.Equals, 1)
94 c.Assert(spList.Items, check.HasLen, 1)
95 c.Check(spList.Items[0].UUID, check.Equals, sp.UUID)
96 c.Check(spList.Items[0].Properties["foo"], check.Equals, "bar")
98 anonCtx := context.WithValue(context.Background(), contextKeyTestTokens, []string{arvadostest.AnonymousToken})
99 spList, err = s.conn.SpecimenList(anonCtx, arvados.ListOptions{Limit: -1, Filters: []arvados.Filter{{"uuid", "=", sp.UUID}}})
100 c.Check(err, check.IsNil)
101 c.Check(spList.ItemsAvailable, check.Equals, 0)
102 c.Check(spList.Items, check.HasLen, 0)
104 spDel, err := s.conn.SpecimenDelete(s.ctx, arvados.DeleteOptions{UUID: sp.UUID})
105 c.Check(err, check.IsNil)
106 c.Check(spDel.UUID, check.Equals, sp.UUID)