func TestPruneCache(t *testing.T) {
	if testing.Short() {
		t.SkipNow()
	}
	sc := newStreamCache(10)
	for i := 0; i < int(sc.cacheSize)+5; i++ {
		sc.Add(strconv.Itoa(i), []byte{})
	}
	if len(sc.streamHeap) != int(sc.cacheSize) || len(sc.streamMap) != len(sc.streamHeap) {
		t.Error("Cache is not equal to the cacheSize")
	}
	sc.pruneCache(2)
	if len(sc.streamHeap) != 2 || len(sc.streamMap) != 2 {
		t.Error("Cache was not pruned")
	}
	sc.pruneCache(20)
	if len(sc.streamHeap) != 2 || len(sc.streamMap) != 2 {
		t.Error("Cache size was changed by pruning to larger value")
	}
	sc.pruneCache(0)
	id := "test"
	for i := 0; i < 5; i++ {
		sc.Add(id, []byte{})
	}
	if len(sc.streamHeap) != 1 || len(sc.streamMap) != 1 {
		t.Fatalf("Chunk added more the once.\nHeap length: %v\nMap length: %v\n", len(sc.streamHeap), len(sc.streamMap))
	}
}
TestPruneCache tests to make sure that pruneCache always prunes the cache
to the given size
package renter
import (
	"container/heap"
	"reflect"
	"strconv"
	"testing"
	"time"
)
func TestHeapImplementation(t *testing.T) {
	streamHeap := make(streamHeap, 0, DefaultStreamCacheSize)
	heap.Init(&streamHeap)
	length := len(streamHeap)
	cd := &chunkData{
		id:         "Push",
		data:       []byte{},
		lastAccess: time.Now(),
	}
	heap.Push(&streamHeap, cd)
	if len(streamHeap) != length+1 {
		t.Error("Length of heap did not change, chunkData was not pushed onto Heap. Length of heap is still ", len(streamHeap))
	}
	if !reflect.DeepEqual(cd, streamHeap[0]) {
		t.Error("Chunk on top of heap is not the chunk that was just pushed on, chunkData.id =", streamHeap[0].id)
	}
	for i := 0; i < 3; i++ {
		heap.Push(&streamHeap, &chunkData{
			id:         strconv.Itoa(i),
			data:       []byte{},
			lastAccess: time.Now().Add(-1 * time.Minute),
		})
	}
	cd = streamHeap[0]
	streamHeap.update(cd, cd.id, cd.data, time.Now())
	if reflect.DeepEqual(cd, streamHeap[0]) {
		t.Error("Heap order was not updated. Recently accessed element at top of heap")
	}
	cd = streamHeap[len(streamHeap)-1]
	streamHeap.update(cd, cd.id, cd.data, time.Now().Add(-1*time.Hour))
	if !reflect.DeepEqual(cd, streamHeap[0]) {
		t.Error("Heap order was not updated. Least recently accessed element is not at top of heap")
	}
	cd = streamHeap[0]
	length = len(streamHeap)
	if pop := heap.Pop(&streamHeap).(*chunkData); !reflect.DeepEqual(cd, pop) {
		t.Error("Element at the top of the Heap was not popped off")
	}
	if len(streamHeap) != length-1 {
		t.Error("Heap length was not reduced by 1")
	}
}