test(workitems): replace schema validation with exact query files
Summary
Implements step 1 (and steps 2-4) of #2272 (closed): replace the opt-in GraphQL schema validation with golden-file query matching that always runs in every environment including CI.
Problem
The existing loadSchema/validateSchema approach in workitems_test.go silently skips validation when schema/gitlab.graphql is absent (which is the case in most CI runs and local developer environments). The schema file had to be manually regenerated with an external tool (get-graphql-schema), which is not part of the standard make workflow.
Solution
Replace schema validation with exact query string matching using golden files stored in testdata/. Each file contains the exact GraphQL query string that the client is expected to produce for a given operation.
Changes
- Added golden
.graphqlfiles intestdata/for each query/mutation:testdata/query_get_work_item.graphqltestdata/query_get_work_item_id.graphqltestdata/query_list_work_items.graphqltestdata/query_list_work_item_types.graphqltestdata/mutation_create_work_item.graphqltestdata/mutation_update_work_item.graphqltestdata/mutation_delete_work_item.graphql
- Added
assertQueryMatches()helper that reads a golden file and asserts the received query matches it exactly (after whitespace trimming) - Updated test mock handlers to use
assertQueryMatches()for fixed-structure queries (GetWorkItem, CreateWorkItem, UpdateWorkItem, DeleteWorkItem, GetWorkItemID, ListWorkItemTypes) - Removed
loadSchema()andvalidateSchema()helpers - Removed
github.com/graph-gophers/graphql-godependency fromgo.mod/go.sum - Deleted
schema/gitlab.graphqland theschema/directory
Notes
The ListWorkItems query is dynamically built based on options (different options produce different query strings), so its handler does not use assertQueryMatches(). The existing TestBuildListWorkItemsQuery_* tests continue to verify its structure comprehensively.
Acceptance Criteria
-
schema/gitlab.graphqland theschema/directory are deleted - A golden
.graphqlfile exists intestdata/for each query or mutation the client produces - Each test's mock handler asserts the received query matches the corresponding golden file (for fixed-structure queries)
-
loadSchemaandvalidateSchemaare removed fromworkitems_test.go - The
github.com/graph-gophers/graphql-godependency is removed - Query validation is no longer opt-in — it runs in every environment including CI
Closes #2272 (closed)