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 .graphql files in testdata/ for each query/mutation:
    • testdata/query_get_work_item.graphql
    • testdata/query_get_work_item_id.graphql
    • testdata/query_list_work_items.graphql
    • testdata/query_list_work_item_types.graphql
    • testdata/mutation_create_work_item.graphql
    • testdata/mutation_update_work_item.graphql
    • testdata/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() and validateSchema() helpers
  • Removed github.com/graph-gophers/graphql-go dependency from go.mod/go.sum
  • Deleted schema/gitlab.graphql and the schema/ 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.graphql and the schema/ directory are deleted
  • A golden .graphql file exists in testdata/ 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)
  • loadSchema and validateSchema are removed from workitems_test.go
  • The github.com/graph-gophers/graphql-go dependency is removed
  • Query validation is no longer opt-in — it runs in every environment including CI

Closes #2272 (closed)

Merge request reports

Loading