better tests

This commit is contained in:
Karl Seguin 2014-11-13 22:26:05 +07:00
parent 7316f99bd9
commit 2131ac5052
2 changed files with 9 additions and 4 deletions

View file

@ -50,14 +50,17 @@ func (b *BucketTests) SetsAnExistingItem() {
func (b *BucketTests) ReplaceDoesNothingIfKeyDoesNotExist() {
bucket := testBucket()
item, _ := bucket.set("power", TestValue("9002"), time.Minute)
Expect(bucket.replace("power", TestValue("9004"))).To.Equal(true)
Expect(item.Value().(string)).To.Equal("9004")
Expect(bucket.replace("power", TestValue("9002"))).To.Equal(false)
Expect(bucket.get("power")).To.Equal(nil)
}
func (b *BucketTests) ReplaceReplacesThevalue() {
bucket := testBucket()
Expect(bucket.replace("power", TestValue("9002"))).To.Equal(false)
item, _ := bucket.set("power", TestValue("9002"), time.Minute)
Expect(bucket.replace("power", TestValue("9004"))).To.Equal(true)
Expect(item.Value().(string)).To.Equal("9004")
Expect(bucket.get("power").Value().(string)).To.Equal("9004")
//not sure how to test that the TTL hasn't changed sort of a sleep..
}
func testBucket() *Bucket {

View file

@ -42,6 +42,7 @@ func (l *LayeredCacheTests) SetsMultipleValueWithinTheSameLayer() {
func (l *LayeredCacheTests) ReplaceDoesNothingIfKeyDoesNotExist() {
cache := newLayered()
Expect(cache.Replace("spice", "flow", "value-a")).To.Equal(false)
Expect(cache.Get("spice", "flow")).To.Equal(nil)
}
func (l *LayeredCacheTests) ReplaceUpdatesTheValue() {
@ -49,6 +50,7 @@ func (l *LayeredCacheTests) ReplaceUpdatesTheValue() {
cache.Set("spice", "flow", "value-a", time.Minute)
Expect(cache.Replace("spice", "flow", "value-b")).To.Equal(true)
Expect(cache.Get("spice", "flow").Value().(string)).To.Equal("value-b")
//not sure how to test that the TTL hasn't changed sort of a sleep..
}
func (l *LayeredCacheTests) DeletesAValue() {