2015-01-10 22:40:10 +00:00
|
|
|
package backend_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/rand"
|
|
|
|
"io"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/restic/restic/backend"
|
2015-04-09 19:15:48 +00:00
|
|
|
. "github.com/restic/restic/test"
|
2015-01-10 22:40:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func randomID() []byte {
|
|
|
|
buf := make([]byte, backend.IDSize)
|
|
|
|
_, err := io.ReadFull(rand.Reader, buf)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return buf
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSet(t *testing.T) {
|
|
|
|
s := backend.NewIDSet()
|
|
|
|
|
|
|
|
testID := randomID()
|
|
|
|
err := s.Find(testID)
|
2015-04-09 19:15:48 +00:00
|
|
|
Assert(t, err != nil, "found test ID in IDSet before insertion")
|
2015-01-10 22:40:10 +00:00
|
|
|
|
|
|
|
for i := 0; i < 238; i++ {
|
|
|
|
s.Insert(randomID())
|
|
|
|
}
|
|
|
|
|
|
|
|
s.Insert(testID)
|
2015-04-09 19:15:48 +00:00
|
|
|
OK(t, s.Find(testID))
|
2015-01-10 22:40:10 +00:00
|
|
|
|
|
|
|
for i := 0; i < 80; i++ {
|
|
|
|
s.Insert(randomID())
|
|
|
|
}
|
|
|
|
|
|
|
|
s.Insert(testID)
|
2015-04-09 19:15:48 +00:00
|
|
|
OK(t, s.Find(testID))
|
2015-01-10 22:40:10 +00:00
|
|
|
}
|