10 type RootSorterSuite struct{}
12 var _ = Suite(&RootSorterSuite{})
14 func FakeSvcRoot(i uint64) string {
15 return fmt.Sprintf("https://%x.svc/", i)
18 func FakeSvcUuid(i uint64) string {
19 return fmt.Sprintf("zzzzz-bi6l4-%015x", i)
22 func FakeServiceRoots(n uint64) map[string]string {
23 sr := map[string]string{}
24 for i := uint64(0); i < n; i++ {
25 sr[FakeSvcUuid(i)] = FakeSvcRoot(i)
30 func (*RootSorterSuite) EmptyRoots(c *C) {
31 rs := NewRootSorter(map[string]string{}, Md5String("foo"))
32 c.Check(rs.GetSortedRoots(), Equals, []string{})
35 func (*RootSorterSuite) JustOneRoot(c *C) {
36 rs := NewRootSorter(FakeServiceRoots(1), Md5String("foo"))
37 c.Check(rs.GetSortedRoots(), Equals, []string{FakeSvcRoot(0)})
40 func (*RootSorterSuite) ReferenceSet(c *C) {
41 fakeroots := FakeServiceRoots(16)
42 // These reference probe orders are explained further in
43 // ../../python/tests/test_keep_client.py:
44 expected_orders := []string{
50 for h, expected_order := range expected_orders {
51 hash := Md5String(fmt.Sprintf("%064x", h))
52 roots := NewRootSorter(fakeroots, hash).GetSortedRoots()
53 for i, svc_id_s := range strings.Split(expected_order, "") {
54 svc_id, err := strconv.ParseUint(svc_id_s, 16, 64)
55 c.Assert(err, Equals, nil)
56 c.Check(roots[i], Equals, FakeSvcRoot(svc_id))