func hashTimeouts(min, max time.Duration, multiplier float64) string { return fmt.Sprintf("%x", deephash.Hash(struct { Min, Max time.Duration Multiplier float64 }{ Min: min, Max: max, Multiplier: multiplier, })) }
func TestCrawlSuccess(t *testing.T) { c := newMockCrawler() // Test completable requests testCases := map[string]*fakeResult{ "http://golang.org/": fetcher["http://golang.org/"], "http://golang.org/pkg/": fetcher["http://golang.org/pkg/"], } // Fire! for target, res := range testCases { c.crawl(strToUrl(target), 1, fetcher) var r *Result select { case <-c.skipped: t.Error("Request was skipped") case <-c.errored: t.Error("Request errored") case r = <-c.completed: } assert.NotNil(t, r.Page) assert.NotNil(t, r.Page.Links) // To compare links returned we need to ensure they are in the same datastructure // and in the same order. Converting to a sorted string slice ensures this. links := linksToStrings(r.Page.Links) tclinks := res.urls sort.Strings(links) sort.Strings(tclinks) // Hash both to do a deep comparision of the two assert.Equal(t, deephash.Hash(links), deephash.Hash(tclinks), fmt.Sprintf("%#v and %#v should be equal", links, tclinks)) } }
func hashSlas(m map[string]map[string]time.Duration) string { return fmt.Sprintf("%x", deephash.Hash(m)) }
func hashEndpoints(m map[string]grantedServices) string { return fmt.Sprintf("%x", deephash.Hash(m)) }