git-lfs/lfs/util_test.go

40 lines
847 B
Go
Raw Normal View History

2015-03-19 19:30:55 +00:00
package lfs
2014-08-06 22:04:34 +00:00
import (
"bytes"
"testing"
2015-05-13 19:43:41 +00:00
2016-11-15 17:01:18 +00:00
"github.com/git-lfs/git-lfs/progress"
"github.com/stretchr/testify/assert"
2014-08-06 22:04:34 +00:00
)
func TestWriterWithCallback(t *testing.T) {
called := 0
calledRead := make([]int64, 0, 2)
2014-08-06 22:04:34 +00:00
reader := &progress.CallbackReader{
2014-08-06 22:04:34 +00:00
TotalSize: 5,
Reader: bytes.NewBufferString("BOOYA"),
C: func(total int64, read int64, current int) error {
2014-08-06 22:04:34 +00:00
called += 1
calledRead = append(calledRead, read)
2014-08-06 22:04:34 +00:00
assert.Equal(t, 5, int(total))
return nil
},
}
readBuf := make([]byte, 3)
n, err := reader.Read(readBuf)
assert.Nil(t, err)
assert.Equal(t, "BOO", string(readBuf[0:n]))
n, err = reader.Read(readBuf)
assert.Nil(t, err)
assert.Equal(t, "YA", string(readBuf[0:n]))
2014-08-06 22:04:34 +00:00
assert.Equal(t, 2, called)
assert.Len(t, calledRead, 2)
assert.Equal(t, 3, int(calledRead[0]))
assert.Equal(t, 5, int(calledRead[1]))
2014-08-06 22:04:34 +00:00
}