Ejemplo n.º 1
0
// DisorderedSubset attempts to find all the given subsets in the list of actuals.
// Does not allow one actual to match more than one subset, be warray of the
// possibility of insufficiently specific subsets.
func DisorderedSubset(t Fataler, a, s interface{}, extra ...interface{}) {
	actuals := toInterfaceSlice(a)
	subsets := toInterfaceSlice(s)

	used := make([]bool, len(actuals))
	matches := 0
	for _, subset := range subsets {
		for i, actual := range actuals {
			if used[i] {
				continue
			}
			if subsetp.Check(subset, actual) {
				matches++
				used[i] = true
				break
			}
		}
	}
	if matches != len(subsets) {
		fatal(cond{
			Fataler:    t,
			Format:     "expected subsets not found:\nACTUAL:\n%s\nEXPECTED SUBSET\n%s",
			FormatArgs: []interface{}{spew.Sdump(actuals), tsdump(subsets)},
			Extra:      extra,
		})
	}
}
Ejemplo n.º 2
0
// Subset ensures actual matches subset.
func Subset(t Fataler, actual, subset interface{}, a ...interface{}) {
	if !subsetp.Check(subset, actual) {
		fatal(cond{
			Fataler:    t,
			Format:     "expected subset not found:\nACTUAL:\n%s\nEXPECTED SUBSET\n%s",
			FormatArgs: []interface{}{spew.Sdump(actual), tsdump(subset)},
			Extra:      a,
		})
	}
}
Ejemplo n.º 3
0
// ContainsMetric checks if associated gmond instance contains the given
// metric.
func (h *Harness) ContainsMetric(m *gmon.Metric) {
	deadline := time.Now().Add(5 * time.Second)
	for {
		g := h.State()
		for _, cluster := range g.Clusters {
			for _, host := range cluster.Hosts {
				for _, metric := range host.Metrics {
					if subset.Check(m, &metric) {
						return
					}
				}
			}
		}

		if time.Now().After(deadline) {
			h.t.Fatalf("did not find metric\n%s\n--in--\n%s", spew.Sdump(m), spew.Sdump(g))
		}
	}
}