Chromium Code Reviews| 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 package memory | 5 package memory |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "bytes" | |
| 8 "fmt" | 9 "fmt" |
| 9 "testing" | 10 "testing" |
| 10 "time" | 11 "time" |
| 11 | 12 |
| 12 dsS "github.com/luci/gae/service/datastore" | 13 dsS "github.com/luci/gae/service/datastore" |
| 13 "github.com/luci/gae/service/datastore/serialize" | 14 "github.com/luci/gae/service/datastore/serialize" |
| 14 infoS "github.com/luci/gae/service/info" | 15 infoS "github.com/luci/gae/service/info" |
| 15 . "github.com/luci/luci-go/common/testing/assertions" | 16 . "github.com/luci/luci-go/common/testing/assertions" |
| 16 . "github.com/smartystreets/goconvey/convey" | 17 . "github.com/smartystreets/goconvey/convey" |
| 17 "golang.org/x/net/context" | 18 "golang.org/x/net/context" |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 521 So(ds.Put(&Foo{}), ShouldErrLike, "allocateIDs is disabl ed") | 522 So(ds.Put(&Foo{}), ShouldErrLike, "allocateIDs is disabl ed") |
| 522 | 523 |
| 523 So(ds.Put(&Foo{ID: 1}), ShouldBeNil) | 524 So(ds.Put(&Foo{ID: 1}), ShouldBeNil) |
| 524 | 525 |
| 525 ds.Testable().CatchupIndexes() | 526 ds.Testable().CatchupIndexes() |
| 526 | 527 |
| 527 count, err := ds.Count(dsS.NewQuery("")) | 528 count, err := ds.Count(dsS.NewQuery("")) |
| 528 So(err, ShouldBeNil) | 529 So(err, ShouldBeNil) |
| 529 So(count, ShouldEqual, 1) // normally this would include __entity_group__ | 530 So(count, ShouldEqual, 1) // normally this would include __entity_group__ |
| 530 }) | 531 }) |
| 532 | |
| 533 Convey("Testable.ParseIndexYAML", func() { | |
| 534 yaml := ` | |
| 535 indexes: | |
| 536 | |
| 537 - kind: Cat | |
| 538 ancestor: no | |
| 539 properties: | |
| 540 - name: name | |
| 541 - name: age | |
| 542 direction: desc | |
| 543 | |
| 544 - kind: Cat | |
| 545 properties: | |
| 546 - name: name | |
| 547 direction: asc | |
| 548 - name: whiskers | |
| 549 direction: desc | |
| 550 | |
| 551 - kind: Store | |
| 552 ancestor: yes | |
| 553 properties: | |
| 554 - name: business | |
| 555 direction: asc | |
| 556 - name: owner | |
| 557 direction: asc | |
| 558 ` | |
| 559 idxs := ds.Testable().ParseIndexYAML(bytes.NewBufferStri ng(yaml)) | |
| 560 expected := []*dsS.IndexDefinition{ | |
| 561 { | |
| 562 Kind: "Cat", | |
| 563 Ancestor: false, | |
| 564 SortBy: []dsS.IndexColumn{ | |
| 565 { | |
| 566 Property: "name", | |
| 567 Descending: false, | |
| 568 }, | |
| 569 { | |
| 570 Property: "age", | |
| 571 Descending: true, | |
| 572 }, | |
| 573 }, | |
| 574 }, | |
| 575 { | |
| 576 Kind: "Cat", | |
| 577 Ancestor: false, | |
| 578 SortBy: []dsS.IndexColumn{ | |
| 579 { | |
| 580 Property: "name", | |
| 581 Descending: false, | |
| 582 }, | |
| 583 { | |
| 584 Property: "whiskers", | |
| 585 Descending: true, | |
| 586 }, | |
| 587 }, | |
| 588 }, | |
| 589 { | |
| 590 Kind: "Store", | |
| 591 Ancestor: true, | |
| 592 SortBy: []dsS.IndexColumn{ | |
| 593 { | |
| 594 Property: "business", | |
| 595 Descending: false, | |
| 596 }, | |
| 597 { | |
| 598 Property: "owner", | |
| 599 Descending: false, | |
| 600 }, | |
| 601 }, | |
| 602 }, | |
| 603 } | |
| 604 So(idxs, ShouldResembleV, expected) | |
| 605 }) | |
| 531 }) | 606 }) |
|
dnj
2016/01/13 16:16:40
Also test filesystem walking using a tempdir.
nishanths (utexas)
2016/01/14 21:15:14
Done. :) The tests are now in service/datastore/da
| |
| 532 } | 607 } |
| 533 | 608 |
| 534 func TestCompoundIndexes(t *testing.T) { | 609 func TestCompoundIndexes(t *testing.T) { |
| 535 t.Parallel() | 610 t.Parallel() |
| 536 | 611 |
| 537 idxKey := func(def dsS.IndexDefinition) string { | 612 idxKey := func(def dsS.IndexDefinition) string { |
| 538 So(def, ShouldNotBeNil) | 613 So(def, ShouldNotBeNil) |
| 539 return "idx::" + string(serialize.ToBytes(*def.PrepForIdxTable() )) | 614 return "idx::" + string(serialize.ToBytes(*def.PrepForIdxTable() )) |
| 540 } | 615 } |
| 541 | 616 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 624 So(ds.Put(&Model{ID: 1, Value: []int64{20, 30}}), ShouldBeNil) | 699 So(ds.Put(&Model{ID: 1, Value: []int64{20, 30}}), ShouldBeNil) |
| 625 | 700 |
| 626 vals := []dsS.PropertyMap{} | 701 vals := []dsS.PropertyMap{} |
| 627 So(ds.GetAll(dsS.NewQuery("Model").Project("Value"), &vals), Sho uldBeNil) | 702 So(ds.GetAll(dsS.NewQuery("Model").Project("Value"), &vals), Sho uldBeNil) |
| 628 So(len(vals), ShouldEqual, 2) | 703 So(len(vals), ShouldEqual, 2) |
| 629 | 704 |
| 630 So(vals[0]["Value"][0].Value(), ShouldEqual, 20) | 705 So(vals[0]["Value"][0].Value(), ShouldEqual, 20) |
| 631 So(vals[1]["Value"][0].Value(), ShouldEqual, 30) | 706 So(vals[1]["Value"][0].Value(), ShouldEqual, 30) |
| 632 }) | 707 }) |
| 633 } | 708 } |
| OLD | NEW |