[#5958] fixed RecordQuery() custom struct scanning
This commit is contained in:
@@ -66,7 +66,7 @@ func TestRecordQueryOne(t *testing.T) {
|
||||
name string
|
||||
collection string
|
||||
recordId string
|
||||
model core.Model
|
||||
model any
|
||||
}{
|
||||
{
|
||||
"record model",
|
||||
@@ -82,6 +82,14 @@ func TestRecordQueryOne(t *testing.T) {
|
||||
core.BaseRecordProxy
|
||||
}{},
|
||||
},
|
||||
{
|
||||
"custom struct",
|
||||
"demo1",
|
||||
"84nmscqy84lsi1t",
|
||||
&struct {
|
||||
Id string `db:"id" json:"id"`
|
||||
}{},
|
||||
},
|
||||
}
|
||||
|
||||
for _, s := range scenarios {
|
||||
@@ -98,8 +106,14 @@ func TestRecordQueryOne(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if s.model.PK() != s.recordId {
|
||||
t.Fatalf("Expected record with id %q, got %q", s.recordId, s.model.PK())
|
||||
raw, err := json.Marshal(s.model)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rawStr := string(raw)
|
||||
|
||||
if !strings.Contains(rawStr, fmt.Sprintf(`"id":%q`, s.recordId)) {
|
||||
t.Fatalf("Missing id %q in\n%s", s.recordId, rawStr)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -111,6 +125,10 @@ func TestRecordQueryAll(t *testing.T) {
|
||||
app, _ := tests.NewTestApp()
|
||||
defer app.Cleanup()
|
||||
|
||||
type customStructs struct {
|
||||
Id string `db:"id" json:"id"`
|
||||
}
|
||||
|
||||
type mockRecordProxy struct {
|
||||
core.BaseRecordProxy
|
||||
}
|
||||
@@ -145,6 +163,18 @@ func TestRecordQueryAll(t *testing.T) {
|
||||
[]any{"84nmscqy84lsi1t", "al1h9ijdeojtsjy"},
|
||||
&[]mockRecordProxy{},
|
||||
},
|
||||
{
|
||||
"slice of custom structs",
|
||||
"demo1",
|
||||
[]any{"84nmscqy84lsi1t", "al1h9ijdeojtsjy"},
|
||||
&[]customStructs{},
|
||||
},
|
||||
{
|
||||
"slice of pointer custom structs",
|
||||
"demo1",
|
||||
[]any{"84nmscqy84lsi1t", "al1h9ijdeojtsjy"},
|
||||
&[]customStructs{},
|
||||
},
|
||||
}
|
||||
|
||||
for _, s := range scenarios {
|
||||
|
||||
Reference in New Issue
Block a user