This repository has been archived on 2025-03-30. You can view files and clone it, but cannot push or open issues or pull requests.
bactdb/datastore/species_test.go
Matthew Dillon 830a8805c9 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
2014-10-15 13:01:11 -08:00

37 lines
766 B
Go

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)
}
}