Skip to content

Conversation

@hemanta212
Copy link
Contributor

Problem

Mocks currently return a slice with a single zero/nil-value result when all expected outputs are null (the "not found" case). Service code that checks len(results) == 0 fails.

Solution

In Go mock codegen, detect test cases where all output fields are explicitly null and emit an empty slice return for slice-returning result structs.

Changes

  • language/go/mock.go: return []*Result{} when ReturnsSlice and all outputs are null
  • language/go/mock.go: factor output lookup for reuse in null detection
  • language/go/mock_test.go: add regression test for all-null output → empty slice

When a variable is bound via OPTIONAL MATCH, its properties can be null
even if the schema marks them as required. This change tracks whether
each binding came from OPTIONAL MATCH and uses that to force
Required=false for return fields from optional bindings.

Changes:
- Add 'optional' bool field to variableBinding struct
- Pass optional flag through extractBindings* functions
- Update lookupFieldFromExpression to return binding for optional check
- Force Required=false when binding.optional is true
Complex expressions (functions, arithmetic, CASE, aggregates, etc.)
now default to nullable (Required: false) since we can't statically
determine if they might return null.

Only simple 'variable.property' patterns on non-optional bindings will
use the schema's Required field.

Changes:
- Flip default from required=true to required=false in extractProjectionItem
- 7 new test cases for bailout patterns (function, CASE, aggregate, list index, chained access)
- Update existing tests to expect conservative behavior
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant