本文介绍了为什么我会收到“无效的实体类型”与datastore.Put使用Go AppEngine aetest中的datastore.PropertyList?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此测试以 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:
当试图将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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!