9 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
10 check "gopkg.in/check.v1"
13 var _ = check.Suite(&MountsSuite{})
15 type MountsSuite struct {
20 func (s *MountsSuite) SetUpTest(c *check.C) {
21 s.vm = MakeTestVolumeManager(2)
23 s.rtr = MakeRESTRouter()
24 theConfig.systemAuthToken = arvadostest.DataManagerToken
27 func (s *MountsSuite) TearDownTest(c *check.C) {
30 theConfig = DefaultConfig()
34 func (s *MountsSuite) TestMounts(c *check.C) {
35 vols := s.vm.AllWritable()
36 vols[0].Put(context.Background(), TestHash, TestBlock)
37 vols[1].Put(context.Background(), TestHash2, TestBlock2)
39 resp := s.call("GET", "/mounts", "")
40 c.Check(resp.Code, check.Equals, http.StatusOK)
41 var mntList []struct {
48 err := json.Unmarshal(resp.Body.Bytes(), &mntList)
49 c.Assert(err, check.IsNil)
50 c.Assert(len(mntList), check.Equals, 2)
51 for _, m := range mntList {
52 c.Check(len(m.UUID), check.Equals, 27)
53 c.Check(m.UUID[:12], check.Equals, "zzzzz-ivpuk-")
54 c.Check(m.DeviceID, check.Equals, "mock-device-id")
55 c.Check(m.ReadOnly, check.Equals, false)
56 c.Check(m.Replication, check.Equals, 1)
57 c.Check(m.Tier, check.Equals, 1)
59 c.Check(mntList[0].UUID, check.Not(check.Equals), mntList[1].UUID)
62 for _, tok := range []string{"", "xyzzy"} {
63 resp = s.call("GET", "/mounts/"+mntList[1].UUID+"/blocks", tok)
64 c.Check(resp.Code, check.Equals, http.StatusUnauthorized)
65 c.Check(resp.Body.String(), check.Equals, "Unauthorized\n")
68 tok := arvadostest.DataManagerToken
70 // Nonexistent mount UUID
71 resp = s.call("GET", "/mounts/X/blocks", tok)
72 c.Check(resp.Code, check.Equals, http.StatusNotFound)
73 c.Check(resp.Body.String(), check.Equals, "mount not found\n")
75 // Complete index of first mount
76 resp = s.call("GET", "/mounts/"+mntList[0].UUID+"/blocks", tok)
77 c.Check(resp.Code, check.Equals, http.StatusOK)
78 c.Check(resp.Body.String(), check.Matches, TestHash+`\+[0-9]+ [0-9]+\n\n`)
80 // Partial index of first mount (one block matches prefix)
81 resp = s.call("GET", "/mounts/"+mntList[0].UUID+"/blocks?prefix="+TestHash[:2], tok)
82 c.Check(resp.Code, check.Equals, http.StatusOK)
83 c.Check(resp.Body.String(), check.Matches, TestHash+`\+[0-9]+ [0-9]+\n\n`)
85 // Complete index of second mount (note trailing slash)
86 resp = s.call("GET", "/mounts/"+mntList[1].UUID+"/blocks/", tok)
87 c.Check(resp.Code, check.Equals, http.StatusOK)
88 c.Check(resp.Body.String(), check.Matches, TestHash2+`\+[0-9]+ [0-9]+\n\n`)
90 // Partial index of second mount (no blocks match prefix)
91 resp = s.call("GET", "/mounts/"+mntList[1].UUID+"/blocks/?prefix="+TestHash[:2], tok)
92 c.Check(resp.Code, check.Equals, http.StatusOK)
93 c.Check(resp.Body.String(), check.Equals, "\n")
96 func (s *MountsSuite) call(method, path, tok string) *httptest.ResponseRecorder {
97 resp := httptest.NewRecorder()
98 req, _ := http.NewRequest(method, path, nil)
100 req.Header.Set("Authorization", "OAuth2 "+tok)
102 s.rtr.ServeHTTP(resp, req)