예제 #1
0
func TestPrefixLength(t *testing.T) {
	list := samples

	m := mockBackend{}
	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
	}

	l, err := backend.PrefixLength(m, backend.Snapshot)
	OK(t, err)
	Equals(t, 19, l)

	list = samples[:3]
	l, err = backend.PrefixLength(m, backend.Snapshot)
	OK(t, err)
	Equals(t, 19, l)

	list = samples[3:]
	l, err = backend.PrefixLength(m, backend.Snapshot)
	OK(t, err)
	Equals(t, 8, l)
}
예제 #2
0
// PrefixLength returns the number of bytes required so that all prefixes of
// all IDs of type t are unique.
func (r *Repository) PrefixLength(t backend.Type) (int, error) {
	return backend.PrefixLength(r.be, t)
}