(t *testing.T)
| 27 | } |
| 28 | |
| 29 | func TestDownloadOrder(t *testing.T) { |
| 30 | buff := []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15} |
| 31 | downloader, invocations, ranges := newDownloadRangeClient(buff) |
| 32 | con, partSize := 3, 3 |
| 33 | d := NewDownloader(func(d *Downloader) { |
| 34 | d.Concurrency = con |
| 35 | d.PartSize = partSize |
| 36 | d.HttpClient = downloader.HttpRequest |
| 37 | }) |
| 38 | |
| 39 | var start, length int64 = 2, 10 |
| 40 | length2 := length |
| 41 | if length2 == -1 { |
| 42 | length2 = int64(len(buff)) - start |
| 43 | } |
| 44 | req := &HttpRequestParams{ |
| 45 | Range: http_range.Range{Start: start, Length: length}, |
| 46 | Size: int64(len(buff)), |
| 47 | } |
| 48 | readCloser, err := d.Download(context.Background(), req) |
| 49 | |
| 50 | if err != nil { |
| 51 | t.Fatalf("expect no error, got %v", err) |
| 52 | } |
| 53 | resultBuf, err := io.ReadAll(readCloser) |
| 54 | if err != nil { |
| 55 | t.Fatalf("expect no error, got %v", err) |
| 56 | } |
| 57 | if exp, a := buff[start:start+length2], resultBuf; !bytes.Equal(exp, a) { |
| 58 | t.Errorf("expect buffer %v, got %v", exp, a) |
| 59 | } |
| 60 | chunkSize := int(length+int64(partSize)-1) / partSize |
| 61 | if e, a := chunkSize, *invocations; e != a { |
| 62 | t.Errorf("expect %v API calls, got %v", e, a) |
| 63 | } |
| 64 | |
| 65 | expectRngs := []string{"2-1", "6-3", "3-3", "9-3"} |
| 66 | for _, rng := range expectRngs { |
| 67 | if !containsString(*ranges, rng) { |
| 68 | t.Errorf("expect range %v, but absent in return", rng) |
| 69 | } |
| 70 | } |
| 71 | if e, a := expectRngs, *ranges; len(e) != len(a) { |
| 72 | t.Errorf("expect %v ranges, got %v", e, a) |
| 73 | } |
| 74 | if err := readCloser.Close(); err != nil { |
| 75 | t.Errorf("expect no error on close, got %v", err) |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | func TestDownloadInterrupt(t *testing.T) { |
| 80 | buff := []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15} |
nothing calls this directly
no test coverage detected