@@ -24,6 +24,7 @@ import (
2424 "io/ioutil"
2525 "math/rand"
2626 "os"
27+ "strconv"
2728 "strings"
2829 "testing"
2930 "time"
@@ -86,12 +87,17 @@ func TestJournalFollow(t *testing.T) {
8687}
8788
8889func TestJournalFollowTail (t * testing.T ) {
90+ documentation := "https://github.com/coreos/go-systemd/"
8991 r , err := NewJournalReader (JournalReaderConfig {
9092 Since : time .Duration (- 15 ) * time .Second ,
9193 Matches : []Match {
9294 {
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 ,
95101 },
96102 },
97103 })
@@ -109,35 +115,34 @@ func TestJournalFollowTail(t *testing.T) {
109115 // start writing some test entries
110116 done := make (chan struct {}, 1 )
111117 errCh := make (chan error , 1 )
112- defer close (done )
113118 go func () {
114119 for {
115120 select {
116121 case <- done :
117122 return
118123 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 {
120127 errCh <- perr
121128 return
122129 }
123-
124130 time .Sleep (time .Second )
125131 }
126132 }
127133 }()
128134
129- // and follow the reader synchronously
130135 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 )
133137 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 )
137139
138140 select {
139141 case err := <- errCh :
140142 t .Fatalf ("Error writing to journal: %s" , err )
143+ case entry := <- entries :
144+ t .Log ("received: " + entry .Cursor )
145+ return
141146 default :
142147 }
143148}
0 commit comments