-
Notifications
You must be signed in to change notification settings - Fork 15
/
executor_test.go
51 lines (40 loc) · 1.05 KB
/
executor_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
package dqlx
import (
"encoding/json"
"testing"
"time"
"github.com/dgraph-io/dgo/v200/protos/api"
"github.com/stretchr/testify/require"
)
func UnmarshalTestHelper(name string, in interface{}, out interface{}) func(t *testing.T) {
return func(t *testing.T) {
var err error
r := Response{
Raw: &api.Response{},
dataKeyPath: name,
}
if r.dataKeyPath == "" {
r.Raw.Json, err = json.Marshal(in)
} else {
r.Raw.Json, err = json.Marshal(map[string]interface{}{name: in})
}
require.NoError(t, err)
err = r.Unmarshal(out)
require.NoError(t, err)
require.Equal(t, in, out)
}
}
func TestUnmarshal(t *testing.T) {
t.Helper()
// Test cases to ensure the DQL schema types are properly unmarshalled
// https://dgraph.io/docs/query-language/schema/#scalar-types
t.Run("dateTime", func(t *testing.T) {
t.Helper()
var out map[string]time.Time
in := map[string]time.Time{
"now": time.Now().UTC(),
}
t.Run("unnamed", UnmarshalTestHelper("", &in, &out))
t.Run("named", UnmarshalTestHelper("rootQuery", &in, &out))
})
}