Add tests for trace registry
This commit is contained in:
45
cmd/cencus_test.go
Normal file
45
cmd/cencus_test.go
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/cpuguy83/strongerrors"
|
||||||
|
|
||||||
|
"go.opencensus.io/trace"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGetTracingExporter(t *testing.T) {
|
||||||
|
defer delete(tracingExporters, "mock")
|
||||||
|
|
||||||
|
mockExporterFn := func(_ TracingExporterOptions) (trace.Exporter, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := GetTracingExporter("notexist", TracingExporterOptions{})
|
||||||
|
if !strongerrors.IsNotFound(err) {
|
||||||
|
t.Fatalf("expected not found error, got: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
RegisterTracingExporter("mock", mockExporterFn)
|
||||||
|
|
||||||
|
if _, err := GetTracingExporter("mock", TracingExporterOptions{}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAvailableExporters(t *testing.T) {
|
||||||
|
defer delete(tracingExporters, "mock")
|
||||||
|
|
||||||
|
mockExporterFn := func(_ TracingExporterOptions) (trace.Exporter, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
RegisterTracingExporter("mock", mockExporterFn)
|
||||||
|
|
||||||
|
for _, e := range AvailableTraceExporters() {
|
||||||
|
if e == "mock" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Fatal("could not find mock exporter in list of registered exporters")
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/cpuguy83/strongerrors"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/virtual-kubelet/virtual-kubelet/log"
|
"github.com/virtual-kubelet/virtual-kubelet/log"
|
||||||
"go.opencensus.io/trace"
|
"go.opencensus.io/trace"
|
||||||
@@ -42,7 +43,7 @@ func RegisterTracingExporter(name string, f TracingExporterInitFunc) {
|
|||||||
func GetTracingExporter(name string, opts TracingExporterOptions) (trace.Exporter, error) {
|
func GetTracingExporter(name string, opts TracingExporterOptions) (trace.Exporter, error) {
|
||||||
f, ok := tracingExporters[name]
|
f, ok := tracingExporters[name]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.Errorf("tracing exporter %q not found", name)
|
return nil, strongerrors.NotFound(errors.Errorf("tracing exporter %q not found", name))
|
||||||
}
|
}
|
||||||
return f(opts)
|
return f(opts)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user