1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
14 type RootSorterSuite struct{}
16 var _ = Suite(&RootSorterSuite{})
18 func FakeSvcRoot(i uint64) string {
19 return fmt.Sprintf("https://%x.svc/", i)
22 func FakeSvcUUID(i uint64) string {
23 return fmt.Sprintf("zzzzz-bi6l4-%015x", i)
26 func FakeServiceRoots(n uint64) map[string]string {
27 sr := map[string]string{}
28 for i := uint64(0); i < n; i++ {
29 sr[FakeSvcUUID(i)] = FakeSvcRoot(i)
34 func (*RootSorterSuite) EmptyRoots(c *C) {
35 rs := NewRootSorter(map[string]string{}, Md5String("foo"))
36 c.Check(rs.GetSortedRoots(), Equals, []string{})
39 func (*RootSorterSuite) JustOneRoot(c *C) {
40 rs := NewRootSorter(FakeServiceRoots(1), Md5String("foo"))
41 c.Check(rs.GetSortedRoots(), Equals, []string{FakeSvcRoot(0)})
44 func (*RootSorterSuite) ReferenceSet(c *C) {
45 fakeroots := FakeServiceRoots(16)
46 // These reference probe orders are explained further in
47 // ../../python/tests/test_keep_client.py:
48 expectedOrders := []string{
54 for h, expectedOrder := range expectedOrders {
55 hash := Md5String(fmt.Sprintf("%064x", h))
56 roots := NewRootSorter(fakeroots, hash).GetSortedRoots()
57 for i, svcIDs := range strings.Split(expectedOrder, "") {
58 svcID, err := strconv.ParseUint(svcIDs, 16, 64)
59 c.Assert(err, Equals, nil)
60 c.Check(roots[i], Equals, FakeSvcRoot(svcID))