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