Skip to content

test: verify array of struct decoding using DecodeOptionProto#835

Open
olavloite wants to merge 5 commits into
mainfrom
fix/309-array-of-struct-test
Open

test: verify array of struct decoding using DecodeOptionProto#835
olavloite wants to merge 5 commits into
mainfrom
fix/309-array-of-struct-test

Conversation

@olavloite

@olavloite olavloite commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Adds TestArrayOfStruct to verify that arrays of structs can be decoded using the spannerdriver.ExecOptions{DecodeOption: spannerdriver.DecodeOptionProto} option and scanning into a spanner.GenericColumnValue.

Fixes #309

@olavloite olavloite requested a review from a team as a code owner June 11, 2026 17:41

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a new integration test, TestArrayOfStruct, to verify querying and decoding an array of structs. The review feedback suggests using cmp.Diff instead of reflect.DeepEqual to compare the results, which provides a clearer, field-by-field diff in case of test failures.

Comment on lines +6112 to +6114
if !reflect.DeepEqual(allEntries, expected) {
t.Errorf("allEntries mismatch\n Got: %+v\nWant: %+v", allEntries, expected)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using reflect.DeepEqual on slices of pointers (like []*Entry) will print pointer addresses (e.g., 0xc000...) instead of the actual struct values in the test failure output, making debugging difficult. Since github.com/google/go-cmp/cmp is already imported and used in this file, using cmp.Diff is more idiomatic and provides a readable, field-by-field diff of the mismatch.

Suggested change
if !reflect.DeepEqual(allEntries, expected) {
t.Errorf("allEntries mismatch\n Got: %+v\nWant: %+v", allEntries, expected)
}
if diff := cmp.Diff(expected, allEntries); diff != "" {
t.Errorf("allEntries mismatch (-want +got):\n%s", diff)
}

@olavloite

Copy link
Copy Markdown
Collaborator Author

LGTM. The test verifies that complex arrays of structs can be parsed and decoded into custom Go structs using GenericColumnValue and DecodeOptionProto.

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.

Unable to scan into an array of struct

1 participant