File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import (
1919 "errors"
2020 "fmt"
2121 "io"
22+ "io/ioutil"
2223 "os"
2324 "testing"
2425 "time"
@@ -150,3 +151,27 @@ func TestJournalCursorGetSeekAndTest(t *testing.T) {
150151 t .Fatalf ("Error testing cursor to journal: %s" , err )
151152 }
152153}
154+
155+ func TestNewJournalFromDir (t * testing.T ) {
156+ // test for error handling
157+ dir := "/ClearlyNonExistingPath/"
158+ j , err := NewJournalFromDir (dir )
159+ if err == nil {
160+ defer j .Close ()
161+ t .Fatalf ("Error expected when opening dummy path (%s)" , dir )
162+ }
163+ // test for main code path
164+ dir , err = ioutil .TempDir ("" , "go-systemd-test" )
165+ if err != nil {
166+ t .Fatalf ("Error creating tempdir: %s" , err )
167+ }
168+ defer os .RemoveAll (dir )
169+ j , err = NewJournalFromDir (dir )
170+ if err != nil {
171+ t .Fatalf ("Error opening journal: %s" , err )
172+ }
173+ if j == nil {
174+ t .Fatal ("Got a nil journal" )
175+ }
176+ j .Close ()
177+ }
You can’t perform that action at this time.
0 commit comments