-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil_test.go
More file actions
88 lines (79 loc) · 2.36 KB
/
Copy pathutil_test.go
File metadata and controls
88 lines (79 loc) · 2.36 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package kosmo
import (
"testing"
"github.com/graphql-go/graphql"
. "github.com/smartystreets/goconvey/convey"
)
type TStructForObjectConfigTest struct {
Name string
}
func TestReplaceResolverPrefixes(t *testing.T) {
Convey("Given prefixes and graphql.Fields", t, func() {
fields := graphql.Fields{
"Pre1Name1": &graphql.Field{},
"Pre2Name2": &graphql.Field{},
}
prefixes := []string{"Pre1", "Pre2"}
newFields := replaceResolverPrefixes(prefixes, fields)
Convey("The matching prefixes in the given fields should have been replaced with an empty string", func() {
_, ok1 := newFields["Name1"]
_, ok2 := newFields["Name2"]
So(ok1, ShouldBeTrue)
So(ok2, ShouldBeTrue)
})
})
}
func TestValidateResolverArgument(t *testing.T) {
Convey("Given resolver arguments", t, func() {
fn := func() {}
Convey("In a Describer", func() {
rslvr, descr := validateResolverArgument(Describer{Value: fn, Description: "Test"})
Convey("It should return the resolver and the provided description", func() {
So(rslvr, ShouldEqual, fn)
So(descr, ShouldEqual, "Test")
})
})
Convey("Raw", func() {
rslvr, descr := validateResolverArgument(fn)
Convey("It should return the resolver and a empty description", func() {
So(rslvr, ShouldEqual, fn)
So(descr, ShouldEqual, "")
})
})
})
}
func TestGqlObjFallbackFactory(t *testing.T) {
Convey("Given a graphql.ObjectConfig", t, func() {
conf := structToGraphConfig(TStructForObjectConfigTest{})
fn := gqlObjFallbackFactory(conf)
Convey("It should return a cache setter function", func() {
Convey("And the setter should receive a new graphql.Object", func() {
obj := graphql.NewObject(conf)
setter := func(value interface{}) {
So(value, ShouldHaveSameTypeAs, obj)
So(value, ShouldNotBeNil)
}
fn(setter)
})
})
})
}
func TestMakeGraphQLObject(t *testing.T) {
Convey("Given a graphql.ObjectConfig", t, func() {
conf := structToGraphConfig(TStructForObjectConfigTest{})
Convey("In case the config name is empty", func() {
confCopy := conf
confCopy.Name = ""
obj := makeGraphQLObject(confCopy)
Convey("It should return nil", func() {
So(obj, ShouldBeNil)
})
})
Convey("In case the config name is set", func() {
obj := makeGraphQLObject(conf)
Convey("It should return a valid graphql.Object", func() {
So(obj, ShouldNotBeNil)
})
})
})
}