8 "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
9 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
10 "git.curoverse.com/arvados.git/sdk/go/keepclient"
11 check "gopkg.in/check.v1"
14 func (s *IntegrationSuite) TestRanges(c *check.C) {
18 testdata := make([]byte, blocksize)
19 for i := 0; i < blocksize; i++ {
20 testdata[i] = byte(' ')
22 copy(testdata[1:4], []byte("foo"))
23 arv, err := arvadosclient.MakeArvadosClient()
24 c.Assert(err, check.Equals, nil)
25 arv.ApiToken = arvadostest.ActiveToken
26 kc, err := keepclient.MakeKeepClient(arv)
27 c.Assert(err, check.Equals, nil)
28 loc, _, err := kc.PutB(testdata[:])
29 c.Assert(err, check.Equals, nil)
30 loc2, _, err := kc.PutB([]byte{'Z'})
31 c.Assert(err, check.Equals, nil)
33 mtext := fmt.Sprintf(". %s %s %s %s %s 1:%d:testdata.bin 0:1:space.txt\n", loc, loc, loc, loc, loc2, blocksize*4)
34 coll := map[string]interface{}{}
35 err = arv.Create("collections",
36 map[string]interface{}{
37 "collection": map[string]interface{}{
38 "name": "test data for keep-web TestRanges",
39 "manifest_text": mtext,
42 c.Assert(err, check.Equals, nil)
43 uuid = coll["uuid"].(string)
44 defer arv.Delete("collections", uuid, nil, nil)
47 url := mustParseURL("http://" + uuid + ".collections.example.com/testdata.bin")
48 for _, trial := range []struct {
57 {"1000000-1000003", true, "foo "},
58 {"999999-1000003", true, " foo "},
59 {"2000000-2000003", true, "foo "},
60 {"1999999-2000002", true, " foo"},
61 {"3999998-3999999", true, " Z"},
62 {"3999998-4000004", true, " Z"},
63 {"3999998-", true, " Z"},
65 c.Logf("trial: %#v", trial)
66 resp := httptest.NewRecorder()
71 RequestURI: url.RequestURI(),
73 "Authorization": {"OAuth2 " + arvadostest.ActiveToken},
74 "Range": {"bytes=" + trial.header},
77 s.testServer.Handler.ServeHTTP(resp, req)
79 c.Check(resp.Code, check.Equals, http.StatusPartialContent)
80 c.Check(resp.Body.Len(), check.Equals, len(trial.expectBody))
81 if resp.Body.Len() > 1000 {
82 c.Check(resp.Body.String()[:1000]+"[...]", check.Equals, trial.expectBody)
84 c.Check(resp.Body.String(), check.Equals, trial.expectBody)
87 c.Check(resp.Code, check.Equals, http.StatusRequestedRangeNotSatisfiable)