Species Read - Order of ops:
router/routes.go router/api.go models/species_test.go models/species.go models/client.go datastore/migrations/addspecies.sql datastore/migrations/dropspecies.sql datastore/species_test.go datastore/species.go datastore/datastore.go api/species_test.go api/species.go api/handler.go
This commit is contained in:
parent
6fe6d5d189
commit
830a8805c9
13 changed files with 263 additions and 7 deletions
37
datastore/species_test.go
Normal file
37
datastore/species_test.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
package datastore
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/thermokarst/bactdb/models"
|
||||
)
|
||||
|
||||
func TestSpeciesStore_Get_db(t *testing.T) {
|
||||
tx, _ := DB.Begin()
|
||||
defer tx.Rollback()
|
||||
|
||||
// Test on a clean database
|
||||
tx.Exec(`DELETE FROM species;`)
|
||||
|
||||
wantGenus := &models.Genus{GenusName: "Test Genus"}
|
||||
if err := tx.Insert(wantGenus); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
want := &models.Species{Id: 1, GenusId: wantGenus.Id, SpeciesName: "Test Species"}
|
||||
if err := tx.Insert(want); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
d := NewDatastore(tx)
|
||||
species, err := d.Species.Get(1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
normalizeTime(&want.CreatedAt, &want.UpdatedAt, &want.DeletedAt)
|
||||
if !reflect.DeepEqual(species, want) {
|
||||
t.Errorf("got species %+v, want %+v", species, want)
|
||||
}
|
||||
}
|
Reference in a new issue