update tests

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2021-02-12 20:50:02 +03:00
parent 6e1f30e931
commit f92f3ca5f7
14 changed files with 59 additions and 78 deletions

View File

@@ -8,15 +8,14 @@ import (
"github.com/prometheus/client_golang/prometheus"
dto "github.com/prometheus/client_model/go"
"github.com/stretchr/testify/assert"
bmemory "github.com/unistack-org/micro-broker-memory/v3"
cli "github.com/unistack-org/micro-client-grpc/v3"
jsoncodec "github.com/unistack-org/micro-codec-json/v3"
promwrapper "github.com/unistack-org/micro-metrics-prometheus/v3"
rmemory "github.com/unistack-org/micro-register-memory/v3"
rrouter "github.com/unistack-org/micro-router-register/v3"
srv "github.com/unistack-org/micro-server-grpc/v3"
"github.com/unistack-org/micro/v3/broker"
"github.com/unistack-org/micro/v3/client"
"github.com/unistack-org/micro/v3/register"
"github.com/unistack-org/micro/v3/router"
"github.com/unistack-org/micro/v3/server"
)
@@ -42,8 +41,8 @@ func (t *testHandler) Method(ctx context.Context, req *TestRequest, rsp *TestRes
func TestPrometheusMetrics(t *testing.T) {
client.DefaultRetries = 0
// setup
reg := rmemory.NewRegister()
brk := bmemory.NewBroker(broker.Register(reg))
reg := register.NewRegister()
brk := broker.NewBroker(broker.Register(reg))
name := "test"
id := "id-1234567890"

View File

@@ -9,12 +9,11 @@ import (
"time"
"github.com/juju/ratelimit"
bmemory "github.com/unistack-org/micro-broker-memory/v3"
tmemory "github.com/unistack-org/micro-network-transport-memory"
rmemory "github.com/unistack-org/micro-register-memory/v3"
rrouter "github.com/unistack-org/micro-router-register/v3"
"github.com/unistack-org/micro/v3/broker"
"github.com/unistack-org/micro/v3/client"
"github.com/unistack-org/micro/v3/errors"
"github.com/unistack-org/micro/v3/network/transport"
"github.com/unistack-org/micro/v3/router"
"github.com/unistack-org/micro/v3/server"
)
@@ -29,8 +28,8 @@ func (t *testHandler) Method(ctx context.Context, req *TestRequest, rsp *TestRes
func TestRateClientLimit(t *testing.T) {
// setup
r := rmemory.NewRegister()
tr := tmemory.NewTransport()
r := register.NewRegister()
tr := transport.NewTransport()
testRates := []int{1, 10, 20}
for _, limit := range testRates {
@@ -72,9 +71,9 @@ func TestRateServerLimit(t *testing.T) {
testRates := []int{1, 5, 6, 10}
for _, limit := range testRates {
r := rmemory.NewRegister()
b := bmemory.NewBroker()
tr := tmemory.NewTransport()
r := register.NewRegister()
b := broker.NewBroker()
tr := transport.NewTransport()
_ = b
br := ratelimit.NewBucketWithRate(float64(limit), int64(limit))

View File

@@ -2,22 +2,21 @@ package opentracing_test
import (
"context"
"fmt"
"testing"
opentracing "github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/mocktracer"
"github.com/stretchr/testify/assert"
rbroker "github.com/unistack-org/micro-broker-memory/v3"
cli "github.com/unistack-org/micro-client-grpc/v3"
jsoncodec "github.com/unistack-org/micro-codec-json/v3"
rmemory "github.com/unistack-org/micro-register-memory/v3"
rrouter "github.com/unistack-org/micro-router-register/v3"
srv "github.com/unistack-org/micro-server-grpc/v3"
otwrapper "github.com/unistack-org/micro-wrapper-trace-opentracing/v3"
"github.com/unistack-org/micro/v3/broker"
"github.com/unistack-org/micro/v3/client"
"github.com/unistack-org/micro/v3/errors"
"github.com/unistack-org/micro/v3/logger"
"github.com/unistack-org/micro/v3/register"
"github.com/unistack-org/micro/v3/router"
"github.com/unistack-org/micro/v3/server"
)
@@ -46,6 +45,7 @@ func (t *testHandler) Method(ctx context.Context, req *TestRequest, rsp *TestRes
}
func TestClient(t *testing.T) {
logger.DefaultLogger = logger.NewLogger(logger.WithLevel(logger.ErrorLevel))
// setup
assert := assert.New(t)
for name, tt := range map[string]struct {
@@ -70,8 +70,8 @@ func TestClient(t *testing.T) {
t.Run(name, func(t *testing.T) {
tracer := mocktracer.New()
reg := rmemory.NewRegister()
brk := rbroker.NewBroker(broker.Register(reg))
reg := register.NewRegister()
brk := broker.NewBroker(broker.Register(reg))
serverName := "micro.server.name"
serverID := "id-1234567890"
@@ -83,7 +83,7 @@ func TestClient(t *testing.T) {
client.Codec("application/grpc+json", jsoncodec.NewCodec()),
client.Codec("application/json", jsoncodec.NewCodec()),
client.Router(rt),
client.WrapCall(otwrapper.NewClientCallWrapper(otwrapper.WithTracer(tracer))),
client.Wrap(otwrapper.NewClientWrapper(otwrapper.WithTracer(tracer))),
)
s := srv.NewServer(
@@ -106,19 +106,20 @@ func TestClient(t *testing.T) {
*testHandler
}
s.Handle(s.NewHandler(&Test{new(testHandler)}))
if err := s.Handle(s.NewHandler(&Test{new(testHandler)})); err != nil {
t.Fatal(err)
}
if err := s.Start(); err != nil {
t.Fatalf("Unexpected error starting server: %v", err)
}
ctx, span, err := otwrapper.StartSpanFromContext(context.Background(), tracer, "root")
ctx, span, err := otwrapper.StartSpanFromOutgoingContext(context.Background(), tracer, "root")
assert.NoError(err)
req := c.NewRequest(serverName, "Test.Method", &TestRequest{IsError: tt.isError}, client.WithContentType("application/json"))
rsp := TestResponse{}
err = c.Call(ctx, req, &rsp)
if tt.isError {
assert.Error(err)
} else {
@@ -133,7 +134,6 @@ func TestClient(t *testing.T) {
var rootSpan opentracing.Span
for _, s := range spans {
fmt.Printf("%#+v\n", s)
// order of traces in buffer is not garanteed
switch s.OperationName {
case "root":