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

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

Issue 1259463002: Add BoolFlag for rawdatastore. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: rename to toggle Created 5 years, 5 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
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 rawdatastore 7 package rawdatastore
8 8
9 import ( 9 import (
10 "bytes" 10 "bytes"
(...skipping 1625 matching lines...) Expand 10 before | Expand all | Expand 10 after
1636 1636
1637 Convey("attempting to get a PLS for a non *struct is an error", func() { 1637 Convey("attempting to get a PLS for a non *struct is an error", func() {
1638 pls := GetPLS((*[]string)(nil)) 1638 pls := GetPLS((*[]string)(nil))
1639 So(pls.Problem(), ShouldEqual, ErrInvalidEntityType) 1639 So(pls.Problem(), ShouldEqual, ErrInvalidEntityType)
1640 }) 1640 })
1641 1641
1642 Convey("convertible meta default types", func() { 1642 Convey("convertible meta default types", func() {
1643 type OKDefaults struct { 1643 type OKDefaults struct {
1644 When string `gae:"$when,tomorrow"` 1644 When string `gae:"$when,tomorrow"`
1645 Amount int64 `gae:"$amt,100"` 1645 Amount int64 `gae:"$amt,100"`
1646 DoIt Toggle `gae:"$doit,on"`
1646 } 1647 }
1647 » » » pls := GetPLS(&OKDefaults{}) 1648 » » » okd := &OKDefaults{}
1649 » » » pls := GetPLS(okd)
1648 So(pls.Problem(), ShouldBeNil) 1650 So(pls.Problem(), ShouldBeNil)
1649 1651
1650 v, err := pls.GetMeta("when") 1652 v, err := pls.GetMeta("when")
1651 So(err, ShouldBeNil) 1653 So(err, ShouldBeNil)
1652 So(v, ShouldEqual, "tomorrow") 1654 So(v, ShouldEqual, "tomorrow")
1653 1655
1654 v, err = pls.GetMeta("amt") 1656 v, err = pls.GetMeta("amt")
1655 So(err, ShouldBeNil) 1657 So(err, ShouldBeNil)
1656 So(v, ShouldEqual, int64(100)) 1658 So(v, ShouldEqual, int64(100))
1659
1660 So(okd.DoIt, ShouldEqual, Auto)
1661 v, err = pls.GetMeta("doit")
1662 So(err, ShouldBeNil)
1663 So(v, ShouldBeTrue)
1664
1665 err = pls.SetMeta("doit", false)
1666 So(err, ShouldBeNil)
1667 v, err = pls.GetMeta("doit")
1668 So(err, ShouldBeNil)
1669 So(v, ShouldBeFalse)
1670 So(okd.DoIt, ShouldEqual, Off)
1671
1672 err = pls.SetMeta("doit", true)
1673 So(err, ShouldBeNil)
1674 v, err = pls.GetMeta("doit")
1675 So(err, ShouldBeNil)
1676 So(v, ShouldBeTrue)
1677 So(okd.DoIt, ShouldEqual, On)
1657 }) 1678 })
1658 1679
1659 Convey("meta fields can be saved", func() { 1680 Convey("meta fields can be saved", func() {
1660 type OKDefaults struct { 1681 type OKDefaults struct {
1661 When string `gae:"$when,tomorrow"` 1682 When string `gae:"$when,tomorrow"`
1662 Amount int64 `gae:"$amt,100"` 1683 Amount int64 `gae:"$amt,100"`
1663 } 1684 }
1664 pls := GetPLS(&OKDefaults{}) 1685 pls := GetPLS(&OKDefaults{})
1665 pm, err := pls.Save(true) 1686 pm, err := pls.Save(true)
1666 So(err, ShouldBeNil) 1687 So(err, ShouldBeNil)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1709 1730
1710 Convey("Bad default meta type", func() { 1731 Convey("Bad default meta type", func() {
1711 type BadDefault struct { 1732 type BadDefault struct {
1712 Val time.Time `gae:"$meta,tomorrow"` 1733 Val time.Time `gae:"$meta,tomorrow"`
1713 } 1734 }
1714 pls := GetPLS(&BadDefault{}) 1735 pls := GetPLS(&BadDefault{})
1715 So(pls.Problem().Error(), ShouldContainSubstring, "bad t ype") 1736 So(pls.Problem().Error(), ShouldContainSubstring, "bad t ype")
1716 }) 1737 })
1717 }) 1738 })
1718 } 1739 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698