OLD | NEW |
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 1730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1741 So(pls.Problem(), ShouldEqual, ErrInvalidEntityType) | 1741 So(pls.Problem(), ShouldEqual, ErrInvalidEntityType) |
1742 | 1742 |
1743 Convey("the error PLS can still be used", func() { | 1743 Convey("the error PLS can still be used", func() { |
1744 k, _ := pls.GetMeta("kind") | 1744 k, _ := pls.GetMeta("kind") |
1745 So(k, ShouldBeNil) | 1745 So(k, ShouldBeNil) |
1746 | 1746 |
1747 props := pls.GetAllMeta() | 1747 props := pls.GetAllMeta() |
1748 So(props, ShouldResemble, PropertyMap{ | 1748 So(props, ShouldResemble, PropertyMap{ |
1749 "$kind": []Property{mpNI("")}, | 1749 "$kind": []Property{mpNI("")}, |
1750 }) | 1750 }) |
| 1751 |
| 1752 _, err := pls.Save(true) |
| 1753 So(err, ShouldNotBeNil) |
1751 }) | 1754 }) |
1752 }) | 1755 }) |
1753 | 1756 |
1754 Convey("convertible meta default types", func() { | 1757 Convey("convertible meta default types", func() { |
1755 type OKDefaults struct { | 1758 type OKDefaults struct { |
1756 When string `gae:"$when,tomorrow"` | 1759 When string `gae:"$when,tomorrow"` |
1757 Amount int64 `gae:"$amt,100"` | 1760 Amount int64 `gae:"$amt,100"` |
1758 DoIt Toggle `gae:"$doit,on"` | 1761 DoIt Toggle `gae:"$doit,on"` |
1759 } | 1762 } |
1760 okd := &OKDefaults{} | 1763 okd := &OKDefaults{} |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1864 So(mgs.GetMetaDefault("id", ""), ShouldEqual, "moo|100") | 1867 So(mgs.GetMetaDefault("id", ""), ShouldEqual, "moo|100") |
1865 So(mgs.GetMetaDefault("kind", ""), ShouldEqual, "CoolKin
d") | 1868 So(mgs.GetMetaDefault("kind", ""), ShouldEqual, "CoolKin
d") |
1866 | 1869 |
1867 So(mgs.SetMeta("kind", "Something"), ShouldErrLike, "une
xported field") | 1870 So(mgs.SetMeta("kind", "Something"), ShouldErrLike, "une
xported field") |
1868 So(mgs.SetMeta("id", "happy|27"), ShouldBeNil) | 1871 So(mgs.SetMeta("id", "happy|27"), ShouldBeNil) |
1869 | 1872 |
1870 So(idp.parent, ShouldEqual, "happy") | 1873 So(idp.parent, ShouldEqual, "happy") |
1871 So(idp.id, ShouldEqual, 27) | 1874 So(idp.id, ShouldEqual, 27) |
1872 | 1875 |
1873 So(mgs.GetAllMeta(), ShouldResemble, PropertyMap{ | 1876 So(mgs.GetAllMeta(), ShouldResemble, PropertyMap{ |
1874 » » » » "$id": {MkPropertyNI("happy|27")}, | 1877 » » » » "$id": {mpNI("happy|27")}, |
1875 » » » » "$kind": {MkPropertyNI("CoolKind")}, | 1878 » » » » "$kind": {mpNI("CoolKind")}, |
1876 }) | 1879 }) |
1877 }) | 1880 }) |
1878 | 1881 |
1879 Convey("MetaGetterSetter implementation (KindOverride)", func()
{ | 1882 Convey("MetaGetterSetter implementation (KindOverride)", func()
{ |
1880 ko := &KindOverride{ID: 20} | 1883 ko := &KindOverride{ID: 20} |
1881 mgs := getMGS(ko) | 1884 mgs := getMGS(ko) |
1882 So(mgs.GetMetaDefault("kind", ""), ShouldEqual, "KindOve
rride") | 1885 So(mgs.GetMetaDefault("kind", ""), ShouldEqual, "KindOve
rride") |
1883 | 1886 |
1884 ko.customKind = "something" | 1887 ko.customKind = "something" |
1885 So(mgs.GetMetaDefault("kind", ""), ShouldEqual, "somethi
ng") | 1888 So(mgs.GetMetaDefault("kind", ""), ShouldEqual, "somethi
ng") |
1886 | 1889 |
1887 So(mgs.SetMeta("kind", "Nerp"), ShouldBeNil) | 1890 So(mgs.SetMeta("kind", "Nerp"), ShouldBeNil) |
1888 So(ko.customKind, ShouldEqual, "Nerp") | 1891 So(ko.customKind, ShouldEqual, "Nerp") |
1889 | 1892 |
1890 So(mgs.SetMeta("kind", "KindOverride"), ShouldBeNil) | 1893 So(mgs.SetMeta("kind", "KindOverride"), ShouldBeNil) |
1891 So(ko.customKind, ShouldEqual, "") | 1894 So(ko.customKind, ShouldEqual, "") |
1892 | 1895 |
1893 So(mgs.GetAllMeta(), ShouldResemble, PropertyMap{ | 1896 So(mgs.GetAllMeta(), ShouldResemble, PropertyMap{ |
1894 » » » » "$id": {MkPropertyNI(20)}, | 1897 » » » » "$id": {mpNI(20)}, |
1895 » » » » "$kind": {MkPropertyNI("KindOverride")}, | 1898 » » » » "$kind": {mpNI("KindOverride")}, |
1896 }) | 1899 }) |
1897 ko.customKind = "wut" | 1900 ko.customKind = "wut" |
1898 So(mgs.GetAllMeta(), ShouldResemble, PropertyMap{ | 1901 So(mgs.GetAllMeta(), ShouldResemble, PropertyMap{ |
1899 » » » » "$id": {MkPropertyNI(20)}, | 1902 » » » » "$id": {mpNI(20)}, |
1900 » » » » "$kind": {MkPropertyNI("wut")}, | 1903 » » » » "$kind": {mpNI("wut")}, |
| 1904 » » » }) |
| 1905 |
| 1906 » » » props, err := GetPLS(ko).Save(true) |
| 1907 » » » So(err, ShouldBeNil) |
| 1908 » » » So(props, ShouldResemble, PropertyMap{ |
| 1909 » » » » "$id": {mpNI(20)}, |
| 1910 » » » » "$kind": {mpNI("wut")}, |
1901 }) | 1911 }) |
1902 }) | 1912 }) |
1903 }) | 1913 }) |
1904 } | 1914 } |
OLD | NEW |