@@ -8,6 +8,91 @@ import (
8
8
"github.com/graph-gophers/graphql-go/decode"
9
9
)
10
10
11
+ func TestNullID_ImplementsUnmarshaler (t * testing.T ) {
12
+ defer func () {
13
+ if err := recover (); err != nil {
14
+ t .Error (err )
15
+ }
16
+ }()
17
+
18
+ // assert *NullID implements decode.Unmarshaler interface
19
+ var _ decode.Unmarshaler = (* graphql .NullID )(nil )
20
+ }
21
+
22
+ func TestNullID_UnmarshalGraphQL (t * testing.T ) {
23
+ type args struct {
24
+ input interface {}
25
+ }
26
+
27
+ good := graphql .ID ("1234" )
28
+ ref := graphql.NullID {
29
+ Value : & good ,
30
+ Set : true ,
31
+ }
32
+
33
+ t .Run ("invalid" , func (t * testing.T ) {
34
+ tests := []struct {
35
+ name string
36
+ args args
37
+ wantErr string
38
+ }{
39
+ {
40
+ name : "boolean" ,
41
+ args : args {input : true },
42
+ wantErr : "wrong type for ID: bool" ,
43
+ },
44
+ {
45
+ name : "int" ,
46
+ args : args {input : 1 },
47
+ wantErr : "wrong type for ID: int" ,
48
+ },
49
+ }
50
+
51
+ for _ , tt := range tests {
52
+ t .Run (tt .name , func (t * testing.T ) {
53
+ gt := & graphql.NullID {}
54
+ if err := gt .UnmarshalGraphQL (tt .args .input ); err != nil {
55
+ if err .Error () != tt .wantErr {
56
+ t .Errorf ("UnmarshalGraphQL() error = %v, want = %s" , err , tt .wantErr )
57
+ }
58
+
59
+ return
60
+ }
61
+
62
+ t .Error ("UnmarshalGraphQL() expected error not raised" )
63
+ })
64
+ }
65
+ })
66
+
67
+ tests := []struct {
68
+ name string
69
+ args args
70
+ wantEq graphql.NullID
71
+ }{
72
+ {
73
+ name : "string" ,
74
+ args : args {
75
+ input : string (good ),
76
+ },
77
+ wantEq : ref ,
78
+ },
79
+ }
80
+
81
+ for _ , tt := range tests {
82
+ t .Run (tt .name , func (t * testing.T ) {
83
+ gt := new (graphql.NullID )
84
+ if err := gt .UnmarshalGraphQL (tt .args .input ); err != nil {
85
+ t .Errorf ("UnmarshalGraphQL() error = %v" , err )
86
+ return
87
+ }
88
+
89
+ if * gt .Value != * tt .wantEq .Value {
90
+ t .Errorf ("UnmarshalGraphQL() got = %v, want = %v" , * gt .Value , * tt .wantEq .Value )
91
+ }
92
+ })
93
+ }
94
+ }
95
+
11
96
func TestNullInt_ImplementsUnmarshaler (t * testing.T ) {
12
97
defer func () {
13
98
if err := recover (); err != nil {
0 commit comments