Beispiel #1
0
func TestPrefixClient(t *testing.T) {
	const (
		prefix1      = "prefix1"
		prefix2      = "prefix2"
		avgKey       = "avg"
		avgVal       = float64(1)
		sumKey       = "sum"
		sumVal       = float64(2)
		histogramKey = "histogram"
		histogramVal = float64(3)
		timeKey      = "time"
	)

	var keys []string
	hc := &stats.HookClient{
		BumpAvgHook: func(key string, val float64) {
			keys = append(keys, key)
			ensure.DeepEqual(t, val, avgVal)
		},
		BumpSumHook: func(key string, val float64) {
			keys = append(keys, key)
			ensure.DeepEqual(t, val, sumVal)
		},
		BumpHistogramHook: func(key string, val float64) {
			keys = append(keys, key)
			ensure.DeepEqual(t, val, histogramVal)
		},
		BumpTimeHook: func(key string) interface {
			End()
		} {
			return multiEnderTest{
				EndHook: func() {
					keys = append(keys, key)
				},
			}
		},
	}

	pc := stats.PrefixClient([]string{prefix1, prefix2}, hc)
	pc.BumpAvg(avgKey, avgVal)
	pc.BumpSum(sumKey, sumVal)
	pc.BumpHistogram(histogramKey, histogramVal)
	pc.BumpTime(timeKey).End()

	ensure.SameElements(t, keys, []string{
		prefix1 + avgKey,
		prefix1 + sumKey,
		prefix1 + histogramKey,
		prefix1 + timeKey,
		prefix2 + avgKey,
		prefix2 + sumKey,
		prefix2 + histogramKey,
		prefix2 + timeKey,
	})
}
Beispiel #2
0
func TestSameElementsLengthDifference(t *testing.T) {
	var c capture
	ensure.SameElements(&c, []int{1, 2}, []interface{}{1})
	c.Equal(t, `ensure_test.go:190: expected same elements but found slices of different lengths:
ACTUAL:
([]int) (len=2 cap=2) {
 (int) 1,
 (int) 2
}
EXPECTED
([]interface {}) (len=1 cap=1) {
 (int) 1
}`)
}
Beispiel #3
0
func TestSameElementsRepeated(t *testing.T) {
	var c capture
	ensure.SameElements(&c, []int{1, 2}, []interface{}{1, 1})
	c.Equal(t, `ensure_test.go:208: missing expected element:
ACTUAL:
([]int) (len=2 cap=2) {
 (int) 1,
 (int) 2
}
EXPECTED:
([]interface {}) (len=2 cap=2) {
 (int) 1,
 (int) 1
}
MISSING ELEMENT
(int) 1`)
}
Beispiel #4
0
func TestSameElementsIntAndInterface(t *testing.T) {
	ensure.SameElements(t, []int{1, 2}, []interface{}{2, 1})
}