From cbd5c8c0ad33142a2031762037f594017c4fdade Mon Sep 17 00:00:00 2001 From: Christopher Wilcox Date: Tue, 2 Nov 2021 16:05:05 -0700 Subject: [PATCH] test(datastore): add scenarios around flattening first and last struct fields (#5064) --- datastore/datastore_test.go | 38 ++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/datastore/datastore_test.go b/datastore/datastore_test.go index caf5cbe3e14..99b99edbaab 100644 --- a/datastore/datastore_test.go +++ b/datastore/datastore_test.go @@ -395,6 +395,16 @@ type SliceOfSlices struct { } `datastore:",flatten"` } +type LastFlattened struct { + Bs []struct{ IDs []string } + A struct{ T time.Time } `datastore:",flatten"` +} + +type FirstFlattened struct { + A struct{ T time.Time } `datastore:",flatten"` + Bs []struct{ IDs []string } +} + type Recursive struct { I int R []Recursive @@ -1850,11 +1860,37 @@ var testCases = []testCase{ "", "", }, + { + "last field flattened", + &LastFlattened{}, + &LastFlattened{}, + "", + "", + }, + { + // Request/Bug: https://github.com/googleapis/google-cloud-go/issues/5026 + // User expected this to work as it worked when the last field. (above test) + "first field flattened", + &FirstFlattened{}, + nil, + "flattening nested structs leads to a slice of slices: field \"IDs\"", + "", + }, { "slice of slices", &SliceOfSlices{}, nil, - "flattening nested structs leads to a slice of slices", + "flattening nested structs leads to a slice of slices: field \"F\"", + "", + }, + { + "slice of slices, non-defaults", + &SliceOfSlices{I: 1, S: []struct { + J int + F []float64 + }{{J: 2, F: []float64{3.4, 5.6}}}}, + nil, + "flattening nested structs leads to a slice of slices: field \"F\"", "", }, {