Create species, cleanup schema.
- create species - species genus_id not null
This commit is contained in:
parent
ed2ba26654
commit
7fe5566edf
10 changed files with 155 additions and 3 deletions
|
@ -35,3 +35,31 @@ func TestSpeciesStore_Get_db(t *testing.T) {
|
|||
t.Errorf("got species %+v, want %+v", species, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSpeciesStore_Create_db(t *testing.T) {
|
||||
tx, _ := DB.Begin()
|
||||
defer tx.Rollback()
|
||||
|
||||
// Test on a clean database
|
||||
tx.Exec(`DELETE FROM species;`)
|
||||
|
||||
genus := &models.Genus{}
|
||||
if err := tx.Insert(genus); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
species := &models.Species{Id: 1, GenusId: genus.Id, SpeciesName: "Test Species"}
|
||||
|
||||
d := NewDatastore(tx)
|
||||
created, err := d.Species.Create(species)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !created {
|
||||
t.Error("!created")
|
||||
}
|
||||
if species.Id == 0 {
|
||||
t.Error("want nonzero species.Id after submitting")
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue