Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Unified Diff: service/datastore/datastore_test.go

Issue 1867963003: Add PopulateKey method to datastore. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/gae@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « service/datastore/datastore.go ('k') | service/datastore/multiarg.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: service/datastore/datastore_test.go
diff --git a/service/datastore/datastore_test.go b/service/datastore/datastore_test.go
index c745b675786f75c1d1cb371dcc5804cc74dc1c4b..48d5f85c069b3c2aac65bb0f062a3c25a724cda5 100644
--- a/service/datastore/datastore_test.go
+++ b/service/datastore/datastore_test.go
@@ -142,6 +142,10 @@ func (f *permaBad) Load(pm PropertyMap) error {
return errors.New("permaBad")
}
+type SingletonStruct struct {
+ id int64 `gae:"$id,1"`
+}
+
type FakePLS struct {
IntID int64
StringID string
@@ -377,6 +381,40 @@ func TestKeyForObj(t *testing.T) {
})
}
+func TestPopulateKey(t *testing.T) {
+ t.Parallel()
+
+ Convey("Test PopulateKey", t, func() {
+ k := NewKey("app", "namespace", "kind", "", 1337, nil)
+
+ Convey("Can set the key of a common struct.", func() {
+ var cs CommonStruct
+
+ PopulateKey(&cs, k)
+ So(cs.ID, ShouldEqual, 1337)
+ })
+
+ Convey("Will not set the value of a singleton struct.", func() {
+ var ss SingletonStruct
+
+ PopulateKey(&ss, k)
+ So(ss.id, ShouldEqual, 0)
+ })
+
+ Convey("Will panic when setting the key of a bad struct.", func() {
+ var bs badStruct
+
+ So(func() { PopulateKey(&bs, k) }, ShouldPanic)
+ })
+
+ Convey("Will panic when setting the key of a broken PLS struct.", func() {
+ var broken permaBad
+
+ So(func() { PopulateKey(&broken, k) }, ShouldPanic)
+ })
+ })
+}
+
func TestPut(t *testing.T) {
t.Parallel()
« no previous file with comments | « service/datastore/datastore.go ('k') | service/datastore/multiarg.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698