@@ -24,6 +24,7 @@ import (
24
24
"io/ioutil"
25
25
"math/rand"
26
26
"os"
27
+ "strconv"
27
28
"strings"
28
29
"testing"
29
30
"time"
@@ -86,12 +87,17 @@ func TestJournalFollow(t *testing.T) {
86
87
}
87
88
88
89
func TestJournalFollowTail (t * testing.T ) {
90
+ documentation := "https://github.com/coreos/go-systemd/"
89
91
r , err := NewJournalReader (JournalReaderConfig {
90
92
Since : time .Duration (- 15 ) * time .Second ,
91
93
Matches : []Match {
92
94
{
93
- Field : SD_JOURNAL_FIELD_SYSTEMD_UNIT ,
94
- Value : "NetworkManager.service" ,
95
+ Field : SD_JOURNAL_FIELD_PRIORITY ,
96
+ Value : strconv .Itoa (int (journal .PriInfo )),
97
+ },
98
+ {
99
+ Field : "DOCUMENTATION" ,
100
+ Value : documentation ,
95
101
},
96
102
},
97
103
})
@@ -109,35 +115,34 @@ func TestJournalFollowTail(t *testing.T) {
109
115
// start writing some test entries
110
116
done := make (chan struct {}, 1 )
111
117
errCh := make (chan error , 1 )
112
- defer close (done )
113
118
go func () {
114
119
for {
115
120
select {
116
121
case <- done :
117
122
return
118
123
default :
119
- if perr := journal .Print (journal .PriInfo , "test message %s" , time .Now ()); err != nil {
124
+ vars := make (map [string ]string )
125
+ vars ["DOCUMENTATION" ] = documentation
126
+ if perr := journal .Send (fmt .Sprintf ("test message %s" , time .Now ()), journal .PriInfo , vars ); perr != nil {
120
127
errCh <- perr
121
128
return
122
129
}
123
-
124
130
time .Sleep (time .Second )
125
131
}
126
132
}
127
133
}()
128
134
129
- // and follow the reader synchronously
130
135
entries := make (chan * JournalEntry )
131
- timeout := time .Duration (5 ) * time .Second
132
- ctx , cancel := context .WithTimeout (context .Background (), timeout )
136
+ ctx , cancel := context .WithTimeout (context .Background (), time .Duration (5 )* time .Second )
133
137
defer cancel ()
134
- if err = r .FollowTail (entries , ctx ); err != nil {
135
- t .Fatalf ("Error during follow: %s" , err )
136
- }
138
+ go r .FollowTail (entries , errCh , ctx )
137
139
138
140
select {
139
141
case err := <- errCh :
140
142
t .Fatalf ("Error writing to journal: %s" , err )
143
+ case entry := <- entries :
144
+ t .Log ("received: " + entry .Cursor )
145
+ return
141
146
default :
142
147
}
143
148
}
0 commit comments