progressscanner_test.go 601 B

12345678910111213141516171819202122232425262728293031
  1. package filex
  2. import (
  3. "strings"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. "gopkg.in/cheggaaa/pb.v1"
  7. )
  8. func TestProgressScanner(t *testing.T) {
  9. const text = "hello, world"
  10. bar := pb.New(100)
  11. var builder strings.Builder
  12. builder.WriteString(text)
  13. scanner := NewProgressScanner(&mockedScanner{builder: &builder}, bar)
  14. assert.True(t, scanner.Scan())
  15. assert.Equal(t, text, scanner.Text())
  16. }
  17. type mockedScanner struct {
  18. builder *strings.Builder
  19. }
  20. func (s *mockedScanner) Scan() bool {
  21. return s.builder.Len() > 0
  22. }
  23. func (s *mockedScanner) Text() string {
  24. return s.builder.String()
  25. }