Commit cd3a1ce3 authored by Geoff Simmons's avatar Geoff Simmons

NewCursorFile fails if the Log is already attached to VSM.

parent 7d76e225
......@@ -94,10 +94,15 @@ func (log *Log) NewCursor() (*Cursor, error) {
// NewCursorFile creates a Cursor to read from a binary log file,
// created by varnishlog -w.
//
// Fails if the Log object is already attached to a live Varnish log.
func (log *Log) NewCursorFile(path string) (*Cursor, error) {
if err := log.checkNil(); err != nil {
return nil, err
}
if log.vsm != nil {
return nil, errors.New("Already attached to a Varnish log")
}
C.VSL_ResetError(log.vsl)
cursor := C.VSL_CursorFile(log.vsl, C.CString(path), 0)
if cursor == nil {
......
......@@ -69,6 +69,21 @@ func TestNewCursor(t *testing.T) {
defer cn.Delete()
}
func TestIllegalCursorFile(t *testing.T) {
l := New()
defer l.Release()
if err := l.Attach(""); err != nil {
t.Fatal("Attach(default):", err)
return
}
c, err := l.NewCursorFile(testFile)
if err == nil {
t.Fatal("Expected NewCursorFile() to fail for attached Log")
return
}
c.Delete()
}
func TestE2ECursor(t *testing.T) {
l := New()
defer l.Release()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment