为什么我会收到“无效的实体类型”与datastore.Put使用Go AppEngine aetest中的datastore.PropertyList? [英] Why do I get "invalid entity type" with datastore.Put using a datastore.PropertyList in a Go AppEngine aetest?
问题描述
此测试以 partnermerge_test.go:22:datastore:无效实体类型
$ b
This test fails with partnermerge_test.go:22: datastore: invalid entity type
package bigdipper
import (
"testing"
"appengine/aetest"
"appengine/datastore"
)
func TestCreateMigrationProposal(t *testing.T) {
c, err := aetest.NewContext(nil)
if err != nil {
t.Fatal(err)
}
defer c.Close()
if _, err := datastore.Put(
c,
datastore.NewKey(c, "ORDER", "order-id-1", 0, nil),
datastore.PropertyList{}); err != nil {
t.Fatal(err)
}
}
推荐答案
The docs for the datastore.Put function say:
Put将实体src以键k保存到数据存储中。 src必须是
结构指针或实现PropertyLoadSaver;如果一个结构指针
,那么该结构的任何未导出的字段都将被跳过。如果k是
不完整键,则返回的键将是由
数据存储区生成的唯一键。
Put saves the entity src into the datastore with key k. src must be a struct pointer or implement PropertyLoadSaver; if a struct pointer then any unexported fields of that struct will be skipped. If k is an incomplete key, the returned key will be a unique key generated by the datastore.
当试图将PropertyList作为 src
使用时,这有点令人困惑。 PropertyList不实现PropertyLoadSaver,但是* PropertyList的确。添加&在PropertyList之前得到一个指向它的指针修复了这个测试。
This was somewhat confusing when trying to use this with a PropertyList as the src
. A PropertyList does not implement PropertyLoadSaver, but a *PropertyList does. Adding an & before PropertyList to get a pointer to it fixes this test.
package bigdipper
import (
"testing"
"appengine/aetest"
"appengine/datastore"
)
func TestCreateMigrationProposal(t *testing.T) {
c, err := aetest.NewContext(nil)
if err != nil {
t.Fatal(err)
}
defer c.Close()
if _, err := datastore.Put(
c,
datastore.NewKey(c, "ORDER", "order-id-1", 0, nil),
&datastore.PropertyList{}); err != nil {
t.Fatal(err)
}
}
这篇关于为什么我会收到“无效的实体类型”与datastore.Put使用Go AppEngine aetest中的datastore.PropertyList?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!