Add test for scan reader
This commit is contained in:
parent
1591d86e23
commit
2a9c9e893e
|
@ -22,7 +22,7 @@ var (
|
|||
// The maximum size of the buffer used to send output over the console to
|
||||
// clients. Once this length is reached, the line will be truncated and sent
|
||||
// as is.
|
||||
const maxBufferSize = 64 * 1024
|
||||
var maxBufferSize = 64 * 1024
|
||||
|
||||
// FirstNotEmpty returns the first string passed in that is not an empty value.
|
||||
func FirstNotEmpty(v ...string) string {
|
||||
|
|
41
system/utils_test.go
Normal file
41
system/utils_test.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
package system
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
. "github.com/franela/goblin"
|
||||
)
|
||||
|
||||
func TestScanReader(t *testing.T) {
|
||||
g := Goblin(t)
|
||||
|
||||
g.Describe("ScanReader", func() {
|
||||
g.BeforeEach(func() {
|
||||
maxBufferSize = 10
|
||||
})
|
||||
|
||||
g.It("should truncate and return long lines", func() {
|
||||
reader := strings.NewReader("hello world this is a long line\nof text that should be truncated\nnot here\nbut definitely on this line")
|
||||
|
||||
var lines []string
|
||||
err := ScanReader(reader, func(line []byte) {
|
||||
lines = append(lines, string(line))
|
||||
})
|
||||
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(lines).Equal([]string{"hello worl", "of text th", "not here", "but defini"})
|
||||
})
|
||||
|
||||
g.It("should replace cariage returns with newlines", func() {
|
||||
reader := strings.NewReader("test\rstring\r\nanother\rline\nhodor\r\r\rheld the door\nmaterial gourl\n")
|
||||
var lines []string
|
||||
err := ScanReader(reader, func(line []byte) {
|
||||
lines = append(lines, string(line))
|
||||
})
|
||||
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(lines).Equal([]string{"test\rstrin", "another\rli", "hodor\r\r\rhe", "material g"})
|
||||
})
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue
Block a user