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 "fmt" | 8 "fmt" |
9 "strings" | 9 "strings" |
10 "testing" | 10 "testing" |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 err := data.Run(q, func(pm ds.PropertyMa
p, gc ds.CursorCB) error { | 355 err := data.Run(q, func(pm ds.PropertyMa
p, gc ds.CursorCB) error { |
356 So(pm, ShouldResemble, pmap( | 356 So(pm, ShouldResemble, pmap( |
357 "$key", key("Kind", 2, "
__entity_group__", 1), Next, | 357 "$key", key("Kind", 2, "
__entity_group__", 1), Next, |
358 "__version__", 1)) | 358 "__version__", 1)) |
359 | 359 |
360 err := error(nil) | 360 err := error(nil) |
361 curs, err = gc() | 361 curs, err = gc() |
362 So(err, ShouldBeNil) | 362 So(err, ShouldBeNil) |
363 return ds.Stop | 363 return ds.Stop |
364 }) | 364 }) |
365 » » » » » So(err, ShouldBeNil) | 365 » » » » » So(err, shouldBeSuccessful) |
366 | 366 |
367 err = data.Run(q.Start(curs), func(pm ds
.PropertyMap) error { | 367 err = data.Run(q.Start(curs), func(pm ds
.PropertyMap) error { |
368 So(pm, ShouldResemble, stage1Dat
a[2]) | 368 So(pm, ShouldResemble, stage1Dat
a[2]) |
369 return ds.Stop | 369 return ds.Stop |
370 }) | 370 }) |
371 » » » » » So(err, ShouldBeNil) | 371 » » » » » So(err, shouldBeSuccessful) |
372 }, | 372 }, |
373 | 373 |
374 func(c context.Context) { | 374 func(c context.Context) { |
375 data := ds.Get(c) | 375 data := ds.Get(c) |
376 q := nq("Something").Eq("Does", 2).Order
("Not", "-Work") | 376 q := nq("Something").Eq("Does", 2).Order
("Not", "-Work") |
377 So(data.Run(q, func(ds.Key) {}), ShouldE
rrLike, strings.Join([]string{ | 377 So(data.Run(q, func(ds.Key) {}), ShouldE
rrLike, strings.Join([]string{ |
378 "Consider adding:", | 378 "Consider adding:", |
379 "- kind: Something", | 379 "- kind: Something", |
380 " properties:", | 380 " properties:", |
381 " - name: Does", | 381 " - name: Does", |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 } else { | 512 } else { |
513 expect.c
ount = len(expect.get) | 513 expect.c
ount = len(expect.get) |
514 } | 514 } |
515 } | 515 } |
516 | 516 |
517 if expect.keys != nil { | 517 if expect.keys != nil { |
518 Convey(fmt.Sprin
tf("expect %d (keys)", j), func() { | 518 Convey(fmt.Sprin
tf("expect %d (keys)", j), func() { |
519 err := r
unner(func(c context.Context) error { | 519 err := r
unner(func(c context.Context) error { |
520
data := ds.Get(c) | 520
data := ds.Get(c) |
521
count, err := data.Count(expect.q) | 521
count, err := data.Count(expect.q) |
522 » » » » » » » » » »
So(err, ShouldBeNil) | 522 » » » » » » » » » »
So(err, shouldBeSuccessful) |
523
So(count, ShouldEqual, expect.count) | 523
So(count, ShouldEqual, expect.count) |
524 | 524 |
525
rslt := []*ds.Key(nil) | 525
rslt := []*ds.Key(nil) |
526 » » » » » » » » » »
So(data.GetAll(expect.q, &rslt), ShouldBeNil) | 526 » » » » » » » » » »
So(data.GetAll(expect.q, &rslt), shouldBeSuccessful) |
527
So(len(rslt), ShouldEqual, len(expect.keys)) | 527
So(len(rslt), ShouldEqual, len(expect.keys)) |
528
for i, r := range rslt { | 528
for i, r := range rslt { |
529
So(r, ShouldResemble, expect.keys[i]) | 529
So(r, ShouldResemble, expect.keys[i]) |
530
} | 530
} |
531
return nil | 531
return nil |
532 }, &ds.T
ransactionOptions{XG: true}) | 532 }, &ds.T
ransactionOptions{XG: true}) |
533 » » » » » » » » » So(err,
ShouldBeNil) | 533 » » » » » » » » » So(err,
shouldBeSuccessful) |
534 }) | 534 }) |
535 } | 535 } |
536 | 536 |
537 if expect.get != nil { | 537 if expect.get != nil { |
538 Convey(fmt.Sprin
tf("expect %d (data)", j), func() { | 538 Convey(fmt.Sprin
tf("expect %d (data)", j), func() { |
539 err := r
unner(func(c context.Context) error { | 539 err := r
unner(func(c context.Context) error { |
540
data := ds.Get(c) | 540
data := ds.Get(c) |
541
count, err := data.Count(expect.q) | 541
count, err := data.Count(expect.q) |
542 » » » » » » » » » »
So(err, ShouldBeNil) | 542 » » » » » » » » » »
So(err, shouldBeSuccessful) |
543
So(count, ShouldEqual, expect.count) | 543
So(count, ShouldEqual, expect.count) |
544 | 544 |
545
rslt := []ds.PropertyMap(nil) | 545
rslt := []ds.PropertyMap(nil) |
546 » » » » » » » » » »
So(data.GetAll(expect.q, &rslt), ShouldBeNil) | 546 » » » » » » » » » »
So(data.GetAll(expect.q, &rslt), shouldBeSuccessful) |
547
So(len(rslt), ShouldEqual, len(expect.get)) | 547
So(len(rslt), ShouldEqual, len(expect.get)) |
548
for i, r := range rslt { | 548
for i, r := range rslt { |
549
So(r, ShouldResemble, expect.get[i]) | 549
So(r, ShouldResemble, expect.get[i]) |
550
} | 550
} |
551
return nil | 551
return nil |
552 }, &ds.T
ransactionOptions{XG: true}) | 552 }, &ds.T
ransactionOptions{XG: true}) |
553 » » » » » » » » » So(err,
ShouldBeNil) | 553 » » » » » » » » » So(err,
shouldBeSuccessful) |
554 }) | 554 }) |
555 } | 555 } |
556 } | 556 } |
557 | 557 |
558 for j, fn := range stage.extraFn
s { | 558 for j, fn := range stage.extraFn
s { |
559 Convey(fmt.Sprintf("extr
aFn %d", j), func() { | 559 Convey(fmt.Sprintf("extr
aFn %d", j), func() { |
560 fn(c) | 560 fn(c) |
561 }) | 561 }) |
562 } | 562 } |
563 }) | 563 }) |
564 } | 564 } |
565 }) | 565 }) |
566 } | 566 } |
567 }) | 567 }) |
568 | 568 |
569 Convey("Test AutoIndex", t, func() { | 569 Convey("Test AutoIndex", t, func() { |
570 c, err := info.Get(Use(context.Background())).Namespace("ns") | 570 c, err := info.Get(Use(context.Background())).Namespace("ns") |
571 if err != nil { | 571 if err != nil { |
572 panic(err) | 572 panic(err) |
573 } | 573 } |
574 | 574 |
575 data := ds.Get(c) | 575 data := ds.Get(c) |
576 testing := data.Testable() | 576 testing := data.Testable() |
577 testing.Consistent(true) | 577 testing.Consistent(true) |
578 | 578 |
579 So(data.Put(pmap("$key", key("Kind", 1), Next, | 579 So(data.Put(pmap("$key", key("Kind", 1), Next, |
580 "Val", 1, 2, 3, Next, | 580 "Val", 1, 2, 3, Next, |
581 "Extra", "hello", | 581 "Extra", "hello", |
582 » » )), ShouldBeNil) | 582 » » )), shouldBeSuccessful) |
583 | 583 |
584 So(data.Put(pmap("$key", key("Kind", 2), Next, | 584 So(data.Put(pmap("$key", key("Kind", 2), Next, |
585 "Val", 2, 3, 9, Next, | 585 "Val", 2, 3, 9, Next, |
586 "Extra", "ace", "hello", "there", | 586 "Extra", "ace", "hello", "there", |
587 » » )), ShouldBeNil) | 587 » » )), shouldBeSuccessful) |
588 | 588 |
589 q := nq("Kind").Gt("Val", 2).Order("Val", "Extra") | 589 q := nq("Kind").Gt("Val", 2).Order("Val", "Extra") |
590 | 590 |
591 count, err := data.Count(q) | 591 count, err := data.Count(q) |
592 So(err, ShouldErrLike, "Insufficient indexes") | 592 So(err, ShouldErrLike, "Insufficient indexes") |
593 | 593 |
594 testing.AutoIndex(true) | 594 testing.AutoIndex(true) |
595 | 595 |
596 count, err = data.Count(q) | 596 count, err = data.Count(q) |
597 » » So(err, ShouldBeNil) | 597 » » So(err, shouldBeSuccessful) |
598 So(count, ShouldEqual, 2) | 598 So(count, ShouldEqual, 2) |
599 }) | 599 }) |
600 } | 600 } |
| 601 |
| 602 func shouldBeSuccessful(actual interface{}, expected ...interface{}) string { |
| 603 if len(expected) != 0 { |
| 604 return "no expected values permitted" |
| 605 } |
| 606 if actual == nil { |
| 607 return "" |
| 608 } |
| 609 |
| 610 v, ok := actual.(error) |
| 611 if !ok { |
| 612 return fmt.Sprintf("type of 'actual' must be error, not %T", act
ual) |
| 613 } |
| 614 if v == nil || v == ds.Stop { |
| 615 return "" |
| 616 } |
| 617 return fmt.Sprintf("expected success value, not %v", v) |
| 618 } |
OLD | NEW |