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

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: improve error 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
« no previous file with comments | « service/rawdatastore/datastore_impl.go ('k') | service/rawdatastore/properties.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 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)
1678
1679 Convey("Toggle fields REQUIRE a default", func() {
1680 type BadToggle struct {
1681 Bad Toggle `gae:"$wut"`
1682 }
1683 pls := GetPLS(&BadToggle{})
1684 So(pls.Problem().Error(), ShouldContainSubstring , "bad/missing default")
1685 })
1657 }) 1686 })
1658 1687
1659 Convey("meta fields can be saved", func() { 1688 Convey("meta fields can be saved", func() {
1660 type OKDefaults struct { 1689 type OKDefaults struct {
1661 When string `gae:"$when,tomorrow"` 1690 When string `gae:"$when,tomorrow"`
1662 Amount int64 `gae:"$amt,100"` 1691 Amount int64 `gae:"$amt,100"`
1663 } 1692 }
1664 pls := GetPLS(&OKDefaults{}) 1693 pls := GetPLS(&OKDefaults{})
1665 pm, err := pls.Save(true) 1694 pm, err := pls.Save(true)
1666 So(err, ShouldBeNil) 1695 So(err, ShouldBeNil)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1709 1738
1710 Convey("Bad default meta type", func() { 1739 Convey("Bad default meta type", func() {
1711 type BadDefault struct { 1740 type BadDefault struct {
1712 Val time.Time `gae:"$meta,tomorrow"` 1741 Val time.Time `gae:"$meta,tomorrow"`
1713 } 1742 }
1714 pls := GetPLS(&BadDefault{}) 1743 pls := GetPLS(&BadDefault{})
1715 So(pls.Problem().Error(), ShouldContainSubstring, "bad t ype") 1744 So(pls.Problem().Error(), ShouldContainSubstring, "bad t ype")
1716 }) 1745 })
1717 }) 1746 })
1718 } 1747 }
OLDNEW
« no previous file with comments | « service/rawdatastore/datastore_impl.go ('k') | service/rawdatastore/properties.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698