File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -303,6 +303,7 @@ package sdjournal
303303import "C"
304304import (
305305 "bytes"
306+ "errors"
306307 "fmt"
307308 "strings"
308309 "sync"
@@ -370,6 +371,12 @@ const (
370371 IndefiniteWait time.Duration = 1 << 63 - 1
371372)
372373
374+ var (
375+ // Error show when using TestCursor function and cursor parameter is not the same
376+ // as the current cursor position
377+ ErrNoTestCursor = errors .New ("Cursor parameter is not the same as current position" )
378+ )
379+
373380// Journal is a Go wrapper of an sd_journal structure.
374381type Journal struct {
375382 cjournal * C.sd_journal
@@ -879,6 +886,8 @@ func (j *Journal) TestCursor(cursor string) error {
879886
880887 if r < 0 {
881888 return fmt .Errorf ("failed to test to cursor %q: %d" , cursor , syscall .Errno (- r ))
889+ } else if r == 0 {
890+ return ErrNoTestCursor
882891 }
883892
884893 return nil
Original file line number Diff line number Diff line change @@ -178,6 +178,20 @@ func TestJournalCursorGetSeekAndTest(t *testing.T) {
178178 if err != nil {
179179 t .Fatalf ("Error testing cursor to journal: %s" , err )
180180 }
181+
182+ err = journal .Print (journal .PriInfo , "second message %s" , time .Now ())
183+ if err != nil {
184+ t .Fatalf ("Error writing to journal: %s" , err )
185+ }
186+
187+ if err = waitAndNext (j ); err != nil {
188+ t .Fatalf (err .Error ())
189+ }
190+
191+ err = j .TestCursor (c )
192+ if err != ErrNoTestCursor {
193+ t .Fatalf ("Error, TestCursor should fail because current cursor has moved from the previous obtained cursor" )
194+ }
181195}
182196
183197func TestNewJournalFromDir (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments