Create a strain.
This commit is contained in:
parent
6c118f47f7
commit
6bba9058aa
9 changed files with 146 additions and 2 deletions
|
@ -20,3 +20,10 @@ func (s *strainsStore) Get(id int64) (*models.Strain, error) {
|
|||
}
|
||||
return strain[0], nil
|
||||
}
|
||||
|
||||
func (s *strainsStore) Create(strain *models.Strain) (bool, error) {
|
||||
if err := s.dbh.Insert(strain); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
|
|
@ -45,3 +45,23 @@ func TestStrainsStore_Get_db(t *testing.T) {
|
|||
t.Errorf("got strain %+v, want %+v", strain, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStrainsStore_Create_db(t *testing.T) {
|
||||
tx, _ := DB.Begin()
|
||||
defer tx.Rollback()
|
||||
|
||||
strain := newStrain(t, tx)
|
||||
|
||||
d := NewDatastore(tx)
|
||||
|
||||
created, err := d.Strains.Create(strain)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !created {
|
||||
t.Error("!created")
|
||||
}
|
||||
if strain.Id == 0 {
|
||||
t.Error("want nonzero strain.Id after submitting")
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue