You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: collection_test.go
    path of file: ./repos/tiedot/data
    
    the code of the file until where you have to start completion: package data

import (
	"fmt"
	"math/rand"
	"os"
	"strings"
	"testing"

	"github.com/HouzuoGuo/tiedot/dberr"
)

// helper function
func RandStringBytes(n int) string {
	const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
	b := make([]byte, n)
	for i := range b {
		b[i] = letterBytes[rand.Intn(len(letterBytes))]
	}
	return string(b)
}

// setUp
func setupTestCollection() (col *Collection, err error) {
	os.Remove(tmp)
	defer os.Remove(tmp)
	d := defaultConfig()
	return d.OpenCollection(tmp)
}

func TestInsertRead(t *testing.T) {
	os.Remove(tmp)
	defer os.Remove(tmp)
	data := defaultConfig()
	col, err := data.OpenCollection(tmp)
	if err != nil {
		t.Fatalf("Failed to open: %v", err)
		return
	}
	defer col.Close()
	docs := [][]byte{
		[]byte("abc"),
		[]byte("1234")}
	ids := [2]int{}
	if ids[0], err = col.Insert(do
    
func TestInsertReadAll(t *testing.T) {
	os.Remove(tmp)
	defer os.Remove(tmp)
	d := defaultConfig()
	col, err := d.OpenCollection(tmp)
	if err != nil {
		t.Fatalf("Failed to open: %v", err)
		return
	}
	defer col.Close()
	var ids [5]int
	ids[0], err = col.Insert([]byte("abc"))
	if err != nil {
		t.Fatalf("Insert failed: %v", err)
	}
	ids[1], err = col.Insert([]byte("abc"))
	if err != nil {
		t.Fatalf("Insert failed: %v", err)
	}
	ids[2], err = col.Insert([]byte("abc"))
	if err != nil {
		t.Fatalf("Insert failed: %v", err)
	}
	ids[3], err = col.Insert([]byte("abc"))
	if err != nil {
		t.Fatalf("Insert failed: %v", err)
	}
	ids[4], err = col.Insert([]byte("abc"))
	if err != nil {
		t.Fatalf("Insert failed: %v", err)
	}
	successfullyRead := 0
	t.Log(ids)
	col.ForEachDoc(func(_ int, _ []byte) bool {
		successfullyRead++
		return true
	})
	// break
	col.ForEachDoc(func(_ int, _ []byte) bool {
		return false
	})
	if successfullyRead != 5 {
		t.Fatalf("Should have read 5 documents, but only got %d", successfullyRead)
	}
	successfullyRead = 0
	// intentionally corrupt two docuemnts
	col.Buf[ids[4]] = 3     // corrupted validity
	col.Buf[ids[2]+1] = 255 // corrupted room
	col.ForEachDoc(func(_ int, _ []byte) bool {
		successfullyRead++
		return true
	})
	if successfullyRead != 3 {
		t.Fatalf("Should have read 3 documents, but %d are recovered", successfullyRead)
	}
}