1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
12 "git.arvados.org/arvados.git/sdk/go/arvadosclient"
13 "git.arvados.org/arvados.git/sdk/go/arvadostest"
14 "git.arvados.org/arvados.git/sdk/go/keepclient"
15 check "gopkg.in/check.v1"
18 func (s *IntegrationSuite) TestRanges(c *check.C) {
22 testdata := make([]byte, blocksize)
23 for i := 0; i < blocksize; i++ {
24 testdata[i] = byte(' ')
26 copy(testdata[1:4], []byte("foo"))
27 arv, err := arvadosclient.MakeArvadosClient()
28 c.Assert(err, check.Equals, nil)
29 arv.ApiToken = arvadostest.ActiveToken
30 kc, err := keepclient.MakeKeepClient(arv)
31 c.Assert(err, check.Equals, nil)
32 loc, _, err := kc.PutB(testdata[:])
33 c.Assert(err, check.Equals, nil)
34 loc2, _, err := kc.PutB([]byte{'Z'})
35 c.Assert(err, check.Equals, nil)
37 mtext := fmt.Sprintf(". %s %s %s %s %s 1:%d:testdata.bin 0:1:space.txt\n", loc, loc, loc, loc, loc2, blocksize*4)
38 coll := map[string]interface{}{}
39 err = arv.Create("collections",
40 map[string]interface{}{
41 "collection": map[string]interface{}{
42 "name": "test data for keep-web TestRanges",
43 "manifest_text": mtext,
46 c.Assert(err, check.Equals, nil)
47 uuid = coll["uuid"].(string)
48 defer arv.Delete("collections", uuid, nil, nil)
51 url := mustParseURL("http://" + uuid + ".collections.example.com/testdata.bin")
52 for _, trial := range []struct {
61 {"1000000-1000003", true, "foo "},
62 {"999999-1000003", true, " foo "},
63 {"2000000-2000003", true, "foo "},
64 {"1999999-2000002", true, " foo"},
65 {"3999998-3999999", true, " Z"},
66 {"3999998-4000004", true, " Z"},
67 {"3999998-", true, " Z"},
69 c.Logf("trial: %#v", trial)
70 resp := httptest.NewRecorder()
75 RequestURI: url.RequestURI(),
77 "Authorization": {"OAuth2 " + arvadostest.ActiveToken},
78 "Range": {"bytes=" + trial.header},
81 s.handler.ServeHTTP(resp, req)
83 c.Check(resp.Code, check.Equals, http.StatusPartialContent)
84 c.Check(resp.Body.Len(), check.Equals, len(trial.expectBody))
85 if resp.Body.Len() > 1000 {
86 c.Check(resp.Body.String()[:1000]+"[...]", check.Equals, trial.expectBody)
88 c.Check(resp.Body.String(), check.Equals, trial.expectBody)
91 c.Check(resp.Code, check.Equals, http.StatusRequestedRangeNotSatisfiable)