-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patharguments_test.go
More file actions
52 lines (47 loc) · 1.9 KB
/
Copy patharguments_test.go
File metadata and controls
52 lines (47 loc) · 1.9 KB
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
package gqlstruct_test
import (
"github.com/graphql-go/graphql"
"github.com/lab259/go-graphql-struct"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"reflect"
)
var _ = Describe("ArgsOf", func() {
type ComplexModel struct {
FirstName string `graphql:"!firstName"`
MiddleName string
LastName string `graphql:"lastName"`
Age int `graphql:"age"`
}
It("should generate arguments from a non pointer object", func() {
fields, err := gqlstruct.NewEncoder().ArgsOf(reflect.TypeOf(ComplexModel{}))
Expect(err).ToNot(HaveOccurred())
Expect(fields).ToNot(BeNil())
Expect(fields).To(HaveLen(3))
Expect(fields).To(HaveKey("firstName"))
Expect(fields["firstName"].Type).To(BeAssignableToTypeOf(graphql.NewNonNull(nil)))
Expect(fields["firstName"].Type.(*graphql.NonNull).OfType).To(Equal(graphql.String))
Expect(fields).To(HaveKey("lastName"))
Expect(fields["lastName"].Type).To(Equal(graphql.String))
Expect(fields).To(HaveKey("age"))
Expect(fields["age"].Type).To(Equal(graphql.Int))
})
It("should generate arguments from a pointer", func() {
fields, err := gqlstruct.NewEncoder().ArgsOf(reflect.TypeOf(&ComplexModel{}))
Expect(err).ToNot(HaveOccurred())
Expect(fields).ToNot(BeNil())
Expect(fields).To(HaveLen(3))
Expect(fields).To(HaveKey("firstName"))
Expect(fields["firstName"].Type).To(BeAssignableToTypeOf(graphql.NewNonNull(nil)))
Expect(fields["firstName"].Type.(*graphql.NonNull).OfType).To(Equal(graphql.String))
Expect(fields).To(HaveKey("lastName"))
Expect(fields["lastName"].Type).To(Equal(graphql.String))
Expect(fields).To(HaveKey("age"))
Expect(fields["age"].Type).To(Equal(graphql.Int))
})
It("should fail generating arguments for a non supported datatype", func() {
_, err := gqlstruct.NewEncoder().ArgsOf(reflect.TypeOf("data"))
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("cannot build args from a non struct"))
})
})