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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « service/datastore/datastore.go ('k') | service/datastore/multiarg.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // adapted from github.com/golang/appengine/datastore 5 // adapted from github.com/golang/appengine/datastore
6 6
7 package datastore 7 package datastore
8 8
9 import ( 9 import (
10 "bytes" 10 "bytes"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 } 135 }
136 136
137 type permaBad struct { 137 type permaBad struct {
138 PropertyLoadSaver 138 PropertyLoadSaver
139 } 139 }
140 140
141 func (f *permaBad) Load(pm PropertyMap) error { 141 func (f *permaBad) Load(pm PropertyMap) error {
142 return errors.New("permaBad") 142 return errors.New("permaBad")
143 } 143 }
144 144
145 type SingletonStruct struct {
146 id int64 `gae:"$id,1"`
147 }
148
145 type FakePLS struct { 149 type FakePLS struct {
146 IntID int64 150 IntID int64
147 StringID string 151 StringID string
148 Kind string 152 Kind string
149 153
150 Value int64 154 Value int64
151 gotLoaded bool 155 gotLoaded bool
152 156
153 failGetMeta bool 157 failGetMeta bool
154 failLoad bool 158 failLoad bool
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 NonSerializableField complex64 374 NonSerializableField complex64
371 } 375 }
372 376
373 So(func() { ds.KeyForObjErr(&BadObj{ID: 1}) }, S houldPanicLike, 377 So(func() { ds.KeyForObjErr(&BadObj{ID: 1}) }, S houldPanicLike,
374 `field "NonSerializableField" has invali d type: complex64`) 378 `field "NonSerializableField" has invali d type: complex64`)
375 }) 379 })
376 }) 380 })
377 }) 381 })
378 } 382 }
379 383
384 func TestPopulateKey(t *testing.T) {
385 t.Parallel()
386
387 Convey("Test PopulateKey", t, func() {
388 k := NewKey("app", "namespace", "kind", "", 1337, nil)
389
390 Convey("Can set the key of a common struct.", func() {
391 var cs CommonStruct
392
393 PopulateKey(&cs, k)
394 So(cs.ID, ShouldEqual, 1337)
395 })
396
397 Convey("Will not set the value of a singleton struct.", func() {
398 var ss SingletonStruct
399
400 PopulateKey(&ss, k)
401 So(ss.id, ShouldEqual, 0)
402 })
403
404 Convey("Will panic when setting the key of a bad struct.", func( ) {
405 var bs badStruct
406
407 So(func() { PopulateKey(&bs, k) }, ShouldPanic)
408 })
409
410 Convey("Will panic when setting the key of a broken PLS struct." , func() {
411 var broken permaBad
412
413 So(func() { PopulateKey(&broken, k) }, ShouldPanic)
414 })
415 })
416 }
417
380 func TestPut(t *testing.T) { 418 func TestPut(t *testing.T) {
381 t.Parallel() 419 t.Parallel()
382 420
383 Convey("Test Put/PutMulti", t, func() { 421 Convey("Test Put/PutMulti", t, func() {
384 c := info.Set(context.Background(), fakeInfo{}) 422 c := info.Set(context.Background(), fakeInfo{})
385 c = SetRawFactory(c, fakeDatastoreFactory) 423 c = SetRawFactory(c, fakeDatastoreFactory)
386 ds := Get(c) 424 ds := Get(c)
387 425
388 Convey("bad", func() { 426 Convey("bad", func() {
389 Convey("static can't serialize", func() { 427 Convey("static can't serialize", func() {
(...skipping 1149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1539 if err != nil { 1577 if err != nil {
1540 panic(fmt.Errorf("failed to find absolute path f or `%s`", sameLevelDir)) 1578 panic(fmt.Errorf("failed to find absolute path f or `%s`", sameLevelDir))
1541 } 1579 }
1542 1580
1543 ids, err := FindAndParseIndexYAML(abs) 1581 ids, err := FindAndParseIndexYAML(abs)
1544 So(err, ShouldBeNil) 1582 So(err, ShouldBeNil)
1545 So(ids[1].Kind, ShouldEqual, "Test Foo") 1583 So(ids[1].Kind, ShouldEqual, "Test Foo")
1546 }) 1584 })
1547 }) 1585 })
1548 } 1586 }
OLDNEW
« 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