1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
14 var _ = Suite(&streamWriterAtSuite{})
16 type streamWriterAtSuite struct{}
18 func (s *streamWriterAtSuite) TestPartSizes(c *C) {
19 for partsize := 1; partsize < 5; partsize++ {
20 for writesize := 1; writesize < 5; writesize++ {
21 for datasize := 1; datasize < 100; datasize += 13 {
22 for bufextra := 0; bufextra < 5; bufextra++ {
23 c.Logf("=== partsize %d writesize %d datasize %d bufextra %d", partsize, writesize, datasize, bufextra)
24 outbuf := bytes.NewBuffer(nil)
25 indata := make([]byte, datasize)
26 for i := range indata {
29 swa := newStreamWriterAt(outbuf, partsize, make([]byte, datasize+bufextra))
31 for pos := 0; pos < datasize; pos += writesize {
36 endpos := pos + writesize
37 if endpos > datasize {
40 swa.WriteAt(indata[pos:endpos], int64(pos))
45 c.Check(outbuf.Bytes(), DeepEquals, indata)
52 func (s *streamWriterAtSuite) TestOverflow(c *C) {
53 for offset := -1; offset < 2; offset++ {
54 buf := make([]byte, 50)
55 swa := newStreamWriterAt(bytes.NewBuffer(nil), 20, buf)
56 _, err := swa.WriteAt([]byte("foo"), int64(len(buf)+offset))
63 func (s *streamWriterAtSuite) TestIncompleteWrite(c *C) {
64 for _, partsize := range []int{20, 25} {
65 for _, bufsize := range []int{50, 55, 60} {
66 for offset := 0; offset < 3; offset++ {
67 swa := newStreamWriterAt(bytes.NewBuffer(nil), partsize, make([]byte, bufsize))
68 _, err := swa.WriteAt(make([]byte, 1), 49)
70 _, err = swa.WriteAt(make([]byte, 46), int64(offset))
74 c.Check(swa.WroteAt(), Equals, 47)
76 c.Check(swa.Wrote(), Equals, 40/partsize*partsize)
78 c.Check(swa.Wrote(), Equals, 0)