(t *testing.T)
| 13 | ) |
| 14 | |
| 15 | func TestGzipStream(t *testing.T) { |
| 16 | genfile := func(wpipe io.WriteCloser) { |
| 17 | defer wpipe.Close() |
| 18 | w := gzip.NewWriter(wpipe) |
| 19 | defer w.Close() |
| 20 | |
| 21 | for i := 0; i < 30; i++ { |
| 22 | line := bytes.Repeat([]byte{'a'}, 15*1024) |
| 23 | line = append(line, '\n') |
| 24 | w.Write(line) |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | lastModified := time.Unix(1234, 5678) |
| 29 | opener := func(fn string) (io.ReadCloser, int64, time.Time, *url.URL, error) { |
| 30 | if fn != "pipe" { |
| 31 | panic(fn) |
| 32 | } |
| 33 | rpipe, wpipe := io.Pipe() |
| 34 | go genfile(wpipe) |
| 35 | url := &url.URL{ |
| 36 | Scheme: "pipe", |
| 37 | Path: "/fake"} |
| 38 | return rpipe, 0, lastModified, url, nil |
| 39 | } |
| 40 | |
| 41 | sizer := func(fn string) (int64, error) { |
| 42 | return 0, nil |
| 43 | } |
| 44 | |
| 45 | numlines := 0 |
| 46 | data := make(chan *baker.Data) |
| 47 | |
| 48 | var wg sync.WaitGroup |
| 49 | wg.Add(1) |
| 50 | go func() { |
| 51 | for linesData := range data { |
| 52 | cnt := bytes.Count(linesData.Bytes, []byte{'\n'}) |
| 53 | numlines += cnt |
| 54 | |
| 55 | lastModifiedMeta, ok := linesData.Meta[MetadataLastModified] |
| 56 | if !ok { |
| 57 | t.Errorf("last modified metadata is unavailable") |
| 58 | } |
| 59 | |
| 60 | if lastModifiedMeta != lastModified { |
| 61 | t.Errorf( |
| 62 | "invalid last modified in metadata want:%s got:%s", |
| 63 | lastModified, |
| 64 | lastModifiedMeta, |
| 65 | ) |
| 66 | } |
| 67 | |
| 68 | URLMeta, ok := linesData.Meta[MetadataURL] |
| 69 | if !ok { |
| 70 | t.Errorf("url metadata is unavailable") |
| 71 | } |
| 72 | if URLMeta == nil || |
nothing calls this directly
no test coverage detected