Delete strain.

This commit is contained in:
Matthew Dillon 2014-10-29 14:11:50 -08:00
parent ff0e37d2ef
commit df95dfc930
9 changed files with 141 additions and 0 deletions

View file

@ -61,3 +61,19 @@ func (s *strainsStore) Update(id int64, strain *models.Strain) (bool, error) {
return true, nil
}
func (s *strainsStore) Delete(id int64) (bool, error) {
strain, err := s.Get(id)
if err != nil {
return false, err
}
deleted, err := s.dbh.Delete(strain)
if err != nil {
return false, err
}
if deleted == 0 {
return false, ErrNoRowsDeleted
}
return true, nil
}

View file

@ -107,3 +107,22 @@ func TestStrainsStore_Update_db(t *testing.T) {
t.Error("!updated")
}
}
func TestStrainsStore_Delete_db(t *testing.T) {
tx, _ := DB.Begin()
defer tx.Rollback()
strain := insertStrain(t, tx)
d := NewDatastore(tx)
// Delete it
deleted, err := d.Strains.Delete(strain.Id)
if err != nil {
t.Fatal(err)
}
if !deleted {
t.Error("!delete")
}
}