...

Source file src/github.com/gregjones/httpcache/test/test.go

Documentation: github.com/gregjones/httpcache/test

     1  package test
     2  
     3  import (
     4  	"bytes"
     5  	"testing"
     6  
     7  	"github.com/gregjones/httpcache"
     8  )
     9  
    10  // Cache excercises a httpcache.Cache implementation.
    11  func Cache(t *testing.T, cache httpcache.Cache) {
    12  	key := "testKey"
    13  	_, ok := cache.Get(key)
    14  	if ok {
    15  		t.Fatal("retrieved key before adding it")
    16  	}
    17  
    18  	val := []byte("some bytes")
    19  	cache.Set(key, val)
    20  
    21  	retVal, ok := cache.Get(key)
    22  	if !ok {
    23  		t.Fatal("could not retrieve an element we just added")
    24  	}
    25  	if !bytes.Equal(retVal, val) {
    26  		t.Fatal("retrieved a different value than what we put in")
    27  	}
    28  
    29  	cache.Delete(key)
    30  
    31  	_, ok = cache.Get(key)
    32  	if ok {
    33  		t.Fatal("deleted key still present")
    34  	}
    35  }
    36  

View as plain text