Skip to content

Commit 13598f4

Browse files
author
George Malamidis
committed
fixed log output error reporting
1 parent cad631f commit 13598f4

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

message.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ func (this *Message) readOutputFile(path string) ([]byte, error) {
8181
}
8282
br := bufio.NewReader(f)
8383
lr := &io.LimitedReader{br, MAX_OUTFILE_READ_LEN}
84-
buf := make([]byte, 0)
85-
_, e = lr.Read(buf)
84+
buf := make([]byte, MAX_OUTFILE_READ_LEN)
85+
n, e := lr.Read(buf)
8686
if e != nil {
8787
return nil, e
8888
}
89-
return buf, nil
89+
return buf[:n], nil
9090
}
9191

9292
func (this *Message) readOut() string {
@@ -100,6 +100,7 @@ func (this *Message) readOut() string {
100100
} else {
101101
content = append(content, []byte("STDOUT:\n")...)
102102
content = append(content, stdout...)
103+
content = append(content, []byte("\n")...)
103104
}
104105
stderr, e := this.readOutputFile(this.Stderr)
105106
if e != nil {

message_test.go

+32
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package main
22

33
import (
4+
"fmt"
5+
"io/ioutil"
6+
"os"
47
"testing"
58
)
69

@@ -68,3 +71,32 @@ func TestDefaultWorkdir(t *testing.T) {
6871
t.Errorf("[%s] isn't [%s]", msg.Workdir, "/tmp")
6972
}
7073
}
74+
75+
func TestReadOut(t *testing.T) {
76+
logfile := "glowtestreadout.log"
77+
logdata := "log data whatevs"
78+
e := ioutil.WriteFile(logfile, []byte(logdata), os.ModePerm)
79+
if e != nil {
80+
t.Fatal(e)
81+
}
82+
defer func(t *testing.T, logfile string) {
83+
e := os.Remove(logfile)
84+
if e != nil {
85+
t.Fatal(e)
86+
}
87+
}(t, logfile)
88+
msg, e := NewMessage("executable", []string{"arg"}, "email", "workdir", logfile, logfile, "testtube", 0, 0)
89+
hostname, e := os.Hostname()
90+
if e != nil {
91+
t.Fatal(e)
92+
}
93+
expectedOutput := fmt.Sprintf(`hostname: %s
94+
STDOUT:
95+
log data whatevs
96+
STDERR:
97+
log data whatevs`, hostname)
98+
actualOutput := msg.readOut()
99+
if expectedOutput != actualOutput {
100+
t.Errorf("[%s] isn't [%s]", expectedOutput, actualOutput)
101+
}
102+
}

0 commit comments

Comments
 (0)