-
Notifications
You must be signed in to change notification settings - Fork 3
/
querier_test.go
48 lines (39 loc) · 966 Bytes
/
querier_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package db_test
import (
"github.com/drborges/datastore-model"
"github.com/drborges/goexpect"
"testing"
)
var (
diego = &Person{Name: "Diego", Country: "Brazil"}
munjal = &Person{Name: "Munjal", Country: "USA"}
)
type Person struct {
db.Model `db:"People"`
Name string `db:"id"`
Country string
}
func TestQuerierEntityAtSlicePtr(t *testing.T) {
t.Parallel()
people := []*Person{diego, munjal}
entity := db.EntityAt(&people, 1)
expect := goexpect.New(t)
expect(entity).ToBe(munjal)
}
func TestQuerierEntityAtSlice(t *testing.T) {
t.Parallel()
people := []*Person{diego, munjal}
entity := db.EntityAt(people, 0)
expect := goexpect.New(t)
expect(entity).ToBe(diego)
}
func TestQuerierEntityAtPanicsWhenInvalidParameterIsProvided(t *testing.T) {
t.Parallel()
defer func() {
expect := goexpect.New(t)
err := recover()
expect(err).ToBe(db.ErrInvalidType)
}()
db.EntityAt(123, 0) // Should panic
panic("Should not reach here")
}