diff --git a/gobdb.go b/gobdb.go index 2840129..a734f51 100644 --- a/gobdb.go +++ b/gobdb.go @@ -108,7 +108,7 @@ func (db Gobdb[T]) List() []T { // during the process, the method returns the error with details about what // went wrong. func (db *Gobdb[T]) Add(d ...T) error { - file, err := os.Create(db.path) + file, err := os.OpenFile(db.path, os.O_APPEND|os.O_WRONLY, os.ModeAppend) if err != nil { return fmt.Errorf("unable to open file: %w", err) } diff --git a/gobdb_test.go b/gobdb_test.go index e9f2520..ff67720 100644 --- a/gobdb_test.go +++ b/gobdb_test.go @@ -30,7 +30,7 @@ func TestAdd(t *testing.T) { want := []string{"barbara", "victor", "walter"} err = db.Add(want...) if err != nil { - t.Errorf("unable to add data %v: %s", want, err) + t.Fatalf("unable to add data %v: %s", want, err) } got := db.List() if !cmp.Equal(want, got) {