1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
13 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
14 check "gopkg.in/check.v1"
17 var _ = check.Suite(&MountsSuite{})
19 type MountsSuite struct {
24 func (s *MountsSuite) SetUpTest(c *check.C) {
25 s.vm = MakeTestVolumeManager(2)
27 s.rtr = MakeRESTRouter()
28 theConfig.systemAuthToken = arvadostest.DataManagerToken
31 func (s *MountsSuite) TearDownTest(c *check.C) {
34 theConfig = DefaultConfig()
38 func (s *MountsSuite) TestMounts(c *check.C) {
39 vols := s.vm.AllWritable()
40 vols[0].Put(context.Background(), TestHash, TestBlock)
41 vols[1].Put(context.Background(), TestHash2, TestBlock2)
43 resp := s.call("GET", "/mounts", "")
44 c.Check(resp.Code, check.Equals, http.StatusOK)
45 var mntList []struct {
52 err := json.Unmarshal(resp.Body.Bytes(), &mntList)
53 c.Assert(err, check.IsNil)
54 c.Assert(len(mntList), check.Equals, 2)
55 for _, m := range mntList {
56 c.Check(len(m.UUID), check.Equals, 27)
57 c.Check(m.UUID[:12], check.Equals, "zzzzz-ivpuk-")
58 c.Check(m.DeviceID, check.Equals, "mock-device-id")
59 c.Check(m.ReadOnly, check.Equals, false)
60 c.Check(m.Replication, check.Equals, 1)
61 c.Check(m.Tier, check.Equals, 1)
63 c.Check(mntList[0].UUID, check.Not(check.Equals), mntList[1].UUID)
66 for _, tok := range []string{"", "xyzzy"} {
67 resp = s.call("GET", "/mounts/"+mntList[1].UUID+"/blocks", tok)
68 c.Check(resp.Code, check.Equals, http.StatusUnauthorized)
69 c.Check(resp.Body.String(), check.Equals, "Unauthorized\n")
72 tok := arvadostest.DataManagerToken
74 // Nonexistent mount UUID
75 resp = s.call("GET", "/mounts/X/blocks", tok)
76 c.Check(resp.Code, check.Equals, http.StatusNotFound)
77 c.Check(resp.Body.String(), check.Equals, "mount not found\n")
79 // Complete index of first mount
80 resp = s.call("GET", "/mounts/"+mntList[0].UUID+"/blocks", tok)
81 c.Check(resp.Code, check.Equals, http.StatusOK)
82 c.Check(resp.Body.String(), check.Matches, TestHash+`\+[0-9]+ [0-9]+\n\n`)
84 // Partial index of first mount (one block matches prefix)
85 resp = s.call("GET", "/mounts/"+mntList[0].UUID+"/blocks?prefix="+TestHash[:2], tok)
86 c.Check(resp.Code, check.Equals, http.StatusOK)
87 c.Check(resp.Body.String(), check.Matches, TestHash+`\+[0-9]+ [0-9]+\n\n`)
89 // Complete index of second mount (note trailing slash)
90 resp = s.call("GET", "/mounts/"+mntList[1].UUID+"/blocks/", tok)
91 c.Check(resp.Code, check.Equals, http.StatusOK)
92 c.Check(resp.Body.String(), check.Matches, TestHash2+`\+[0-9]+ [0-9]+\n\n`)
94 // Partial index of second mount (no blocks match prefix)
95 resp = s.call("GET", "/mounts/"+mntList[1].UUID+"/blocks/?prefix="+TestHash[:2], tok)
96 c.Check(resp.Code, check.Equals, http.StatusOK)
97 c.Check(resp.Body.String(), check.Equals, "\n")
100 func (s *MountsSuite) call(method, path, tok string) *httptest.ResponseRecorder {
101 resp := httptest.NewRecorder()
102 req, _ := http.NewRequest(method, path, nil)
104 req.Header.Set("Authorization", "OAuth2 "+tok)
106 s.rtr.ServeHTTP(resp, req)