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 {
44 err := json.Unmarshal(resp.Body.Bytes(), &mntList)
45 c.Check(err, check.IsNil)
46 c.Check(len(mntList), check.Equals, 2)
49 for _, tok := range []string{"", "xyzzy"} {
50 resp = s.call("GET", "/mounts/"+mntList[1].UUID+"/blocks", tok)
51 c.Check(resp.Code, check.Equals, http.StatusUnauthorized)
52 c.Check(resp.Body.String(), check.Equals, "Unauthorized\n")
55 tok := arvadostest.DataManagerToken
57 // Nonexistent mount UUID
58 resp = s.call("GET", "/mounts/X/blocks", tok)
59 c.Check(resp.Code, check.Equals, http.StatusNotFound)
60 c.Check(resp.Body.String(), check.Equals, "mount not found\n")
62 // Complete index of first mount
63 resp = s.call("GET", "/mounts/"+mntList[0].UUID+"/blocks", tok)
64 c.Check(resp.Code, check.Equals, http.StatusOK)
65 c.Check(resp.Body.String(), check.Matches, TestHash+`\+[0-9]+ [0-9]+\n\n`)
67 // Partial index of first mount (one block matches prefix)
68 resp = s.call("GET", "/mounts/"+mntList[0].UUID+"/blocks/"+TestHash[:2], tok)
69 c.Check(resp.Code, check.Equals, http.StatusOK)
70 c.Check(resp.Body.String(), check.Matches, TestHash+`\+[0-9]+ [0-9]+\n\n`)
72 // Complete index of second mount (note trailing slash)
73 resp = s.call("GET", "/mounts/"+mntList[1].UUID+"/blocks/", tok)
74 c.Check(resp.Code, check.Equals, http.StatusOK)
75 c.Check(resp.Body.String(), check.Matches, TestHash2+`\+[0-9]+ [0-9]+\n\n`)
77 // Partial index of second mount (no blocks match prefix)
78 resp = s.call("GET", "/mounts/"+mntList[1].UUID+"/blocks/"+TestHash[:2], tok)
79 c.Check(resp.Code, check.Equals, http.StatusOK)
80 c.Check(resp.Body.String(), check.Equals, "\n")
83 func (s *MountsSuite) call(method, path, tok string) *httptest.ResponseRecorder {
84 resp := httptest.NewRecorder()
85 req, _ := http.NewRequest(method, path, nil)
87 req.Header.Set("Authorization", "OAuth2 "+tok)
89 s.rtr.ServeHTTP(resp, req)