|
1 | 1 | package rget |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/google/go-cmp/cmp" |
| 7 | +) |
| 8 | + |
| 9 | +func TestWrite(t *testing.T) { |
| 10 | +} |
| 11 | + |
| 12 | +func TestRun(t *testing.T) { |
| 13 | +} |
| 14 | + |
| 15 | +func TestContentLength(t *testing.T) { |
| 16 | +} |
| 17 | + |
| 18 | +func TestAcceptRangesHeaderCheck(t *testing.T) { |
| 19 | +} |
| 20 | + |
| 21 | +//func divide(contentLength int64, concurrency int) Units { |
| 22 | +func TestDivide(t *testing.T) { |
| 23 | + |
| 24 | + const ( |
| 25 | + url = "https://example.com/test.iso" |
| 26 | + contentLength = 5 |
| 27 | + ) |
| 28 | + |
| 29 | + testCases := []struct { |
| 30 | + caseName string |
| 31 | + concurrency uint |
| 32 | + expected Option |
| 33 | + }{ |
| 34 | + { |
| 35 | + caseName: "ContentLength:5/5", |
| 36 | + concurrency: 5, |
| 37 | + expected: Option{ |
| 38 | + URL: url, |
| 39 | + ContentLength: contentLength, |
| 40 | + Concurrency: 5, |
| 41 | + Units: []Unit{ |
| 42 | + {TempFileName: "0_test.iso", RangeStart: 0, RangeEnd: 0}, |
| 43 | + {TempFileName: "1_test.iso", RangeStart: 1, RangeEnd: 1}, |
| 44 | + {TempFileName: "2_test.iso", RangeStart: 2, RangeEnd: 2}, |
| 45 | + {TempFileName: "3_test.iso", RangeStart: 3, RangeEnd: 3}, |
| 46 | + {TempFileName: "4_test.iso", RangeStart: 4, RangeEnd: 4}, |
| 47 | + }, |
| 48 | + }, |
| 49 | + }, |
| 50 | + { |
| 51 | + caseName: "ContentLength:5/1", |
| 52 | + concurrency: 1, |
| 53 | + expected: Option{ |
| 54 | + URL: url, |
| 55 | + ContentLength: contentLength, |
| 56 | + Concurrency: 1, |
| 57 | + Units: []Unit{ |
| 58 | + {TempFileName: "0_test.iso", RangeStart: 0, RangeEnd: 4}, |
| 59 | + }, |
| 60 | + }, |
| 61 | + }, |
| 62 | + { |
| 63 | + caseName: "ContentLength:5/10", |
| 64 | + concurrency: 10, |
| 65 | + expected: Option{ |
| 66 | + URL: url, |
| 67 | + ContentLength: contentLength, |
| 68 | + Concurrency: 5, |
| 69 | + Units: []Unit{ |
| 70 | + {TempFileName: "0_test.iso", RangeStart: 0, RangeEnd: 0}, |
| 71 | + {TempFileName: "1_test.iso", RangeStart: 1, RangeEnd: 1}, |
| 72 | + {TempFileName: "2_test.iso", RangeStart: 2, RangeEnd: 2}, |
| 73 | + {TempFileName: "3_test.iso", RangeStart: 3, RangeEnd: 3}, |
| 74 | + {TempFileName: "4_test.iso", RangeStart: 4, RangeEnd: 4}, |
| 75 | + }, |
| 76 | + }, |
| 77 | + }, |
| 78 | + { |
| 79 | + caseName: "ContentLength:5/0", |
| 80 | + concurrency: 0, |
| 81 | + expected: Option{ |
| 82 | + URL: url, |
| 83 | + ContentLength: contentLength, |
| 84 | + Concurrency: 1, |
| 85 | + Units: []Unit{ |
| 86 | + {TempFileName: "0_test.iso", RangeStart: 0, RangeEnd: 4}, |
| 87 | + }, |
| 88 | + }, |
| 89 | + }, |
| 90 | + } |
| 91 | + |
| 92 | + for _, tc := range testCases { |
| 93 | + tc := tc |
| 94 | + t.Run(tc.caseName, func(t *testing.T) { |
| 95 | + t.Parallel() |
| 96 | + |
| 97 | + o := Option{URL: url, ContentLength: contentLength, Concurrency: tc.concurrency} |
| 98 | + o.divide() |
| 99 | + |
| 100 | + if !cmp.Equal(o, tc.expected) { |
| 101 | + t.Errorf("actual: %+v\nexpected: %+v\n", o, tc.expected) |
| 102 | + } |
| 103 | + |
| 104 | + }) |
| 105 | + } |
| 106 | +} |
| 107 | + |
| 108 | +func TestParallelDownload(t *testing.T) { |
| 109 | +} |
| 110 | + |
| 111 | +func TestDownloadWithContext(t *testing.T) { |
| 112 | +} |
| 113 | + |
| 114 | +func TestCombine(t *testing.T) { |
| 115 | +} |
0 commit comments