| 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 1072 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1083 | 1083 |
| 1084 Convey("Unless you have an ,extra field!", func() { | 1084 Convey("Unless you have an ,extra field!", func() { |
| 1085 type Val struct { | 1085 type Val struct { |
| 1086 ID int64 `gae:"$id"` | 1086 ID int64 `gae:"$id"` |
| 1087 | 1087 |
| 1088 Val int64 | 1088 Val int64 |
| 1089 Extra PropertyMap `gae:",extra"` | 1089 Extra PropertyMap `gae:",extra"` |
| 1090 } | 1090 } |
| 1091 tv := &Val{ID: 10} | 1091 tv := &Val{ID: 10} |
| 1092 So(ds.Get(tv), ShouldBeNil) | 1092 So(ds.Get(tv), ShouldBeNil) |
| 1093 » » » » So(tv, ShouldResembleV, &Val{ | 1093 » » » » So(tv, ShouldResemble, &Val{ |
| 1094 ID: 10, | 1094 ID: 10, |
| 1095 Val: 100, | 1095 Val: 100, |
| 1096 Extra: PropertyMap{ | 1096 Extra: PropertyMap{ |
| 1097 "TwoVal": {mp(200)}, | 1097 "TwoVal": {mp(200)}, |
| 1098 }, | 1098 }, |
| 1099 }) | 1099 }) |
| 1100 }) | 1100 }) |
| 1101 }) | 1101 }) |
| 1102 | 1102 |
| 1103 Convey("Can round-trip extra fields", func() { | 1103 Convey("Can round-trip extra fields", func() { |
| 1104 type Expando struct { | 1104 type Expando struct { |
| 1105 ID int64 `gae:"$id"` | 1105 ID int64 `gae:"$id"` |
| 1106 | 1106 |
| 1107 Something int | 1107 Something int |
| 1108 Extra PropertyMap `gae:",extra"` | 1108 Extra PropertyMap `gae:",extra"` |
| 1109 } | 1109 } |
| 1110 ex := &Expando{10, 17, PropertyMap{ | 1110 ex := &Expando{10, 17, PropertyMap{ |
| 1111 "Hello": {mp("Hello")}, | 1111 "Hello": {mp("Hello")}, |
| 1112 "World": {mp(true)}, | 1112 "World": {mp(true)}, |
| 1113 }} | 1113 }} |
| 1114 So(ds.Put(ex), ShouldBeNil) | 1114 So(ds.Put(ex), ShouldBeNil) |
| 1115 | 1115 |
| 1116 ex = &Expando{ID: 10} | 1116 ex = &Expando{ID: 10} |
| 1117 So(ds.Get(ex), ShouldBeNil) | 1117 So(ds.Get(ex), ShouldBeNil) |
| 1118 » » » So(ex, ShouldResembleV, &Expando{ | 1118 » » » So(ex, ShouldResemble, &Expando{ |
| 1119 ID: 10, | 1119 ID: 10, |
| 1120 Something: 17, | 1120 Something: 17, |
| 1121 Extra: PropertyMap{ | 1121 Extra: PropertyMap{ |
| 1122 "Hello": {mp("Hello")}, | 1122 "Hello": {mp("Hello")}, |
| 1123 "World": {mp(true)}, | 1123 "World": {mp(true)}, |
| 1124 }, | 1124 }, |
| 1125 }) | 1125 }) |
| 1126 }) | 1126 }) |
| 1127 | 1127 |
| 1128 Convey("Can read-but-not-write", func() { | 1128 Convey("Can read-but-not-write", func() { |
| 1129 initial := PropertyMap{ | 1129 initial := PropertyMap{ |
| 1130 "$key": {mpNI(ds.MakeKey("Convert", 10))}, | 1130 "$key": {mpNI(ds.MakeKey("Convert", 10))}, |
| 1131 "Val": {mp(100)}, | 1131 "Val": {mp(100)}, |
| 1132 "TwoVal": {mp(200)}, | 1132 "TwoVal": {mp(200)}, |
| 1133 } | 1133 } |
| 1134 So(ds.Put(initial), ShouldBeNil) | 1134 So(ds.Put(initial), ShouldBeNil) |
| 1135 type Convert struct { | 1135 type Convert struct { |
| 1136 ID int64 `gae:"$id"` | 1136 ID int64 `gae:"$id"` |
| 1137 | 1137 |
| 1138 Val int64 | 1138 Val int64 |
| 1139 NewVal int64 | 1139 NewVal int64 |
| 1140 Extra PropertyMap `gae:"-,extra"` | 1140 Extra PropertyMap `gae:"-,extra"` |
| 1141 } | 1141 } |
| 1142 c := &Convert{ID: 10} | 1142 c := &Convert{ID: 10} |
| 1143 So(ds.Get(c), ShouldBeNil) | 1143 So(ds.Get(c), ShouldBeNil) |
| 1144 » » » So(c, ShouldResembleV, &Convert{ | 1144 » » » So(c, ShouldResemble, &Convert{ |
| 1145 ID: 10, Val: 100, NewVal: 0, Extra: PropertyMap{
"TwoVal": {mp(200)}}, | 1145 ID: 10, Val: 100, NewVal: 0, Extra: PropertyMap{
"TwoVal": {mp(200)}}, |
| 1146 }) | 1146 }) |
| 1147 c.NewVal = c.Extra["TwoVal"][0].Value().(int64) | 1147 c.NewVal = c.Extra["TwoVal"][0].Value().(int64) |
| 1148 So(ds.Put(c), ShouldBeNil) | 1148 So(ds.Put(c), ShouldBeNil) |
| 1149 | 1149 |
| 1150 c = &Convert{ID: 10} | 1150 c = &Convert{ID: 10} |
| 1151 So(ds.Get(c), ShouldBeNil) | 1151 So(ds.Get(c), ShouldBeNil) |
| 1152 » » » So(c, ShouldResembleV, &Convert{ | 1152 » » » So(c, ShouldResemble, &Convert{ |
| 1153 ID: 10, Val: 100, NewVal: 200, Extra: nil, | 1153 ID: 10, Val: 100, NewVal: 200, Extra: nil, |
| 1154 }) | 1154 }) |
| 1155 }) | 1155 }) |
| 1156 | 1156 |
| 1157 Convey("Can black hole", func() { | 1157 Convey("Can black hole", func() { |
| 1158 initial := PropertyMap{ | 1158 initial := PropertyMap{ |
| 1159 "$key": {mpNI(ds.MakeKey("BlackHole", 10))}, | 1159 "$key": {mpNI(ds.MakeKey("BlackHole", 10))}, |
| 1160 "Val": {mp(100)}, | 1160 "Val": {mp(100)}, |
| 1161 "TwoVal": {mp(200)}, | 1161 "TwoVal": {mp(200)}, |
| 1162 } | 1162 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1179 } | 1179 } |
| 1180 So(ds.Put(initial), ShouldBeNil) | 1180 So(ds.Put(initial), ShouldBeNil) |
| 1181 | 1181 |
| 1182 type IntChange struct { | 1182 type IntChange struct { |
| 1183 ID int64 `gae:"$id"` | 1183 ID int64 `gae:"$id"` |
| 1184 Val string | 1184 Val string |
| 1185 Extra PropertyMap `gae:"-,extra"` | 1185 Extra PropertyMap `gae:"-,extra"` |
| 1186 } | 1186 } |
| 1187 i := &IntChange{ID: 10} | 1187 i := &IntChange{ID: 10} |
| 1188 So(ds.Get(i), ShouldBeNil) | 1188 So(ds.Get(i), ShouldBeNil) |
| 1189 » » » So(i, ShouldResembleV, &IntChange{ID: 10, Extra: Propert
yMap{"Val": {mp(100)}}}) | 1189 » » » So(i, ShouldResemble, &IntChange{ID: 10, Extra: Property
Map{"Val": {mp(100)}}}) |
| 1190 i.Val = fmt.Sprint(i.Extra["Val"][0].Value()) | 1190 i.Val = fmt.Sprint(i.Extra["Val"][0].Value()) |
| 1191 So(ds.Put(i), ShouldBeNil) | 1191 So(ds.Put(i), ShouldBeNil) |
| 1192 | 1192 |
| 1193 i = &IntChange{ID: 10} | 1193 i = &IntChange{ID: 10} |
| 1194 So(ds.Get(i), ShouldBeNil) | 1194 So(ds.Get(i), ShouldBeNil) |
| 1195 » » » So(i, ShouldResembleV, &IntChange{ID: 10, Val: "100"}) | 1195 » » » So(i, ShouldResemble, &IntChange{ID: 10, Val: "100"}) |
| 1196 }) | 1196 }) |
| 1197 | 1197 |
| 1198 Convey("Native fields have priority over Extra fields", func() { | 1198 Convey("Native fields have priority over Extra fields", func() { |
| 1199 type Dup struct { | 1199 type Dup struct { |
| 1200 ID int64 `gae:"$id"` | 1200 ID int64 `gae:"$id"` |
| 1201 Val int64 | 1201 Val int64 |
| 1202 Extra PropertyMap `gae:",extra"` | 1202 Extra PropertyMap `gae:",extra"` |
| 1203 } | 1203 } |
| 1204 d := &Dup{ID: 10, Val: 100, Extra: PropertyMap{ | 1204 d := &Dup{ID: 10, Val: 100, Extra: PropertyMap{ |
| 1205 "Val": {mp(200)}, | 1205 "Val": {mp(200)}, |
| 1206 "Other": {mp("other")}, | 1206 "Other": {mp("other")}, |
| 1207 }} | 1207 }} |
| 1208 So(ds.Put(d), ShouldBeNil) | 1208 So(ds.Put(d), ShouldBeNil) |
| 1209 | 1209 |
| 1210 d = &Dup{ID: 10} | 1210 d = &Dup{ID: 10} |
| 1211 So(ds.Get(d), ShouldBeNil) | 1211 So(ds.Get(d), ShouldBeNil) |
| 1212 » » » So(d, ShouldResembleV, &Dup{ | 1212 » » » So(d, ShouldResemble, &Dup{ |
| 1213 ID: 10, Val: 100, Extra: PropertyMap{"Other": {m
p("other")}}, | 1213 ID: 10, Val: 100, Extra: PropertyMap{"Other": {m
p("other")}}, |
| 1214 }) | 1214 }) |
| 1215 }) | 1215 }) |
| 1216 | 1216 |
| 1217 Convey("Can change repeated field to non-repeating field", func(
) { | 1217 Convey("Can change repeated field to non-repeating field", func(
) { |
| 1218 initial := PropertyMap{ | 1218 initial := PropertyMap{ |
| 1219 "$key": {mpNI(ds.MakeKey("NonRepeating", 10))}, | 1219 "$key": {mpNI(ds.MakeKey("NonRepeating", 10))}, |
| 1220 "Val": {mp(100), mp(200), mp(400)}, | 1220 "Val": {mp(100), mp(200), mp(400)}, |
| 1221 } | 1221 } |
| 1222 So(ds.Put(initial), ShouldBeNil) | 1222 So(ds.Put(initial), ShouldBeNil) |
| 1223 | 1223 |
| 1224 type NonRepeating struct { | 1224 type NonRepeating struct { |
| 1225 ID int64 `gae:"$id"` | 1225 ID int64 `gae:"$id"` |
| 1226 Val int64 | 1226 Val int64 |
| 1227 Extra PropertyMap `gae:",extra"` | 1227 Extra PropertyMap `gae:",extra"` |
| 1228 } | 1228 } |
| 1229 n := &NonRepeating{ID: 10} | 1229 n := &NonRepeating{ID: 10} |
| 1230 So(ds.Get(n), ShouldBeNil) | 1230 So(ds.Get(n), ShouldBeNil) |
| 1231 » » » So(n, ShouldResembleV, &NonRepeating{ | 1231 » » » So(n, ShouldResemble, &NonRepeating{ |
| 1232 ID: 10, Val: 0, Extra: PropertyMap{ | 1232 ID: 10, Val: 0, Extra: PropertyMap{ |
| 1233 "Val": {mp(100), mp(200), mp(400)}, | 1233 "Val": {mp(100), mp(200), mp(400)}, |
| 1234 }, | 1234 }, |
| 1235 }) | 1235 }) |
| 1236 }) | 1236 }) |
| 1237 | 1237 |
| 1238 Convey("Deals correctly with recursive types", func() { | 1238 Convey("Deals correctly with recursive types", func() { |
| 1239 initial := PropertyMap{ | 1239 initial := PropertyMap{ |
| 1240 "$key": {mpNI(ds.MakeKey("Outer", 10))}, | 1240 "$key": {mpNI(ds.MakeKey("Outer", 10))}, |
| 1241 "I.A": {mp(1), mp(2), mp(4)}, | 1241 "I.A": {mp(1), mp(2), mp(4)}, |
| 1242 "I.B": {mp(10), mp(20), mp(40)}, | 1242 "I.B": {mp(10), mp(20), mp(40)}, |
| 1243 "I.C": {mp(100), mp(200), mp(400)}, | 1243 "I.C": {mp(100), mp(200), mp(400)}, |
| 1244 } | 1244 } |
| 1245 So(ds.Put(initial), ShouldBeNil) | 1245 So(ds.Put(initial), ShouldBeNil) |
| 1246 type Inner struct { | 1246 type Inner struct { |
| 1247 A int64 | 1247 A int64 |
| 1248 B int64 | 1248 B int64 |
| 1249 } | 1249 } |
| 1250 type Outer struct { | 1250 type Outer struct { |
| 1251 ID int64 `gae:"$id"` | 1251 ID int64 `gae:"$id"` |
| 1252 | 1252 |
| 1253 I []Inner | 1253 I []Inner |
| 1254 Extra PropertyMap `gae:",extra"` | 1254 Extra PropertyMap `gae:",extra"` |
| 1255 } | 1255 } |
| 1256 o := &Outer{ID: 10} | 1256 o := &Outer{ID: 10} |
| 1257 So(ds.Get(o), ShouldBeNil) | 1257 So(ds.Get(o), ShouldBeNil) |
| 1258 » » » So(o, ShouldResembleV, &Outer{ | 1258 » » » So(o, ShouldResemble, &Outer{ |
| 1259 ID: 10, | 1259 ID: 10, |
| 1260 I: []Inner{ | 1260 I: []Inner{ |
| 1261 {1, 10}, | 1261 {1, 10}, |
| 1262 {2, 20}, | 1262 {2, 20}, |
| 1263 {4, 40}, | 1263 {4, 40}, |
| 1264 }, | 1264 }, |
| 1265 Extra: PropertyMap{ | 1265 Extra: PropertyMap{ |
| 1266 "I.C": {mp(100), mp(200), mp(400)}, | 1266 "I.C": {mp(100), mp(200), mp(400)}, |
| 1267 }, | 1267 }, |
| 1268 }) | 1268 }) |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1366 Property: "business", | 1366 Property: "business", |
| 1367 Descending: false, | 1367 Descending: false, |
| 1368 }, | 1368 }, |
| 1369 { | 1369 { |
| 1370 Property: "owner", | 1370 Property: "owner", |
| 1371 Descending: false, | 1371 Descending: false, |
| 1372 }, | 1372 }, |
| 1373 }, | 1373 }, |
| 1374 }, | 1374 }, |
| 1375 } | 1375 } |
| 1376 » » So(ids, ShouldResembleV, expected) | 1376 » » So(ids, ShouldResemble, expected) |
| 1377 }) | 1377 }) |
| 1378 | 1378 |
| 1379 Convey("returns non-nil error for incorrectly formatted YAML", t, func()
{ | 1379 Convey("returns non-nil error for incorrectly formatted YAML", t, func()
{ |
| 1380 | 1380 |
| 1381 Convey("missing top level `indexes` key", func() { | 1381 Convey("missing top level `indexes` key", func() { |
| 1382 yaml := ` | 1382 yaml := ` |
| 1383 - kind: Cat | 1383 - kind: Cat |
| 1384 properties: | 1384 properties: |
| 1385 - name: name | 1385 - name: name |
| 1386 - name: age | 1386 - name: age |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1521 if err != nil { | 1521 if err != nil { |
| 1522 panic(fmt.Errorf("failed to find absolute path f
or `%s`", sameLevelDir)) | 1522 panic(fmt.Errorf("failed to find absolute path f
or `%s`", sameLevelDir)) |
| 1523 } | 1523 } |
| 1524 | 1524 |
| 1525 ids, err := FindAndParseIndexYAML(abs) | 1525 ids, err := FindAndParseIndexYAML(abs) |
| 1526 So(err, ShouldBeNil) | 1526 So(err, ShouldBeNil) |
| 1527 So(ids[1].Kind, ShouldEqual, "Test Foo") | 1527 So(ids[1].Kind, ShouldEqual, "Test Foo") |
| 1528 }) | 1528 }) |
| 1529 }) | 1529 }) |
| 1530 } | 1530 } |
| OLD | NEW |