(t *testing.T)
| 35 | } |
| 36 | |
| 37 | func TestQueryRewriting(t *testing.T) { |
| 38 | b, err := os.ReadFile("query_test.yaml") |
| 39 | require.NoError(t, err, "Unable to read test file") |
| 40 | |
| 41 | var tests []QueryRewritingCase |
| 42 | err = yaml.Unmarshal(b, &tests) |
| 43 | require.NoError(t, err, "Unable to unmarshal tests to yaml.") |
| 44 | |
| 45 | gqlSchema := test.LoadSchemaFromFile(t, "schema.graphql") |
| 46 | |
| 47 | testRewriter := NewQueryRewriter() |
| 48 | |
| 49 | for _, tcase := range tests { |
| 50 | t.Run(tcase.Name, func(t *testing.T) { |
| 51 | var vars map[string]interface{} |
| 52 | if tcase.GQLVariables != "" { |
| 53 | require.NoError(t, json.Unmarshal([]byte(tcase.GQLVariables), &vars)) |
| 54 | } |
| 55 | op, err := gqlSchema.Operation( |
| 56 | &schema.Request{ |
| 57 | Query: tcase.GQLQuery, |
| 58 | Variables: vars, |
| 59 | }) |
| 60 | require.NoError(t, err) |
| 61 | gqlQuery := test.GetQuery(t, op) |
| 62 | |
| 63 | dgQuery, dgVars, err := testRewriter.Rewrite(context.Background(), gqlQuery) |
| 64 | require.NoError(t, err) |
| 65 | require.Equal(t, tcase.DGQuery, dgraph.AsString(dgQuery)) |
| 66 | if len(tcase.DGVars) == 0 { |
| 67 | require.Empty(t, dgVars) |
| 68 | } else { |
| 69 | require.Equal(t, tcase.DGVars, dgVars) |
| 70 | } |
| 71 | }) |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | type HTTPRewritingCase struct { |
| 76 | Name string |
nothing calls this directly
no test coverage detected