示例#1
0
func TestMultiCollector(t *testing.T) {
	cs := zipkin.MultiCollector{
		&stubCollector{errid: 1},
		&stubCollector{},
		&stubCollector{errid: 2},
	}
	err := cs.Collect(s)
	if err == nil {
		t.Fatal("wanted error, got none")
	}
	if want, have := "error 1; error 2", err.Error(); want != have {
		t.Errorf("want %q, have %q", want, have)
	}
	collectionError := err.(zipkin.CollectionError).GetErrors()
	if want, have := 3, len(collectionError); want != have {
		t.Fatalf("want %d, have %d", want, have)
	}
	if want, have := cs[0].Collect(s).Error(), collectionError[0].Error(); want != have {
		t.Errorf("want %q, have %q", want, have)
	}
	if want, have := cs[1].Collect(s), collectionError[1]; want != have {
		t.Errorf("want %q, have %q", want, have)
	}
	if want, have := cs[2].Collect(s).Error(), collectionError[2].Error(); want != have {
		t.Errorf("want %q, have %q", want, have)
	}

	for _, c := range cs {
		if !c.(*stubCollector).collected {
			t.Error("collect not called")
		}
	}
}
示例#2
0
func TestMultiCollectorClose(t *testing.T) {
	cs := zipkin.MultiCollector{
		&stubCollector{errid: 1},
		&stubCollector{},
		&stubCollector{errid: 2},
	}
	err := cs.Close()
	if err == nil {
		t.Fatal("wanted error, got none")
	}
	if want, have := "error 1; error 2", err.Error(); want != have {
		t.Errorf("want %q, have %q", want, have)
	}

	for _, c := range cs {
		if !c.(*stubCollector).closed {
			t.Error("close not called")
		}
	}
}