Skip to content

Commit

Permalink
test(datastore): add scenarios around flattening first and last struc…
Browse files Browse the repository at this point in the history
…t fields (#5064)
  • Loading branch information
crwilcox committed Nov 2, 2021
1 parent 88a1cdb commit cbd5c8c
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion datastore/datastore_test.go
Expand Up @@ -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
Expand Down Expand Up @@ -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\"",
"",
},
{
Expand Down

0 comments on commit cbd5c8c

Please sign in to comment.