-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathkind_extractor_test.go
76 lines (59 loc) · 1.51 KB
/
kind_extractor_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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package db_test
import (
"github.com/drborges/datastore-model"
"github.com/drborges/goexpect"
"reflect"
"testing"
)
func TestKindExtractorExtractsKindFromNonTaggedModel(t *testing.T) {
type Tag struct {
db.Model
Name string
}
tag := &Tag{}
meta := &db.Metadata{}
field := reflect.TypeOf(tag).Elem().Field(0)
value := reflect.ValueOf(tag).Elem().Field(0)
err := db.KindExtractor{meta}.Extract(tag, field, value)
expect := goexpect.New(t)
expect(err).ToBe(nil)
expect(meta.Kind).ToBe("Tag")
}
func TestKindExtractorExtractsKindFromTag(t *testing.T) {
type Tag struct {
db.Model `db:"Tags"`
Name string
}
tag := &Tag{}
meta := &db.Metadata{}
field := reflect.TypeOf(tag).Elem().Field(0)
value := reflect.ValueOf(tag).Elem().Field(0)
err := db.KindExtractor{meta}.Extract(tag, field, value)
expect := goexpect.New(t)
expect(err).ToBe(nil)
expect(meta.Kind).ToBe("Tags")
}
func TestKindExtractorAccpetsModelEmbeddedField(t *testing.T) {
type Tag struct {
db.Model
Name string
}
tag := &Tag{}
meta := &db.Metadata{}
field := reflect.TypeOf(tag).Elem().Field(0)
accepts := db.KindExtractor{meta}.Accept(field)
expect := goexpect.New(t)
expect(accepts).ToBe(true)
}
func TestKindExtractorDoesNotAccpetNonModelEmbeddedField(t *testing.T) {
type Tag struct {
db.Model
Name string
}
tag := &Tag{}
meta := &db.Metadata{}
fieldModel := reflect.TypeOf(tag).Elem().Field(1)
accepts := db.KindExtractor{meta}.Accept(fieldModel)
expect := goexpect.New(t)
expect(accepts).ToBe(false)
}