Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(344)

Unified Diff: impl/memory/memcache_test.go

Issue 1354333002: Fix memcache.Interface.Get to return a memcache.Item (Closed) Base URL: https://github.com/luci/gae.git@fix_meta_serialize
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: impl/memory/memcache_test.go
diff --git a/impl/memory/memcache_test.go b/impl/memory/memcache_test.go
index 73fa2b46da2f56444bfbbc452c9ba1eee7663a1e..bc2d0e5fed0df4e66b75d507b4e4cb4a0f57e4d6 100644
--- a/impl/memory/memcache_test.go
+++ b/impl/memory/memcache_test.go
@@ -48,16 +48,14 @@ func TestMemcache(t *testing.T) {
value: []byte("cool"),
CasID: 1,
}
- getItm := &mcItem{
- key: "sup",
- }
- So(mc.Get(getItm), ShouldBeNil)
+ getItm, err := mc.Get("sup")
+ So(err, ShouldBeNil)
So(getItm, ShouldResemble, testItem)
Convey("which can expire", func() {
tc.Add(time.Second * 4)
- getItm := &mcItem{key: "sup"}
- So(mc.Get(getItm), ShouldEqual, mcS.ErrCacheMiss)
+ getItm, err := mc.Get("sup")
+ So(err, ShouldEqual, mcS.ErrCacheMiss)
So(getItm, ShouldResemble, &mcItem{key: "sup"})
})
})
@@ -73,7 +71,8 @@ func TestMemcache(t *testing.T) {
So(mc.Delete("sup"), ShouldBeNil)
- So(mc.Get(mc.NewItem("sup")), ShouldEqual, mcS.ErrCacheMiss)
+ _, err := mc.Get("sup")
+ So(err, ShouldEqual, mcS.ErrCacheMiss)
})
Convey("but not if it's not there", func() {
@@ -97,13 +96,14 @@ func TestMemcache(t *testing.T) {
value: []byte("newp"),
CasID: 2,
}
- getItm := mc.NewItem("sup")
- So(mc.Get(getItm), ShouldBeNil)
+ getItm, err := mc.Get("sup")
+ So(err, ShouldBeNil)
So(getItm, ShouldResemble, testItem)
Convey("Flush works too", func() {
So(mc.Flush(), ShouldBeNil)
- So(mc.Get(getItm), ShouldEqual, mcS.ErrCacheMiss)
+ _, err := mc.Get("sup")
+ So(err, ShouldEqual, mcS.ErrCacheMiss)
})
})
@@ -140,8 +140,8 @@ func TestMemcache(t *testing.T) {
So(mc.Add(itm), ShouldBeNil)
Convey("works after a Get", func() {
- itm = mc.NewItem("sup")
- So(mc.Get(itm), ShouldBeNil)
+ itm, err := mc.Get("sup")
+ So(err, ShouldBeNil)
So(itm.(*mcItem).CasID, ShouldEqual, 1)
itm.SetValue([]byte("newp"))
@@ -169,15 +169,15 @@ func TestMemcache(t *testing.T) {
expiration: time.Second * 2,
})
- So(mc.Get(mc.NewItem("sup")), ShouldBeNil)
- So(mc.Get(mc.NewItem("sup")), ShouldBeNil)
- So(mc.Get(mc.NewItem("sup")), ShouldBeNil)
- So(mc.Get(mc.NewItem("sup")), ShouldBeNil)
- So(mc.Get(mc.NewItem("wot")), ShouldErrLike, mcS.ErrCacheMiss)
+ for i := 0; i < 4; i++ {
+ _, err := mc.Get("sup")
+ So(err, ShouldBeNil)
+ }
+ _, err = mc.Get("wot")
+ So(err, ShouldErrLike, mcS.ErrCacheMiss)
mci := mc.Raw().(*memcacheImpl)
- So(err, ShouldBeNil)
stats, err := mc.Stats()
So(err, ShouldBeNil)
So(stats.Items, ShouldEqual, 1)
@@ -192,8 +192,8 @@ func TestMemcache(t *testing.T) {
casID: 1,
})
- getItm := mc.NewItem("sup")
- So(mc.Get(getItm), ShouldBeNil)
+ getItm, err := mc.Get("sup")
+ So(err, ShouldBeNil)
So(len(mci.data.items), ShouldEqual, 1)
So(mci.data.casID, ShouldEqual, 1)

Powered by Google App Engine
This is Rietveld 408576698