@@ -29,6 +29,7 @@ import (
29
29
"os"
30
30
"path/filepath"
31
31
"runtime"
32
+ "strings"
32
33
"sync"
33
34
"time"
34
35
)
@@ -68,13 +69,15 @@ func FileOutputSpec(c gs.Context) {
68
69
outData := make ([]byte , 0 , 20 )
69
70
70
71
c .Specify ("by default" , func () {
71
- fileOutput .handleMessage (pack , & outData )
72
+ err = fileOutput .handleMessage (pack , & outData )
73
+ c .Expect (err , gs .IsNil )
72
74
c .Expect (toString (& outData ), gs .Equals , * msg .Payload + "\n " )
73
75
})
74
76
75
77
c .Specify ("w/ a prepended timestamp when specified" , func () {
76
78
fileOutput .prefix_ts = true
77
- fileOutput .handleMessage (pack , & outData )
79
+ err = fileOutput .handleMessage (pack , & outData )
80
+ c .Expect (err , gs .IsNil )
78
81
// Test will fail if date flips btn handleMessage call and
79
82
// todayStr calculation... should be extremely rare.
80
83
todayStr := time .Now ().Format ("[2006/Jan/02:" )
@@ -83,6 +86,27 @@ func FileOutputSpec(c gs.Context) {
83
86
c .Expect (strContents , pipeline_ts .StringContains , payload )
84
87
c .Expect (strContents , pipeline_ts .StringStartsWith , todayStr )
85
88
})
89
+
90
+ c .Specify ("even when payload is nil" , func () {
91
+ pack .Message .Payload = nil
92
+ err = fileOutput .handleMessage (pack , & outData )
93
+ c .Expect (err , gs .IsNil )
94
+ strContents := toString (& outData )
95
+ c .Expect (strContents , gs .Equals , "\n " )
96
+ })
97
+
98
+ c .Specify ("payload is nil and with a timestamp" , func () {
99
+ pack .Message .Payload = nil
100
+ fileOutput .prefix_ts = true
101
+ err = fileOutput .handleMessage (pack , & outData )
102
+ c .Expect (err , gs .IsNil )
103
+ // Test will fail if date flips btn handleMessage call and
104
+ // todayStr calculation... should be extremely rare.
105
+ todayStr := time .Now ().Format ("[2006/Jan/02:" )
106
+ strContents := toString (& outData )
107
+ c .Expect (strings .HasPrefix (strContents , todayStr ), gs .IsTrue )
108
+ c .Expect (strings .HasSuffix (strContents , " \n " ), gs .IsTrue )
109
+ })
86
110
})
87
111
88
112
c .Specify ("correctly formats JSON output" , func () {
0 commit comments