Delete a measurement
This commit is contained in:
parent
bc3c724a1d
commit
4eecb36e34
9 changed files with 141 additions and 0 deletions
|
@ -69,3 +69,19 @@ func (s *measurementsStore) Update(id int64, measurement *models.Measurement) (b
|
|||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (s *measurementsStore) Delete(id int64) (bool, error) {
|
||||
measurement, err := s.Get(id)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
deleted, err := s.dbh.Delete(measurement)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if deleted == 0 {
|
||||
return false, ErrNoRowsDeleted
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
|
|
@ -118,3 +118,22 @@ func TestMeasurementsStore_Update_db(t *testing.T) {
|
|||
t.Error("!updated")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMeasurementsStore_Delete_db(t *testing.T) {
|
||||
tx, _ := DB.Begin()
|
||||
defer tx.Rollback()
|
||||
|
||||
measurement := insertMeasurement(t, tx)
|
||||
|
||||
d := NewDatastore(tx)
|
||||
|
||||
// Delete it
|
||||
deleted, err := d.Measurements.Delete(measurement.Id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !deleted {
|
||||
t.Error("!delete")
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue