diff --git a/database.go b/database.go index 84a2cb9..0a249fe 100755 --- a/database.go +++ b/database.go @@ -6,7 +6,7 @@ import ( "encoding/json" "sync" - "github.com/jameycribbs/hare/hare_err" + "github.com/jameycribbs/hare/dberr" ) type Record interface { @@ -75,7 +75,7 @@ func (db *Database) Close() error { func (db *Database) CreateTable(tableName string) error { if db.TableExists(tableName) { - return hare_err.TableExists + return dberr.TableExists } if err := db.store.CreateTable(tableName); err != nil { @@ -95,7 +95,7 @@ func (db *Database) CreateTable(tableName string) error { func (db *Database) Delete(tableName string, id int) error { if !db.TableExists(tableName) { - return hare_err.NoTable + return dberr.NoTable } db.locks[tableName].Lock() @@ -110,7 +110,7 @@ func (db *Database) Delete(tableName string, id int) error { func (db *Database) DropTable(tableName string) error { if !db.TableExists(tableName) { - return hare_err.NoTable + return dberr.NoTable } db.locks[tableName].Lock() @@ -131,7 +131,7 @@ func (db *Database) DropTable(tableName string) error { func (db *Database) Find(tableName string, id int, rec Record) error { if !db.TableExists(tableName) { - return hare_err.NoTable + return dberr.NoTable } db.locks[tableName].RLock() @@ -154,7 +154,7 @@ func (db *Database) Find(tableName string, id int, rec Record) error { func (db *Database) IDs(tableName string) ([]int, error) { if !db.TableExists(tableName) { - return nil, hare_err.NoTable + return nil, dberr.NoTable } db.locks[tableName].Lock() @@ -170,7 +170,7 @@ func (db *Database) IDs(tableName string) ([]int, error) { func (db *Database) Insert(tableName string, rec Record) (int, error) { if !db.TableExists(tableName) { - return 0, hare_err.NoTable + return 0, dberr.NoTable } db.locks[tableName].Lock() @@ -199,7 +199,7 @@ func (db *Database) TableExists(tableName string) bool { func (db *Database) Update(tableName string, rec Record) error { if !db.TableExists(tableName) { - return hare_err.NoTable + return dberr.NoTable } db.locks[tableName].Lock() diff --git a/database_disk_test.go b/database_disk_test.go index 652e1b9..463d38d 100755 --- a/database_disk_test.go +++ b/database_disk_test.go @@ -10,7 +10,7 @@ import ( "testing" "github.com/jameycribbs/hare/datastores/disk" - "github.com/jameycribbs/hare/hare_err" + "github.com/jameycribbs/hare/dberr" ) func TestAllDatabaseDiskTests(t *testing.T) { @@ -41,7 +41,7 @@ func TestAllDatabaseDiskTests(t *testing.T) { db := newTestDatabaseDisk(t) db.Close() - wantErr := hare_err.NoTable + wantErr := dberr.NoTable gotErr := db.Find("contacts", 3, &Contact{}) if !errors.Is(gotErr, wantErr) { @@ -82,12 +82,12 @@ func TestAllDatabaseDiskTests(t *testing.T) { } }, func(t *testing.T) { - //CreateTable (ErrTableExists)... + //CreateTable (TableExists error)... db := newTestDatabaseDisk(t) defer db.Close() - wantErr := hare_err.TableExists + wantErr := dberr.TableExists gotErr := db.CreateTable("contacts") if !errors.Is(gotErr, wantErr) { @@ -105,7 +105,7 @@ func TestAllDatabaseDiskTests(t *testing.T) { t.Fatal(err) } - wantErr := hare_err.NoRecord + wantErr := dberr.NoRecord gotErr := db.Find("contacts", 3, &Contact{}) if !errors.Is(gotErr, wantErr) { @@ -113,12 +113,12 @@ func TestAllDatabaseDiskTests(t *testing.T) { } }, func(t *testing.T) { - //Delete (ErrNoTable)... + //Delete (NoTable error)... db := newTestDatabaseDisk(t) defer db.Close() - wantErr := hare_err.NoTable + wantErr := dberr.NoTable gotErr := db.Delete("nonexistent", 3) if !errors.Is(gotErr, wantErr) { @@ -144,12 +144,12 @@ func TestAllDatabaseDiskTests(t *testing.T) { } }, func(t *testing.T) { - //DropTable (ErrNoTable)... + //DropTable (NoTable error)... db := newTestDatabaseDisk(t) defer db.Close() - wantErr := hare_err.NoTable + wantErr := dberr.NoTable gotErr := db.DropTable("nonexistent") if !errors.Is(gotErr, wantErr) { @@ -177,12 +177,12 @@ func TestAllDatabaseDiskTests(t *testing.T) { } }, func(t *testing.T) { - //Find (ErrNoRecord)... + //Find (NoRecord error)... db := newTestDatabaseDisk(t) defer db.Close() - wantErr := hare_err.NoRecord + wantErr := dberr.NoRecord gotErr := db.Find("contacts", 5, &Contact{}) if !errors.Is(gotErr, wantErr) { @@ -215,12 +215,12 @@ func TestAllDatabaseDiskTests(t *testing.T) { } }, func(t *testing.T) { - //IDs() (ErrNoTable)... + //IDs() (NoTable error)... db := newTestDatabaseDisk(t) defer db.Close() - wantErr := hare_err.NoTable + wantErr := dberr.NoTable _, gotErr := db.IDs("nonexistent") if !errors.Is(gotErr, wantErr) { @@ -258,12 +258,12 @@ func TestAllDatabaseDiskTests(t *testing.T) { } }, func(t *testing.T) { - //Insert (ErrNoTable)... + //Insert (NoTable error)... db := newTestDatabaseDisk(t) defer db.Close() - wantErr := hare_err.NoTable + wantErr := dberr.NoTable _, gotErr := db.Insert("nonexistent", &Contact{FirstName: "Robin", LastName: "Williams", Age: 88}) if !errors.Is(gotErr, wantErr) { @@ -316,12 +316,12 @@ func TestAllDatabaseDiskTests(t *testing.T) { } }, func(t *testing.T) { - //Update (ErrNoTable)... + //Update (NoTable error)... db := newTestDatabaseDisk(t) defer db.Close() - wantErr := hare_err.NoTable + wantErr := dberr.NoTable gotErr := db.Update("nonexistent", &Contact{ID: 4, FirstName: "Hazel", LastName: "Koller", Age: 26}) if !errors.Is(gotErr, wantErr) { diff --git a/database_ram_test.go b/database_ram_test.go index e4ce8a7..1267035 100755 --- a/database_ram_test.go +++ b/database_ram_test.go @@ -8,7 +8,7 @@ import ( "testing" "github.com/jameycribbs/hare/datastores/ram" - "github.com/jameycribbs/hare/hare_err" + "github.com/jameycribbs/hare/dberr" ) func TestAllDatabaseRamTests(t *testing.T) { @@ -39,7 +39,7 @@ func TestAllDatabaseRamTests(t *testing.T) { db := newTestDatabaseRam(t) db.Close() - wantErr := hare_err.NoTable + wantErr := dberr.NoTable gotErr := db.Find("contacts", 3, &Contact{}) if !errors.Is(gotErr, wantErr) { @@ -80,12 +80,12 @@ func TestAllDatabaseRamTests(t *testing.T) { } }, func(t *testing.T) { - //CreateTable (ErrTableExists)... + //CreateTable (TableExists error)... db := newTestDatabaseRam(t) defer db.Close() - wantErr := hare_err.TableExists + wantErr := dberr.TableExists gotErr := db.CreateTable("contacts") if !errors.Is(gotErr, wantErr) { @@ -103,7 +103,7 @@ func TestAllDatabaseRamTests(t *testing.T) { t.Fatal(err) } - wantErr := hare_err.NoRecord + wantErr := dberr.NoRecord gotErr := db.Find("contacts", 3, &Contact{}) if !errors.Is(gotErr, wantErr) { @@ -111,12 +111,12 @@ func TestAllDatabaseRamTests(t *testing.T) { } }, func(t *testing.T) { - //Delete (ErrNoTable)... + //Delete (NoTable error)... db := newTestDatabaseRam(t) defer db.Close() - wantErr := hare_err.NoTable + wantErr := dberr.NoTable gotErr := db.Delete("nonexistent", 3) if !errors.Is(gotErr, wantErr) { @@ -142,12 +142,12 @@ func TestAllDatabaseRamTests(t *testing.T) { } }, func(t *testing.T) { - //DropTable (ErrNoTable)... + //DropTable (NoTable error)... db := newTestDatabaseRam(t) defer db.Close() - wantErr := hare_err.NoTable + wantErr := dberr.NoTable gotErr := db.DropTable("nonexistent") if !errors.Is(gotErr, wantErr) { @@ -175,12 +175,12 @@ func TestAllDatabaseRamTests(t *testing.T) { } }, func(t *testing.T) { - //Find (ErrNoRecord)... + //Find (NoRecord error)... db := newTestDatabaseRam(t) defer db.Close() - wantErr := hare_err.NoRecord + wantErr := dberr.NoRecord gotErr := db.Find("contacts", 5, &Contact{}) if !errors.Is(gotErr, wantErr) { @@ -213,12 +213,12 @@ func TestAllDatabaseRamTests(t *testing.T) { } }, func(t *testing.T) { - //IDs() (ErrNoTable)... + //IDs() (NoTable error)... db := newTestDatabaseRam(t) defer db.Close() - wantErr := hare_err.NoTable + wantErr := dberr.NoTable _, gotErr := db.IDs("nonexistent") if !errors.Is(gotErr, wantErr) { @@ -256,12 +256,12 @@ func TestAllDatabaseRamTests(t *testing.T) { } }, func(t *testing.T) { - //Insert (ErrNoTable)... + //Insert (NoTable error)... db := newTestDatabaseRam(t) defer db.Close() - wantErr := hare_err.NoTable + wantErr := dberr.NoTable _, gotErr := db.Insert("nonexistent", &Contact{FirstName: "Robin", LastName: "Williams", Age: 88}) if !errors.Is(gotErr, wantErr) { @@ -314,12 +314,12 @@ func TestAllDatabaseRamTests(t *testing.T) { } }, func(t *testing.T) { - //Update (ErrNoTable)... + //Update (NoTable error)... db := newTestDatabaseRam(t) defer db.Close() - wantErr := hare_err.NoTable + wantErr := dberr.NoTable gotErr := db.Update("nonexistent", &Contact{ID: 4, FirstName: "Hazel", LastName: "Koller", Age: 26}) if !errors.Is(gotErr, wantErr) { diff --git a/datastores/disk/disk.go b/datastores/disk/disk.go index 51e4ef3..94617a1 100755 --- a/datastores/disk/disk.go +++ b/datastores/disk/disk.go @@ -5,7 +5,7 @@ import ( "os" "strings" - "github.com/jameycribbs/hare/hare_err" + "github.com/jameycribbs/hare/dberr" ) type Disk struct { @@ -43,7 +43,7 @@ func (dsk *Disk) Close() error { func (dsk *Disk) CreateTable(tableName string) error { if dsk.TableExists(tableName) { - return hare_err.TableExists + return dberr.TableExists } filePtr, err := dsk.openFile(tableName, true) @@ -101,7 +101,7 @@ func (dsk *Disk) InsertRec(tableName string, id int, rec []byte) error { ids := tableFile.ids() for _, i := range ids { if id == i { - return hare_err.IDExists + return dberr.IDExists } } @@ -186,7 +186,7 @@ func (dsk *Disk) UpdateRec(tableName string, id int, rec []byte) error { func (dsk *Disk) getTableFile(tableName string) (*tableFile, error) { tableFile, ok := dsk.tableFiles[tableName] if !ok { - return nil, hare_err.NoTable + return nil, dberr.NoTable } return tableFile, nil @@ -263,7 +263,7 @@ func (dsk Disk) openFile(tableName string, createIfNeeded bool) (*os.File, error func (dsk *Disk) closeTable(tableName string) error { tableFile, ok := dsk.tableFiles[tableName] if !ok { - return hare_err.NoTable + return dberr.NoTable } if err := tableFile.close(); err != nil { diff --git a/datastores/disk/disk_test.go b/datastores/disk/disk_test.go index d06cb0e..b2ae543 100755 --- a/datastores/disk/disk_test.go +++ b/datastores/disk/disk_test.go @@ -7,6 +7,8 @@ import ( "sort" "strconv" "testing" + + "github.com/jameycribbs/hare/dberr" ) func TestAllDiskTests(t *testing.T) { @@ -51,7 +53,7 @@ func TestAllDiskTests(t *testing.T) { dsk := newTestDisk(t) dsk.Close() - wantErr := ErrNoTable + wantErr := dberr.NoTable _, gotErr := dsk.ReadRec("contacts", 3) if !errors.Is(gotErr, wantErr) { @@ -92,12 +94,12 @@ func TestAllDiskTests(t *testing.T) { } }, func(t *testing.T) { - //CreateTable (ErrTableExists)... + //CreateTable (TableExists error)... dsk := newTestDisk(t) defer dsk.Close() - wantErr := ErrTableExists + wantErr := dberr.TableExists gotErr := dsk.CreateTable("contacts") if !errors.Is(gotErr, wantErr) { @@ -115,7 +117,7 @@ func TestAllDiskTests(t *testing.T) { t.Fatal(err) } - want := ErrNoRecord + want := dberr.NoRecord _, got := dsk.ReadRec("contacts", 3) if !errors.Is(got, want) { @@ -123,12 +125,12 @@ func TestAllDiskTests(t *testing.T) { } }, func(t *testing.T) { - //DeleteRec (ErrNoTable)... + //DeleteRec (NoTable error)... dsk := newTestDisk(t) defer dsk.Close() - wantErr := ErrNoTable + wantErr := dberr.NoTable gotErr := dsk.DeleteRec("nonexistent", 3) if !errors.Is(gotErr, wantErr) { @@ -152,12 +154,12 @@ func TestAllDiskTests(t *testing.T) { } }, func(t *testing.T) { - //GetLastID (ErrNoTable)... + //GetLastID (NoTable error)... dsk := newTestDisk(t) defer dsk.Close() - wantErr := ErrNoTable + wantErr := dberr.NoTable _, gotErr := dsk.GetLastID("nonexistent") if !errors.Is(gotErr, wantErr) { @@ -190,12 +192,12 @@ func TestAllDiskTests(t *testing.T) { } }, func(t *testing.T) { - //IDs (ErrNoTable)... + //IDs (NoTable error)... dsk := newTestDisk(t) defer dsk.Close() - wantErr := ErrNoTable + wantErr := dberr.NoTable _, gotErr := dsk.IDs("nonexistent") if !errors.Is(gotErr, wantErr) { @@ -226,12 +228,12 @@ func TestAllDiskTests(t *testing.T) { } }, func(t *testing.T) { - //InsertRec (ErrNoTable)... + //InsertRec (NoTable error)... dsk := newTestDisk(t) defer dsk.Close() - wantErr := ErrNoTable + wantErr := dberr.NoTable gotErr := dsk.InsertRec("nonexistent", 5, []byte(`{"id":5,"first_name":"Rex","last_name":"Stout","age":77}`)) if !errors.Is(gotErr, wantErr) { @@ -239,12 +241,12 @@ func TestAllDiskTests(t *testing.T) { } }, func(t *testing.T) { - //InsertRec (ErrIDExists)... + //InsertRec (IDExists error)... dsk := newTestDisk(t) defer dsk.Close() - wantErr := ErrIDExists + wantErr := dberr.IDExists gotErr := dsk.InsertRec("contacts", 3, []byte(`{"id":3,"first_name":"Rex","last_name":"Stout","age":77}`)) if !errors.Is(gotErr, wantErr) { t.Errorf("want %v; got %v", wantErr, gotErr) @@ -281,12 +283,12 @@ func TestAllDiskTests(t *testing.T) { } }, func(t *testing.T) { - //ReadRec (ErrNoTable)... + //ReadRec (NoTable error)... dsk := newTestDisk(t) defer dsk.Close() - wantErr := ErrNoTable + wantErr := dberr.NoTable _, gotErr := dsk.ReadRec("nonexistent", 3) if !errors.Is(gotErr, wantErr) { @@ -321,12 +323,12 @@ func TestAllDiskTests(t *testing.T) { } }, func(t *testing.T) { - //RemoveTable (ErrNoTable)... + //RemoveTable (NoTable error)... dsk := newTestDisk(t) defer dsk.Close() - wantErr := ErrNoTable + wantErr := dberr.NoTable gotErr := dsk.RemoveTable("nonexistent") if !errors.Is(gotErr, wantErr) { @@ -399,12 +401,12 @@ func TestAllDiskTests(t *testing.T) { } }, func(t *testing.T) { - //UpdateRec (ErrNoTable)... + //UpdateRec (NoTable error)... dsk := newTestDisk(t) defer dsk.Close() - wantErr := ErrNoTable + wantErr := dberr.NoTable gotErr := dsk.UpdateRec("nonexistent", 3, []byte(`{"id":3,"first_name":"William","last_name":"Shakespeare","age":77}`)) if !errors.Is(gotErr, wantErr) { @@ -423,12 +425,12 @@ func TestAllDiskTests(t *testing.T) { } }, func(t *testing.T) { - //closeTable (ErrNoTable)... + //closeTable (NoTable error)... dsk := newTestDisk(t) defer dsk.Close() - wantErr := ErrNoTable + wantErr := dberr.NoTable gotErr := dsk.closeTable("nonexistent") if !errors.Is(gotErr, wantErr) { diff --git a/datastores/disk/table_file.go b/datastores/disk/table_file.go index a3c1845..d5ec6d2 100755 --- a/datastores/disk/table_file.go +++ b/datastores/disk/table_file.go @@ -6,7 +6,7 @@ import ( "io" "os" - "github.com/jameycribbs/hare/hare_err" + "github.com/jameycribbs/hare/dberr" ) const dummyRune = 'X' @@ -77,7 +77,7 @@ func (t *tableFile) close() error { func (t *tableFile) deleteRec(id int) error { offset, ok := t.offsets[id] if !ok { - return hare_err.NoRecord + return dberr.NoRecord } rec, err := t.readRec(id) @@ -204,7 +204,7 @@ func (t *tableFile) overwriteRec(offset int64, recLen int) error { func (t *tableFile) readRec(id int) ([]byte, error) { offset, ok := t.offsets[id] if !ok { - return nil, hare_err.NoRecord + return nil, dberr.NoRecord } r := bufio.NewReader(t.ptr) @@ -226,7 +226,7 @@ func (t *tableFile) updateRec(id int, rec []byte) error { oldRecOffset, ok := t.offsets[id] if !ok { - return hare_err.NoRecord + return dberr.NoRecord } oldRec, err := t.readRec(id) diff --git a/datastores/disk/tablefile_test.go b/datastores/disk/tablefile_test.go index 778196a..ef2e009 100755 --- a/datastores/disk/tablefile_test.go +++ b/datastores/disk/tablefile_test.go @@ -7,6 +7,8 @@ import ( "sort" "strconv" "testing" + + "github.com/jameycribbs/hare/dberr" ) func TestAllTableFileTests(t *testing.T) { @@ -35,7 +37,7 @@ func TestAllTableFileTests(t *testing.T) { tf := newTestTableFile(t) tf.close() - wantErr := ErrNoRecord + wantErr := dberr.NoRecord _, gotErr := tf.readRec(3) if !errors.Is(gotErr, wantErr) { diff --git a/datastores/ram/ram.go b/datastores/ram/ram.go index 0f1a62a..83bd561 100755 --- a/datastores/ram/ram.go +++ b/datastores/ram/ram.go @@ -1,6 +1,6 @@ package ram -import "github.com/jameycribbs/hare/hare_err" +import "github.com/jameycribbs/hare/dberr" type Ram struct { tables map[string]*table @@ -24,7 +24,7 @@ func (ram *Ram) Close() error { func (ram *Ram) CreateTable(tableName string) error { if ram.TableExists(tableName) { - return hare_err.TableExists + return dberr.TableExists } ram.tables[tableName] = newTable() @@ -70,7 +70,7 @@ func (ram *Ram) InsertRec(tableName string, id int, rec []byte) error { } if table.recExists(id) { - return hare_err.IDExists + return dberr.IDExists } table.writeRec(id, rec) @@ -94,7 +94,7 @@ func (ram *Ram) ReadRec(tableName string, id int) ([]byte, error) { func (ram *Ram) RemoveTable(tableName string) error { if !ram.TableExists(tableName) { - return hare_err.NoTable + return dberr.NoTable } delete(ram.tables, tableName) @@ -125,7 +125,7 @@ func (ram *Ram) UpdateRec(tableName string, id int, rec []byte) error { } if !table.recExists(id) { - return hare_err.NoRecord + return dberr.NoRecord } table.writeRec(id, rec) @@ -140,7 +140,7 @@ func (ram *Ram) UpdateRec(tableName string, id int, rec []byte) error { func (ram *Ram) getTable(tableName string) (*table, error) { table, ok := ram.tables[tableName] if !ok { - return nil, hare_err.NoTable + return nil, dberr.NoTable } return table, nil diff --git a/datastores/ram/ram_test.go b/datastores/ram/ram_test.go index 68207c4..27fe94a 100755 --- a/datastores/ram/ram_test.go +++ b/datastores/ram/ram_test.go @@ -6,6 +6,8 @@ import ( "sort" "strconv" "testing" + + "github.com/jameycribbs/hare/dberr" ) func TestAllRamTests(t *testing.T) { @@ -34,7 +36,7 @@ func TestAllRamTests(t *testing.T) { ram := newTestRam(t) ram.Close() - wantErr := ErrNoTable + wantErr := dberr.NoTable _, gotErr := ram.ReadRec("contacts", 3) if !errors.Is(gotErr, wantErr) { @@ -66,12 +68,12 @@ func TestAllRamTests(t *testing.T) { } }, func(t *testing.T) { - //CreateTable (ErrTableExists)... + //CreateTable (TableExists error)... ram := newTestRam(t) defer ram.Close() - wantErr := ErrTableExists + wantErr := dberr.TableExists gotErr := ram.CreateTable("contacts") if !errors.Is(gotErr, wantErr) { @@ -89,7 +91,7 @@ func TestAllRamTests(t *testing.T) { t.Fatal(err) } - want := ErrNoRecord + want := dberr.NoRecord _, got := ram.ReadRec("contacts", 3) if !errors.Is(got, want) { @@ -97,12 +99,12 @@ func TestAllRamTests(t *testing.T) { } }, func(t *testing.T) { - //DeleteRec (ErrNoTable)... + //DeleteRec (NoTable error)... ram := newTestRam(t) defer ram.Close() - wantErr := ErrNoTable + wantErr := dberr.NoTable gotErr := ram.DeleteRec("nonexistent", 3) if !errors.Is(gotErr, wantErr) { @@ -126,12 +128,12 @@ func TestAllRamTests(t *testing.T) { } }, func(t *testing.T) { - //GetLastID (ErrNoTable)... + //GetLastID (NoTable error)... ram := newTestRam(t) defer ram.Close() - wantErr := ErrNoTable + wantErr := dberr.NoTable _, gotErr := ram.GetLastID("nonexistent") if !errors.Is(gotErr, wantErr) { @@ -164,12 +166,12 @@ func TestAllRamTests(t *testing.T) { } }, func(t *testing.T) { - //IDs (ErrNoTable)... + //IDs (NoTable error)... ram := newTestRam(t) defer ram.Close() - wantErr := ErrNoTable + wantErr := dberr.NoTable _, gotErr := ram.IDs("nonexistent") if !errors.Is(gotErr, wantErr) { @@ -200,12 +202,12 @@ func TestAllRamTests(t *testing.T) { } }, func(t *testing.T) { - //InsertRec (ErrNoTable)... + //InsertRec (NoTable error)... ram := newTestRam(t) defer ram.Close() - wantErr := ErrNoTable + wantErr := dberr.NoTable gotErr := ram.InsertRec("nonexistent", 5, []byte(`{"id":5,"first_name":"Rex","last_name":"Stout","age":77}`)) if !errors.Is(gotErr, wantErr) { @@ -213,12 +215,12 @@ func TestAllRamTests(t *testing.T) { } }, func(t *testing.T) { - //InsertRec (ErrIDExists)... + //InsertRec (IDExists error)... ram := newTestRam(t) defer ram.Close() - wantErr := ErrRecordExists + wantErr := dberr.IDExists gotErr := ram.InsertRec("contacts", 3, []byte(`{"id":3,"first_name":"Rex","last_name":"Stout","age":77}`)) if !errors.Is(gotErr, wantErr) { t.Errorf("want %v; got %v", wantErr, gotErr) @@ -255,12 +257,12 @@ func TestAllRamTests(t *testing.T) { } }, func(t *testing.T) { - //ReadRec (ErrNoTable)... + //ReadRec (NoTable error)... ram := newTestRam(t) defer ram.Close() - wantErr := ErrNoTable + wantErr := dberr.NoTable _, gotErr := ram.ReadRec("nonexistent", 3) if !errors.Is(gotErr, wantErr) { @@ -286,12 +288,12 @@ func TestAllRamTests(t *testing.T) { } }, func(t *testing.T) { - //RemoveTable (ErrNoTable)... + //RemoveTable (NoTable error)... ram := newTestRam(t) defer ram.Close() - wantErr := ErrNoTable + wantErr := dberr.NoTable gotErr := ram.RemoveTable("nonexistent") if !errors.Is(gotErr, wantErr) { @@ -364,12 +366,12 @@ func TestAllRamTests(t *testing.T) { } }, func(t *testing.T) { - //UpdateRec (ErrNoTable)... + //UpdateRec (NoTable error)... ram := newTestRam(t) defer ram.Close() - wantErr := ErrNoTable + wantErr := dberr.NoTable gotErr := ram.UpdateRec("nonexistent", 3, []byte(`{"id":3,"first_name":"William","last_name":"Shakespeare","age":77}`)) if !errors.Is(gotErr, wantErr) { diff --git a/datastores/ram/table.go b/datastores/ram/table.go index 54dae38..99c2512 100755 --- a/datastores/ram/table.go +++ b/datastores/ram/table.go @@ -1,6 +1,6 @@ package ram -import "github.com/jameycribbs/hare/hare_err" +import "github.com/jameycribbs/hare/dberr" type table struct { records map[int][]byte @@ -16,7 +16,7 @@ func newTable() *table { func (t *table) deleteRec(id int) error { if !t.recExists(id) { - return hare_err.NoRecord + return dberr.NoRecord } delete(t.records, id) @@ -51,7 +51,7 @@ func (t *table) ids() []int { func (t *table) readRec(id int) ([]byte, error) { rec, ok := t.records[id] if !ok { - return nil, hare_err.NoRecord + return nil, dberr.NoRecord } return rec, nil diff --git a/datastores/ram/table_test.go b/datastores/ram/table_test.go index 00fc54e..07bf5e6 100755 --- a/datastores/ram/table_test.go +++ b/datastores/ram/table_test.go @@ -6,6 +6,8 @@ import ( "sort" "strconv" "testing" + + "github.com/jameycribbs/hare/dberr" ) func TestAllTableTests(t *testing.T) { @@ -37,7 +39,7 @@ func TestAllTableTests(t *testing.T) { t.Fatal(err) } - wantErr := ErrNoRecord + wantErr := dberr.NoRecord _, gotErr := tbl.readRec(3) if !errors.Is(gotErr, wantErr) { t.Errorf("want %v; got %v", wantErr, gotErr) diff --git a/hare_err/hare_err.go b/dberr/dberr.go similarity index 94% rename from hare_err/hare_err.go rename to dberr/dberr.go index b4e8e13..474cfc1 100755 --- a/hare_err/hare_err.go +++ b/dberr/dberr.go @@ -1,4 +1,4 @@ -package hare_err +package dberr import "errors"