(c *C)
| 31 | } |
| 32 | |
| 33 | func (s *CompressionSuite) TestDownloadTryCompression(c *C) { |
| 34 | var buf []byte |
| 35 | |
| 36 | expectedChecksums := map[string]utils.ChecksumInfo{ |
| 37 | "file.bz2": {Size: int64(len(bzipData))}, |
| 38 | "file.gz": {Size: int64(len(gzipData))}, |
| 39 | "file.xz": {Size: int64(len(xzData))}, |
| 40 | "file": {Size: int64(len(rawData))}, |
| 41 | } |
| 42 | |
| 43 | // bzip2 only available |
| 44 | buf = make([]byte, 4) |
| 45 | d := NewFakeDownloader() |
| 46 | d.ExpectResponse("http://example.com/file.bz2", bzipData) |
| 47 | r, file, err := DownloadTryCompression(s.ctx, d, s.baseURL, "file", expectedChecksums, false) |
| 48 | c.Assert(err, IsNil) |
| 49 | defer func() { |
| 50 | _ = file.Close() |
| 51 | }() |
| 52 | _, _ = io.ReadFull(r, buf) |
| 53 | c.Assert(string(buf), Equals, rawData) |
| 54 | c.Assert(d.Empty(), Equals, true) |
| 55 | |
| 56 | // bzip2 not available, but gz is |
| 57 | buf = make([]byte, 4) |
| 58 | d = NewFakeDownloader() |
| 59 | d.ExpectError("http://example.com/file.bz2", &Error{Code: 404}) |
| 60 | d.ExpectResponse("http://example.com/file.gz", gzipData) |
| 61 | r, file, err = DownloadTryCompression(s.ctx, d, s.baseURL, "file", expectedChecksums, false) |
| 62 | c.Assert(err, IsNil) |
| 63 | defer func() { |
| 64 | _ = file.Close() |
| 65 | }() |
| 66 | _, _ = io.ReadFull(r, buf) |
| 67 | c.Assert(string(buf), Equals, rawData) |
| 68 | c.Assert(d.Empty(), Equals, true) |
| 69 | |
| 70 | // bzip2 & gzip not available, but xz is |
| 71 | buf = make([]byte, 4) |
| 72 | d = NewFakeDownloader() |
| 73 | d.ExpectError("http://example.com/file.bz2", &Error{Code: 404}) |
| 74 | d.ExpectError("http://example.com/file.gz", &Error{Code: 404}) |
| 75 | d.ExpectResponse("http://example.com/file.xz", xzData) |
| 76 | r, file, err = DownloadTryCompression(s.ctx, d, s.baseURL, "file", expectedChecksums, false) |
| 77 | c.Assert(err, IsNil) |
| 78 | defer func() { |
| 79 | _ = file.Close() |
| 80 | }() |
| 81 | _, _ = io.ReadFull(r, buf) |
| 82 | c.Assert(string(buf), Equals, rawData) |
| 83 | c.Assert(d.Empty(), Equals, true) |
| 84 | |
| 85 | // bzip2, gzip & xz not available, but raw is |
| 86 | buf = make([]byte, 4) |
| 87 | d = NewFakeDownloader() |
| 88 | d.ExpectError("http://example.com/file.bz2", &Error{Code: 404}) |
| 89 | d.ExpectError("http://example.com/file.gz", &Error{Code: 404}) |
| 90 | d.ExpectError("http://example.com/file.xz", &Error{Code: 404}) |
nothing calls this directly
no test coverage detected