7 "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
8 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
9 "git.curoverse.com/arvados.git/sdk/go/streamer"
20 // Gocheck boilerplate
21 func Test(t *testing.T) {
25 // Gocheck boilerplate
26 var _ = Suite(&ServerRequiredSuite{})
27 var _ = Suite(&StandaloneSuite{})
29 var no_server = flag.Bool("no-server", false, "Skip 'ServerRequireSuite'")
31 // Tests that require the Keep server running
32 type ServerRequiredSuite struct{}
35 type StandaloneSuite struct{}
37 func pythonDir() string {
39 return fmt.Sprintf("%s/../../python/tests", cwd)
42 func (s *ServerRequiredSuite) SetUpSuite(c *C) {
44 c.Skip("Skipping tests that require server")
47 arvadostest.StartAPI()
48 arvadostest.StartKeep()
51 func (s *ServerRequiredSuite) TearDownSuite(c *C) {
55 arvadostest.StopKeep()
59 func (s *ServerRequiredSuite) TestMakeKeepClient(c *C) {
60 arv, err := arvadosclient.MakeArvadosClient()
61 c.Assert(err, Equals, nil)
63 kc, err := MakeKeepClient(&arv)
65 c.Assert(err, Equals, nil)
66 c.Check(len(kc.LocalRoots()), Equals, 2)
67 for _, root := range kc.LocalRoots() {
68 c.Check(root, Matches, "http://localhost:\\d+")
72 type StubPutHandler struct {
80 func (sph StubPutHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
81 sph.c.Check(req.URL.Path, Equals, "/"+sph.expectPath)
82 sph.c.Check(req.Header.Get("Authorization"), Equals, fmt.Sprintf("OAuth2 %s", sph.expectApiToken))
83 body, err := ioutil.ReadAll(req.Body)
84 sph.c.Check(err, Equals, nil)
85 sph.c.Check(body, DeepEquals, []byte(sph.expectBody))
87 sph.handled <- fmt.Sprintf("http://%s", req.Host)
90 func RunFakeKeepServer(st http.Handler) (ks KeepServer) {
92 ks.listener, err = net.ListenTCP("tcp", &net.TCPAddr{Port: 0})
94 panic(fmt.Sprintf("Could not listen on any port"))
96 ks.url = fmt.Sprintf("http://%s", ks.listener.Addr().String())
97 go http.Serve(ks.listener, st)
101 func UploadToStubHelper(c *C, st http.Handler, f func(*KeepClient, string,
102 io.ReadCloser, io.WriteCloser, chan uploadStatus)) {
104 ks := RunFakeKeepServer(st)
105 defer ks.listener.Close()
107 arv, _ := arvadosclient.MakeArvadosClient()
108 arv.ApiToken = "abc123"
110 kc, _ := MakeKeepClient(&arv)
112 reader, writer := io.Pipe()
113 upload_status := make(chan uploadStatus)
115 f(kc, ks.url, reader, writer, upload_status)
118 func (s *StandaloneSuite) TestUploadToStubKeepServer(c *C) {
119 log.Printf("TestUploadToStubKeepServer")
121 st := StubPutHandler{
123 "acbd18db4cc2f85cedef654fccc4a4d8",
128 UploadToStubHelper(c, st,
129 func(kc *KeepClient, url string, reader io.ReadCloser,
130 writer io.WriteCloser, upload_status chan uploadStatus) {
132 go kc.uploadToKeepServer(url, st.expectPath, reader, upload_status, int64(len("foo")), "TestUploadToStubKeepServer")
134 writer.Write([]byte("foo"))
138 status := <-upload_status
139 c.Check(status, DeepEquals, uploadStatus{nil, fmt.Sprintf("%s/%s", url, st.expectPath), 200, 1, ""})
142 log.Printf("TestUploadToStubKeepServer done")
145 func (s *StandaloneSuite) TestUploadToStubKeepServerBufferReader(c *C) {
146 log.Printf("TestUploadToStubKeepServerBufferReader")
148 st := StubPutHandler{
150 "acbd18db4cc2f85cedef654fccc4a4d8",
155 UploadToStubHelper(c, st,
156 func(kc *KeepClient, url string, reader io.ReadCloser,
157 writer io.WriteCloser, upload_status chan uploadStatus) {
159 tr := streamer.AsyncStreamFromReader(512, reader)
162 br1 := tr.MakeStreamReader()
164 go kc.uploadToKeepServer(url, st.expectPath, br1, upload_status, 3, "TestUploadToStubKeepServerBufferReader")
166 writer.Write([]byte("foo"))
171 status := <-upload_status
172 c.Check(status, DeepEquals, uploadStatus{nil, fmt.Sprintf("%s/%s", url, st.expectPath), 200, 1, ""})
175 log.Printf("TestUploadToStubKeepServerBufferReader done")
178 type FailHandler struct {
182 func (fh FailHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
183 resp.WriteHeader(500)
184 fh.handled <- fmt.Sprintf("http://%s", req.Host)
187 func (s *StandaloneSuite) TestFailedUploadToStubKeepServer(c *C) {
188 log.Printf("TestFailedUploadToStubKeepServer")
193 hash := "acbd18db4cc2f85cedef654fccc4a4d8"
195 UploadToStubHelper(c, st,
196 func(kc *KeepClient, url string, reader io.ReadCloser,
197 writer io.WriteCloser, upload_status chan uploadStatus) {
199 go kc.uploadToKeepServer(url, hash, reader, upload_status, 3, "TestFailedUploadToStubKeepServer")
201 writer.Write([]byte("foo"))
206 status := <-upload_status
207 c.Check(status.url, Equals, fmt.Sprintf("%s/%s", url, hash))
208 c.Check(status.statusCode, Equals, 500)
210 log.Printf("TestFailedUploadToStubKeepServer done")
213 type KeepServer struct {
214 listener net.Listener
218 func RunSomeFakeKeepServers(st http.Handler, n int) (ks []KeepServer) {
219 ks = make([]KeepServer, n)
221 for i := 0; i < n; i += 1 {
222 ks[i] = RunFakeKeepServer(st)
228 func (s *StandaloneSuite) TestPutB(c *C) {
229 log.Printf("TestPutB")
231 hash := Md5String("foo")
233 st := StubPutHandler{
238 make(chan string, 5)}
240 arv, _ := arvadosclient.MakeArvadosClient()
241 kc, _ := MakeKeepClient(&arv)
244 arv.ApiToken = "abc123"
245 localRoots := make(map[string]string)
247 ks := RunSomeFakeKeepServers(st, 5)
249 for i, k := range ks {
250 localRoots[fmt.Sprintf("zzzzz-bi6l4-fakefakefake%03d", i)] = k.url
251 defer k.listener.Close()
254 kc.SetServiceRoots(localRoots, nil)
256 kc.PutB([]byte("foo"))
258 shuff := NewRootSorter(
259 kc.LocalRoots(), Md5String("foo")).GetSortedRoots()
263 c.Check((s1 == shuff[0] && s2 == shuff[1]) ||
264 (s1 == shuff[1] && s2 == shuff[0]),
268 log.Printf("TestPutB done")
271 func (s *StandaloneSuite) TestPutHR(c *C) {
272 log.Printf("TestPutHR")
274 hash := fmt.Sprintf("%x", md5.Sum([]byte("foo")))
276 st := StubPutHandler{
281 make(chan string, 5)}
283 arv, _ := arvadosclient.MakeArvadosClient()
284 kc, _ := MakeKeepClient(&arv)
287 arv.ApiToken = "abc123"
288 localRoots := make(map[string]string)
290 ks := RunSomeFakeKeepServers(st, 5)
292 for i, k := range ks {
293 localRoots[fmt.Sprintf("zzzzz-bi6l4-fakefakefake%03d", i)] = k.url
294 defer k.listener.Close()
297 kc.SetServiceRoots(localRoots, nil)
299 reader, writer := io.Pipe()
302 writer.Write([]byte("foo"))
306 kc.PutHR(hash, reader, 3)
308 shuff := NewRootSorter(kc.LocalRoots(), hash).GetSortedRoots()
314 c.Check((s1 == shuff[0] && s2 == shuff[1]) ||
315 (s1 == shuff[1] && s2 == shuff[0]),
319 log.Printf("TestPutHR done")
322 func (s *StandaloneSuite) TestPutWithFail(c *C) {
323 log.Printf("TestPutWithFail")
325 hash := fmt.Sprintf("%x", md5.Sum([]byte("foo")))
327 st := StubPutHandler{
332 make(chan string, 4)}
335 make(chan string, 1)}
337 arv, err := arvadosclient.MakeArvadosClient()
338 kc, _ := MakeKeepClient(&arv)
341 arv.ApiToken = "abc123"
342 localRoots := make(map[string]string)
344 ks1 := RunSomeFakeKeepServers(st, 4)
345 ks2 := RunSomeFakeKeepServers(fh, 1)
347 for i, k := range ks1 {
348 localRoots[fmt.Sprintf("zzzzz-bi6l4-fakefakefake%03d", i)] = k.url
349 defer k.listener.Close()
351 for i, k := range ks2 {
352 localRoots[fmt.Sprintf("zzzzz-bi6l4-fakefakefake%03d", i+len(ks1))] = k.url
353 defer k.listener.Close()
356 kc.SetServiceRoots(localRoots, nil)
358 shuff := NewRootSorter(
359 kc.LocalRoots(), Md5String("foo")).GetSortedRoots()
361 phash, replicas, err := kc.PutB([]byte("foo"))
365 c.Check(err, Equals, nil)
366 c.Check(phash, Equals, "")
367 c.Check(replicas, Equals, 2)
372 c.Check((s1 == shuff[1] && s2 == shuff[2]) ||
373 (s1 == shuff[2] && s2 == shuff[1]),
378 func (s *StandaloneSuite) TestPutWithTooManyFail(c *C) {
379 log.Printf("TestPutWithTooManyFail")
381 hash := fmt.Sprintf("%x", md5.Sum([]byte("foo")))
383 st := StubPutHandler{
388 make(chan string, 1)}
391 make(chan string, 4)}
393 arv, err := arvadosclient.MakeArvadosClient()
394 kc, _ := MakeKeepClient(&arv)
397 arv.ApiToken = "abc123"
398 localRoots := make(map[string]string)
400 ks1 := RunSomeFakeKeepServers(st, 1)
401 ks2 := RunSomeFakeKeepServers(fh, 4)
403 for i, k := range ks1 {
404 localRoots[fmt.Sprintf("zzzzz-bi6l4-fakefakefake%03d", i)] = k.url
405 defer k.listener.Close()
407 for i, k := range ks2 {
408 localRoots[fmt.Sprintf("zzzzz-bi6l4-fakefakefake%03d", i+len(ks1))] = k.url
409 defer k.listener.Close()
412 kc.SetServiceRoots(localRoots, nil)
414 _, replicas, err := kc.PutB([]byte("foo"))
416 c.Check(err, Equals, InsufficientReplicasError)
417 c.Check(replicas, Equals, 1)
418 c.Check(<-st.handled, Equals, ks1[0].url)
420 log.Printf("TestPutWithTooManyFail done")
423 type StubGetHandler struct {
426 expectApiToken string
431 func (sgh StubGetHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
432 sgh.c.Check(req.URL.Path, Equals, "/"+sgh.expectPath)
433 sgh.c.Check(req.Header.Get("Authorization"), Equals, fmt.Sprintf("OAuth2 %s", sgh.expectApiToken))
434 resp.WriteHeader(sgh.httpStatus)
435 resp.Header().Set("Content-Length", fmt.Sprintf("%d", len(sgh.body)))
439 func (s *StandaloneSuite) TestGet(c *C) {
440 log.Printf("TestGet")
442 hash := fmt.Sprintf("%x", md5.Sum([]byte("foo")))
444 st := StubGetHandler{
451 ks := RunFakeKeepServer(st)
452 defer ks.listener.Close()
454 arv, err := arvadosclient.MakeArvadosClient()
455 kc, _ := MakeKeepClient(&arv)
456 arv.ApiToken = "abc123"
457 kc.SetServiceRoots(map[string]string{"x": ks.url}, nil)
459 r, n, url2, err := kc.Get(hash)
461 c.Check(err, Equals, nil)
462 c.Check(n, Equals, int64(3))
463 c.Check(url2, Equals, fmt.Sprintf("%s/%s", ks.url, hash))
465 content, err2 := ioutil.ReadAll(r)
466 c.Check(err2, Equals, nil)
467 c.Check(content, DeepEquals, []byte("foo"))
469 log.Printf("TestGet done")
472 func (s *StandaloneSuite) TestGetFail(c *C) {
473 hash := fmt.Sprintf("%x", md5.Sum([]byte("foo")))
475 st := FailHandler{make(chan string, 1)}
477 ks := RunFakeKeepServer(st)
478 defer ks.listener.Close()
480 arv, err := arvadosclient.MakeArvadosClient()
481 kc, _ := MakeKeepClient(&arv)
482 arv.ApiToken = "abc123"
483 kc.SetServiceRoots(map[string]string{"x": ks.url}, nil)
485 r, n, url2, err := kc.Get(hash)
486 c.Check(err, Equals, BlockNotFound)
487 c.Check(n, Equals, int64(0))
488 c.Check(url2, Equals, "")
489 c.Check(r, Equals, nil)
492 func (s *StandaloneSuite) TestGetWithServiceHint(c *C) {
493 uuid := "zzzzz-bi6l4-123451234512345"
494 hash := fmt.Sprintf("%x", md5.Sum([]byte("foo")))
496 // This one shouldn't be used:
497 ks0 := RunFakeKeepServer(StubGetHandler{
503 defer ks0.listener.Close()
504 // This one should be used:
505 ks := RunFakeKeepServer(StubGetHandler{
511 defer ks.listener.Close()
513 arv, err := arvadosclient.MakeArvadosClient()
514 kc, _ := MakeKeepClient(&arv)
515 arv.ApiToken = "abc123"
517 map[string]string{"x": ks0.url},
518 map[string]string{uuid: ks.url})
520 r, n, uri, err := kc.Get(hash + "+K@" + uuid)
522 c.Check(err, Equals, nil)
523 c.Check(n, Equals, int64(3))
524 c.Check(uri, Equals, fmt.Sprintf("%s/%s", ks.url, hash+"+K@"+uuid))
526 content, err := ioutil.ReadAll(r)
527 c.Check(err, Equals, nil)
528 c.Check(content, DeepEquals, []byte("foo"))
531 // Use a service hint to fetch from a local disk service, overriding
532 // rendezvous probe order.
533 func (s *StandaloneSuite) TestGetWithLocalServiceHint(c *C) {
534 uuid := "zzzzz-bi6l4-zzzzzzzzzzzzzzz"
535 hash := fmt.Sprintf("%x", md5.Sum([]byte("foo")))
537 // This one shouldn't be used, although it appears first in
538 // rendezvous probe order:
539 ks0 := RunFakeKeepServer(StubGetHandler{
545 defer ks0.listener.Close()
546 // This one should be used:
547 ks := RunFakeKeepServer(StubGetHandler{
553 defer ks.listener.Close()
555 arv, err := arvadosclient.MakeArvadosClient()
556 kc, _ := MakeKeepClient(&arv)
557 arv.ApiToken = "abc123"
560 "zzzzz-bi6l4-yyyyyyyyyyyyyyy": ks0.url,
561 "zzzzz-bi6l4-xxxxxxxxxxxxxxx": ks0.url,
562 "zzzzz-bi6l4-wwwwwwwwwwwwwww": ks0.url,
565 "zzzzz-bi6l4-yyyyyyyyyyyyyyy": ks0.url,
566 "zzzzz-bi6l4-xxxxxxxxxxxxxxx": ks0.url,
567 "zzzzz-bi6l4-wwwwwwwwwwwwwww": ks0.url,
571 r, n, uri, err := kc.Get(hash + "+K@" + uuid)
573 c.Check(err, Equals, nil)
574 c.Check(n, Equals, int64(3))
575 c.Check(uri, Equals, fmt.Sprintf("%s/%s", ks.url, hash+"+K@"+uuid))
577 content, err := ioutil.ReadAll(r)
578 c.Check(err, Equals, nil)
579 c.Check(content, DeepEquals, []byte("foo"))
582 func (s *StandaloneSuite) TestGetWithServiceHintFailoverToLocals(c *C) {
583 uuid := "zzzzz-bi6l4-123451234512345"
584 hash := fmt.Sprintf("%x", md5.Sum([]byte("foo")))
586 ksLocal := RunFakeKeepServer(StubGetHandler{
592 defer ksLocal.listener.Close()
593 ksGateway := RunFakeKeepServer(StubGetHandler{
597 http.StatusInternalServerError,
599 defer ksGateway.listener.Close()
601 arv, err := arvadosclient.MakeArvadosClient()
602 kc, _ := MakeKeepClient(&arv)
603 arv.ApiToken = "abc123"
605 map[string]string{"zzzzz-bi6l4-keepdisk0000000": ksLocal.url},
606 map[string]string{uuid: ksGateway.url})
608 r, n, uri, err := kc.Get(hash + "+K@" + uuid)
609 c.Assert(err, Equals, nil)
611 c.Check(n, Equals, int64(3))
612 c.Check(uri, Equals, fmt.Sprintf("%s/%s", ksLocal.url, hash+"+K@"+uuid))
614 content, err := ioutil.ReadAll(r)
615 c.Check(err, Equals, nil)
616 c.Check(content, DeepEquals, []byte("foo"))
619 type BarHandler struct {
623 func (this BarHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
624 resp.Write([]byte("bar"))
625 this.handled <- fmt.Sprintf("http://%s", req.Host)
628 func (s *StandaloneSuite) TestChecksum(c *C) {
629 foohash := fmt.Sprintf("%x", md5.Sum([]byte("foo")))
630 barhash := fmt.Sprintf("%x", md5.Sum([]byte("bar")))
632 st := BarHandler{make(chan string, 1)}
634 ks := RunFakeKeepServer(st)
635 defer ks.listener.Close()
637 arv, err := arvadosclient.MakeArvadosClient()
638 kc, _ := MakeKeepClient(&arv)
639 arv.ApiToken = "abc123"
640 kc.SetServiceRoots(map[string]string{"x": ks.url}, nil)
642 r, n, _, err := kc.Get(barhash)
643 _, err = ioutil.ReadAll(r)
644 c.Check(n, Equals, int64(3))
645 c.Check(err, Equals, nil)
649 r, n, _, err = kc.Get(foohash)
650 _, err = ioutil.ReadAll(r)
651 c.Check(n, Equals, int64(3))
652 c.Check(err, Equals, BadChecksum)
657 func (s *StandaloneSuite) TestGetWithFailures(c *C) {
658 content := []byte("waz")
659 hash := fmt.Sprintf("%x", md5.Sum(content))
662 make(chan string, 4)}
664 st := StubGetHandler{
671 arv, err := arvadosclient.MakeArvadosClient()
672 kc, _ := MakeKeepClient(&arv)
673 arv.ApiToken = "abc123"
674 localRoots := make(map[string]string)
676 ks1 := RunSomeFakeKeepServers(st, 1)
677 ks2 := RunSomeFakeKeepServers(fh, 4)
679 for i, k := range ks1 {
680 localRoots[fmt.Sprintf("zzzzz-bi6l4-fakefakefake%03d", i)] = k.url
681 defer k.listener.Close()
683 for i, k := range ks2 {
684 localRoots[fmt.Sprintf("zzzzz-bi6l4-fakefakefake%03d", i+len(ks1))] = k.url
685 defer k.listener.Close()
688 kc.SetServiceRoots(localRoots, nil)
690 // This test works only if one of the failing services is
691 // attempted before the succeeding service. Otherwise,
692 // <-fh.handled below will just hang! (Probe order depends on
693 // the choice of block content "waz" and the UUIDs of the fake
694 // servers, so we just tried different strings until we found
695 // an example that passes this Assert.)
696 c.Assert(NewRootSorter(localRoots, hash).GetSortedRoots()[0], Not(Equals), ks1[0].url)
698 r, n, url2, err := kc.Get(hash)
701 c.Check(err, Equals, nil)
702 c.Check(n, Equals, int64(3))
703 c.Check(url2, Equals, fmt.Sprintf("%s/%s", ks1[0].url, hash))
705 read_content, err2 := ioutil.ReadAll(r)
706 c.Check(err2, Equals, nil)
707 c.Check(read_content, DeepEquals, content)
710 func (s *ServerRequiredSuite) TestPutGetHead(c *C) {
711 content := []byte("TestPutGetHead")
713 arv, err := arvadosclient.MakeArvadosClient()
714 kc, err := MakeKeepClient(&arv)
715 c.Assert(err, Equals, nil)
717 hash := fmt.Sprintf("%x", md5.Sum(content))
720 n, _, err := kc.Ask(hash)
721 c.Check(err, Equals, BlockNotFound)
722 c.Check(n, Equals, int64(0))
725 hash2, replicas, err := kc.PutB(content)
726 c.Check(hash2, Equals, fmt.Sprintf("%s+%d", hash, len(content)))
727 c.Check(replicas, Equals, 2)
728 c.Check(err, Equals, nil)
731 r, n, url2, err := kc.Get(hash)
732 c.Check(err, Equals, nil)
733 c.Check(n, Equals, int64(len(content)))
734 c.Check(url2, Matches, fmt.Sprintf("http://localhost:\\d+/%s", hash))
736 read_content, err2 := ioutil.ReadAll(r)
737 c.Check(err2, Equals, nil)
738 c.Check(read_content, DeepEquals, content)
741 n, url2, err := kc.Ask(hash)
742 c.Check(err, Equals, nil)
743 c.Check(n, Equals, int64(len(content)))
744 c.Check(url2, Matches, fmt.Sprintf("http://localhost:\\d+/%s", hash))
748 type StubProxyHandler struct {
752 func (this StubProxyHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
753 resp.Header().Set("X-Keep-Replicas-Stored", "2")
754 this.handled <- fmt.Sprintf("http://%s", req.Host)
757 func (s *StandaloneSuite) TestPutProxy(c *C) {
758 log.Printf("TestPutProxy")
760 st := StubProxyHandler{make(chan string, 1)}
762 arv, err := arvadosclient.MakeArvadosClient()
763 kc, _ := MakeKeepClient(&arv)
766 kc.Using_proxy = true
767 arv.ApiToken = "abc123"
768 localRoots := make(map[string]string)
770 ks1 := RunSomeFakeKeepServers(st, 1)
772 for i, k := range ks1 {
773 localRoots[fmt.Sprintf("zzzzz-bi6l4-fakefakefake%03d", i)] = k.url
774 defer k.listener.Close()
777 kc.SetServiceRoots(localRoots, nil)
779 _, replicas, err := kc.PutB([]byte("foo"))
782 c.Check(err, Equals, nil)
783 c.Check(replicas, Equals, 2)
785 log.Printf("TestPutProxy done")
788 func (s *StandaloneSuite) TestPutProxyInsufficientReplicas(c *C) {
789 log.Printf("TestPutProxy")
791 st := StubProxyHandler{make(chan string, 1)}
793 arv, err := arvadosclient.MakeArvadosClient()
794 kc, _ := MakeKeepClient(&arv)
797 kc.Using_proxy = true
798 arv.ApiToken = "abc123"
799 localRoots := make(map[string]string)
801 ks1 := RunSomeFakeKeepServers(st, 1)
803 for i, k := range ks1 {
804 localRoots[fmt.Sprintf("zzzzz-bi6l4-fakefakefake%03d", i)] = k.url
805 defer k.listener.Close()
807 kc.SetServiceRoots(localRoots, nil)
809 _, replicas, err := kc.PutB([]byte("foo"))
812 c.Check(err, Equals, InsufficientReplicasError)
813 c.Check(replicas, Equals, 2)
815 log.Printf("TestPutProxy done")
818 func (s *StandaloneSuite) TestMakeLocator(c *C) {
819 l, err := MakeLocator("91f372a266fe2bf2823cb8ec7fda31ce+3+Aabcde@12345678")
820 c.Check(err, Equals, nil)
821 c.Check(l.Hash, Equals, "91f372a266fe2bf2823cb8ec7fda31ce")
822 c.Check(l.Size, Equals, 3)
823 c.Check(l.Hints, DeepEquals, []string{"3", "Aabcde@12345678"})
826 func (s *StandaloneSuite) TestMakeLocatorNoHints(c *C) {
827 l, err := MakeLocator("91f372a266fe2bf2823cb8ec7fda31ce")
828 c.Check(err, Equals, nil)
829 c.Check(l.Hash, Equals, "91f372a266fe2bf2823cb8ec7fda31ce")
830 c.Check(l.Size, Equals, -1)
831 c.Check(l.Hints, DeepEquals, []string{})
834 func (s *StandaloneSuite) TestMakeLocatorNoSizeHint(c *C) {
835 l, err := MakeLocator("91f372a266fe2bf2823cb8ec7fda31ce+Aabcde@12345678")
836 c.Check(err, Equals, nil)
837 c.Check(l.Hash, Equals, "91f372a266fe2bf2823cb8ec7fda31ce")
838 c.Check(l.Size, Equals, -1)
839 c.Check(l.Hints, DeepEquals, []string{"Aabcde@12345678"})
842 func (s *StandaloneSuite) TestMakeLocatorPreservesUnrecognizedHints(c *C) {
843 str := "91f372a266fe2bf2823cb8ec7fda31ce+3+Unknown+Kzzzzz+Afoobar"
844 l, err := MakeLocator(str)
845 c.Check(err, Equals, nil)
846 c.Check(l.Hash, Equals, "91f372a266fe2bf2823cb8ec7fda31ce")
847 c.Check(l.Size, Equals, 3)
848 c.Check(l.Hints, DeepEquals, []string{"3", "Unknown", "Kzzzzz", "Afoobar"})
849 c.Check(l.String(), Equals, str)
852 func (s *StandaloneSuite) TestMakeLocatorInvalidInput(c *C) {
853 _, err := MakeLocator("91f372a266fe2bf2823cb8ec7fda31c")
854 c.Check(err, Equals, InvalidLocatorError)