MCPcopy
hub / github.com/dgraph-io/dgraph / TestCustomHTTPQuery

Function TestCustomHTTPQuery

graphql/resolve/query_test.go:127–164  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

125}
126
127func TestCustomHTTPQuery(t *testing.T) {
128 b, err := os.ReadFile("custom_query_test.yaml")
129 require.NoError(t, err, "Unable to read test file")
130
131 var tests []HTTPRewritingCase
132 err = yaml.Unmarshal(b, &tests)
133 require.NoError(t, err, "Unable to unmarshal tests to yaml.")
134
135 gqlSchema := test.LoadSchemaFromFile(t, "schema.graphql")
136
137 for _, tcase := range tests {
138 t.Run(tcase.Name, func(t *testing.T) {
139 var vars map[string]interface{}
140 if tcase.Variables != "" {
141 require.NoError(t, json.Unmarshal([]byte(tcase.Variables), &vars))
142 }
143
144 op, err := gqlSchema.Operation(
145 &schema.Request{
146 Query: tcase.GQLQuery,
147 Variables: vars,
148 Header: map[string][]string{
149 "bogus": {"header"},
150 "X-App-Token": {"val"},
151 "Auth0-Token": {"tok"},
152 },
153 })
154 require.NoError(t, err)
155 gqlQuery := test.GetQuery(t, op)
156
157 client := newClient(t, tcase)
158 resolver := NewHTTPQueryResolver(client)
159 resolved := resolver.Resolve(context.Background(), gqlQuery)
160
161 testutil.CompareJSON(t, tcase.ResolvedResponse, string(resolved.Data))
162 })
163 }
164}

Callers

nothing calls this directly

Calls 8

LoadSchemaFromFileFunction · 0.92
GetQueryFunction · 0.92
CompareJSONFunction · 0.92
NewHTTPQueryResolverFunction · 0.85
newClientFunction · 0.70
OperationMethod · 0.65
ResolveMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected