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

Side by Side Diff: service/datastore/datastore_test.go

Issue 1523943002: Fix nil-deref panic from Put. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: Created 5 years 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') | no next file » | 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 "fmt" 10 "fmt"
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 407
408 Convey("put with non-modifyable type is an error", func( ) { 408 Convey("put with non-modifyable type is an error", func( ) {
409 cs := CommonStruct{} 409 cs := CommonStruct{}
410 So(ds.Put(cs), ShouldErrLike, "invalid Put input type") 410 So(ds.Put(cs), ShouldErrLike, "invalid Put input type")
411 }) 411 })
412 412
413 Convey("struct with no $kind is an error", func() { 413 Convey("struct with no $kind is an error", func() {
414 s := MGSWithNoKind{} 414 s := MGSWithNoKind{}
415 So(ds.Put(&s), ShouldErrLike, "unable to extract $kind") 415 So(ds.Put(&s), ShouldErrLike, "unable to extract $kind")
416 }) 416 })
417
418 Convey("struct with invalid but non-nil key is an error" , func() {
419 type BadParent struct {
420 ID int64 `gae:"$id"`
421 Parent *Key `gae:"$parent"`
422 }
423 // having an Incomplete parent makes an invalid key
424 bp := &BadParent{ID: 1, Parent: ds.MakeKey("Some thing", 0)}
425 So(ds.Put(bp), ShouldErrLike, ErrInvalidKey)
426 })
417 }) 427 })
418 428
419 Convey("ok", func() { 429 Convey("ok", func() {
420 Convey("[]S", func() { 430 Convey("[]S", func() {
421 css := make([]CommonStruct, 7) 431 css := make([]CommonStruct, 7)
422 for i := range css { 432 for i := range css {
423 if i == 4 { 433 if i == 4 {
424 css[i].ID = 200 434 css[i].ID = 200
425 } 435 }
426 css[i].Value = int64(i) 436 css[i].Value = int64(i)
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 Convey("extra field with bad type", func() { 1263 Convey("extra field with bad type", func() {
1254 type Bad struct { 1264 type Bad struct {
1255 A int64 `gae:",extra"` 1265 A int64 `gae:",extra"`
1256 } 1266 }
1257 So(func() { GetPLS(&Bad{}) }, ShouldPanicLike, 1267 So(func() { GetPLS(&Bad{}) }, ShouldPanicLike,
1258 "struct 'extra' field has invalid type i nt64") 1268 "struct 'extra' field has invalid type i nt64")
1259 }) 1269 })
1260 }) 1270 })
1261 }) 1271 })
1262 } 1272 }
OLDNEW
« no previous file with comments | « service/datastore/datastore.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698