Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for nil in GetColl #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion ejdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,14 @@ func (ejdb *Ejdb) GetColl(colname string) (*EjColl, *EjdbError) {
ejcoll.ejdb = ejdb
ejcoll.ptr = (*[0]byte)(unsafe.Pointer(C.ejdbgetcoll((*C.struct_EJDB)(unsafe.Pointer(ejdb.ptr)), c_colname)))

return ejcoll, ejdb.check_error()
if ejcoll.ptr == nil {
currentError := ejdb.check_error()
if currentError == nil {
currentError = &EjdbError{9000, errors.New("No such collection")}
}
return nil, currentError
}
return ejcoll, nil
}

// Return a slice containing shallow copies of all collection handles (EjColl) currently open.
Expand Down
11 changes: 11 additions & 0 deletions ejdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ func TestGetColl(t *testing.T) {
}
}

func TestGetCollWrongColl(t *testing.T) {
ejdb := open()
coll, err := ejdb.GetColl("NonExistent")
if coll != nil {
t.Error("GetColl() should return nil coll ")
}
if err == nil {
t.Error("GetColl() should return an error")
}
}

func TestGetColls(t *testing.T) {
ejdb := open()
ejdb.CreateColl("MyNewColl", nil)
Expand Down