2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-27 04:32:40 +00:00
restic/backend/generic_test.go

62 lines
1.6 KiB
Go
Raw Normal View History

2014-09-23 20:39:12 +00:00
package backend_test
import (
"testing"
2014-12-05 20:45:49 +00:00
"github.com/restic/restic/backend"
2015-04-09 19:15:48 +00:00
. "github.com/restic/restic/test"
2014-09-23 20:39:12 +00:00
)
2014-12-21 14:57:41 +00:00
type mockBackend struct {
2015-03-28 15:42:35 +00:00
list func(backend.Type, <-chan struct{}) <-chan string
2014-12-21 14:57:41 +00:00
}
2015-03-28 10:50:23 +00:00
func (m mockBackend) List(t backend.Type, done <-chan struct{}) <-chan string {
return m.list(t, done)
2014-12-21 14:57:41 +00:00
}
var samples = backend.IDs{
2016-01-26 20:52:02 +00:00
ParseID("20bdc1402a6fc9b633aaffffffffffffffffffffffffffffffffffffffffffff"),
ParseID("20bdc1402a6fc9b633ccd578c4a92d0f4ef1a457fa2e16c596bc73fb409d6cc0"),
ParseID("20bdc1402a6fc9b633ffffffffffffffffffffffffffffffffffffffffffffff"),
ParseID("20ff988befa5fc40350f00d531a767606efefe242c837aaccb80673f286be53d"),
ParseID("326cb59dfe802304f96ee9b5b9af93bdee73a30f53981e5ec579aedb6f1d0f07"),
ParseID("86b60b9594d1d429c4aa98fa9562082cabf53b98c7dc083abe5dae31074dd15a"),
ParseID("96c8dbe225079e624b5ce509f5bd817d1453cd0a85d30d536d01b64a8669aeae"),
ParseID("fa31d65b87affcd167b119e9d3d2a27b8236ca4836cb077ed3e96fcbe209b792"),
}
func TestPrefixLength(t *testing.T) {
2014-12-21 14:57:41 +00:00
list := samples
m := mockBackend{}
2015-03-28 10:50:23 +00:00
m.list = func(t backend.Type, done <-chan struct{}) <-chan string {
ch := make(chan string)
go func() {
defer close(ch)
for _, id := range list {
select {
case ch <- id.String():
case <-done:
return
}
}
}()
return ch
2014-12-21 14:57:41 +00:00
}
l, err := backend.PrefixLength(m, backend.Snapshot)
2015-04-09 19:15:48 +00:00
OK(t, err)
Equals(t, 19, l)
2014-12-21 14:57:41 +00:00
list = samples[:3]
l, err = backend.PrefixLength(m, backend.Snapshot)
2015-04-09 19:15:48 +00:00
OK(t, err)
Equals(t, 19, l)
2014-12-21 14:57:41 +00:00
list = samples[3:]
l, err = backend.PrefixLength(m, backend.Snapshot)
2015-04-09 19:15:48 +00:00
OK(t, err)
Equals(t, 8, l)
}