Switch from Scanner to Reader to avoid Scanner's maximum token size restrictions
This commit is contained in:
parent
eb7191631f
commit
30ead637e2
@ -21,9 +21,18 @@ func readPipe(
|
|||||||
defer func() {
|
defer func() {
|
||||||
done <- 0
|
done <- 0
|
||||||
}()
|
}()
|
||||||
scanner := bufio.NewScanner(f)
|
|
||||||
for scanner.Scan() {
|
var data []byte
|
||||||
data := scanner.Bytes()
|
var err error
|
||||||
|
reader := bufio.NewReader(f)
|
||||||
|
for data, err = reader.ReadBytes('\n'); err == nil; data, err = reader.ReadBytes('\n') {
|
||||||
|
send <- data
|
||||||
|
}
|
||||||
|
if err != io.EOF {
|
||||||
|
log.Printf("error: failed to read pipe: %v", err)
|
||||||
|
}
|
||||||
|
// In case the last line has no newline
|
||||||
|
if len(data) > 0 {
|
||||||
send <- data
|
send <- data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ func TestExecute(t *testing.T) {
|
|||||||
assertLen := func(t *testing.T, items []Item, length int) {
|
assertLen := func(t *testing.T, items []Item, length int) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
if len(items) != length {
|
if len(items) != length {
|
||||||
t.Fatalf("Expected %d items, got %d", length, len(items))
|
t.Errorf("Expected %d items, got %d", length, len(items))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertNil := func(t *testing.T, err error) {
|
assertNil := func(t *testing.T, err error) {
|
||||||
@ -22,7 +22,7 @@ func TestExecute(t *testing.T) {
|
|||||||
assertNotNil := func(t *testing.T, err error) {
|
assertNotNil := func(t *testing.T, err error) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("expected err")
|
t.Error("expected err")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
execute := func(argv []string) ([]Item, error) {
|
execute := func(argv []string) ([]Item, error) {
|
||||||
@ -196,16 +196,16 @@ func TestExecute(t *testing.T) {
|
|||||||
_, _, errItem, err := Execute("test", argv, nil, nil, "", time.Minute, nil)
|
_, _, errItem, err := Execute("test", argv, nil, nil, "", time.Minute, nil)
|
||||||
assertNotNil(t, err)
|
assertNotNil(t, err)
|
||||||
if errItem.Id == "" {
|
if errItem.Id == "" {
|
||||||
t.Fatal("missing erritem id")
|
t.Error("missing erritem id")
|
||||||
}
|
}
|
||||||
if errItem.Source != "default" {
|
if errItem.Source != "default" {
|
||||||
t.Fatalf("unexpected erritem source: expected default, got %s", errItem.Source)
|
t.Errorf("unexpected erritem source: expected default, got %s", errItem.Source)
|
||||||
}
|
}
|
||||||
if !strings.Contains(errItem.Body, "Hello") || !strings.Contains(errItem.Body, "World") {
|
if !strings.Contains(errItem.Body, "Hello") || !strings.Contains(errItem.Body, "World") {
|
||||||
t.Fatal("missing stderr from erritem")
|
t.Error("missing stderr from erritem")
|
||||||
}
|
}
|
||||||
if !strings.Contains(errItem.Body, "whoops") {
|
if !strings.Contains(errItem.Body, "whoops") {
|
||||||
t.Fatal("missing stdout from erritem")
|
t.Error("missing stdout from erritem")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user