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 1868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1879 v, err := mgs.GetMeta("val") | 1879 v, err := mgs.GetMeta("val") |
1880 So(err, ShouldBeNil) | 1880 So(err, ShouldBeNil) |
1881 So(v, ShouldEqual, int64(100)) | 1881 So(v, ShouldEqual, int64(100)) |
1882 | 1882 |
1883 o.Val = 10 | 1883 o.Val = 10 |
1884 v, err = mgs.GetMeta("val") | 1884 v, err = mgs.GetMeta("val") |
1885 So(err, ShouldBeNil) | 1885 So(err, ShouldBeNil) |
1886 So(v, ShouldEqual, int64(10)) | 1886 So(v, ShouldEqual, int64(10)) |
1887 }) | 1887 }) |
1888 | 1888 |
| 1889 Convey("Derived metadata fields", func() { |
| 1890 type DerivedString string |
| 1891 type DerivedInt int16 |
| 1892 type DerivedStruct struct { |
| 1893 ID DerivedString `gae:"$id"` |
| 1894 Foo DerivedInt `gae:"$foo"` |
| 1895 } |
| 1896 o := &DerivedStruct{"hello", 10} |
| 1897 mgs := getMGS(o) |
| 1898 v, err := mgs.GetMeta("id") |
| 1899 So(err, ShouldBeNil) |
| 1900 So(v, ShouldEqual, "hello") |
| 1901 |
| 1902 v, err = mgs.GetMeta("foo") |
| 1903 So(err, ShouldBeNil) |
| 1904 So(v, ShouldEqual, int64(10)) |
| 1905 |
| 1906 So(mgs.SetMeta("id", "nerds"), ShouldBeNil) |
| 1907 So(mgs.SetMeta("foo", 20), ShouldBeNil) |
| 1908 So(o.ID, ShouldEqual, DerivedString("nerds")) |
| 1909 So(o.Foo, ShouldEqual, DerivedInt(20)) |
| 1910 }) |
| 1911 |
1889 Convey("Bad default meta type", func() { | 1912 Convey("Bad default meta type", func() { |
1890 type BadDefault struct { | 1913 type BadDefault struct { |
1891 Val time.Time `gae:"$meta,tomorrow"` | 1914 Val time.Time `gae:"$meta,tomorrow"` |
1892 } | 1915 } |
1893 pls := GetPLS(&BadDefault{}) | 1916 pls := GetPLS(&BadDefault{}) |
1894 So(pls.Problem().Error(), ShouldContainSubstring, "bad t
ype") | 1917 So(pls.Problem().Error(), ShouldContainSubstring, "bad t
ype") |
1895 }) | 1918 }) |
1896 | 1919 |
1897 Convey("MetaGetterSetter implementation (IDParser)", func() { | 1920 Convey("MetaGetterSetter implementation (IDParser)", func() { |
1898 idp := &IDParser{parent: "moo", id: 100} | 1921 idp := &IDParser{parent: "moo", id: 100} |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1954 So(pls.SetMeta("id", "sup|1337"), ShouldBeNil) | 1977 So(pls.SetMeta("id", "sup|1337"), ShouldBeNil) |
1955 So(ide.EmbeddedID, ShouldResemble, EmbeddedID{"sup", 133
7}) | 1978 So(ide.EmbeddedID, ShouldResemble, EmbeddedID{"sup", 133
7}) |
1956 | 1979 |
1957 So(pls.GetAllMeta(), ShouldResembleV, PropertyMap{ | 1980 So(pls.GetAllMeta(), ShouldResembleV, PropertyMap{ |
1958 "$id": {mpNI("sup|1337")}, | 1981 "$id": {mpNI("sup|1337")}, |
1959 "$kind": {mpNI("IDEmbedder")}, | 1982 "$kind": {mpNI("IDEmbedder")}, |
1960 }) | 1983 }) |
1961 }) | 1984 }) |
1962 }) | 1985 }) |
1963 } | 1986 } |
OLD | NEW |