Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2020-10-30 23:27:33 +03:00
parent 9609706c86
commit 848ffcb6d7
9 changed files with 704 additions and 54 deletions

View File

@ -1,6 +1,7 @@
package http_test package http_test
import ( import (
"context"
"sync" "sync"
"testing" "testing"
"time" "time"
@ -55,7 +56,7 @@ var (
) )
func newTestRegistry() registry.Registry { func newTestRegistry() registry.Registry {
return rmemory.NewRegistry(rmemory.Services(testData)) return rmemory.NewRegistry()
} }
func sub(be *testing.B, c int) { func sub(be *testing.B, c int) {
@ -69,7 +70,7 @@ func sub(be *testing.B, c int) {
be.Fatalf("Unexpected init error: %v", err) be.Fatalf("Unexpected init error: %v", err)
} }
if err := b.Connect(); err != nil { if err := b.Connect(context.TODO()); err != nil {
be.Fatalf("Unexpected connect error: %v", err) be.Fatalf("Unexpected connect error: %v", err)
} }
@ -84,7 +85,7 @@ func sub(be *testing.B, c int) {
done := make(chan bool, c) done := make(chan bool, c)
for i := 0; i < c; i++ { for i := 0; i < c; i++ {
sub, err := b.Subscribe(topic, func(p broker.Event) error { sub, err := b.Subscribe(context.TODO(), topic, func(p broker.Event) error {
done <- true done <- true
m := p.Message() m := p.Message()
@ -102,7 +103,7 @@ func sub(be *testing.B, c int) {
for i := 0; i < be.N; i++ { for i := 0; i < be.N; i++ {
be.StartTimer() be.StartTimer()
if err := b.Publish(topic, msg); err != nil { if err := b.Publish(context.TODO(), topic, msg); err != nil {
be.Fatalf("Unexpected publish error: %v", err) be.Fatalf("Unexpected publish error: %v", err)
} }
<-done <-done
@ -110,10 +111,10 @@ func sub(be *testing.B, c int) {
} }
for _, sub := range subs { for _, sub := range subs {
sub.Unsubscribe() sub.Unsubscribe(context.TODO())
} }
if err := b.Disconnect(); err != nil { if err := b.Disconnect(context.TODO()); err != nil {
be.Fatalf("Unexpected disconnect error: %v", err) be.Fatalf("Unexpected disconnect error: %v", err)
} }
} }
@ -128,7 +129,7 @@ func pub(be *testing.B, c int) {
be.Fatalf("Unexpected init error: %v", err) be.Fatalf("Unexpected init error: %v", err)
} }
if err := b.Connect(); err != nil { if err := b.Connect(context.TODO()); err != nil {
be.Fatalf("Unexpected connect error: %v", err) be.Fatalf("Unexpected connect error: %v", err)
} }
@ -141,7 +142,7 @@ func pub(be *testing.B, c int) {
done := make(chan bool, c*4) done := make(chan bool, c*4)
sub, err := b.Subscribe(topic, func(p broker.Event) error { sub, err := b.Subscribe(context.TODO(), topic, func(p broker.Event) error {
done <- true done <- true
m := p.Message() m := p.Message()
if string(m.Body) != string(msg.Body) { if string(m.Body) != string(msg.Body) {
@ -160,7 +161,7 @@ func pub(be *testing.B, c int) {
for i := 0; i < c; i++ { for i := 0; i < c; i++ {
go func() { go func() {
for range ch { for range ch {
if err := b.Publish(topic, msg); err != nil { if err := b.Publish(context.TODO(), topic, msg); err != nil {
be.Fatalf("Unexpected publish error: %v", err) be.Fatalf("Unexpected publish error: %v", err)
} }
select { select {
@ -179,11 +180,11 @@ func pub(be *testing.B, c int) {
wg.Wait() wg.Wait()
be.StopTimer() be.StopTimer()
sub.Unsubscribe() sub.Unsubscribe(context.TODO())
close(ch) close(ch)
close(done) close(done)
if err := b.Disconnect(); err != nil { if err := b.Disconnect(context.TODO()); err != nil {
be.Fatalf("Unexpected disconnect error: %v", err) be.Fatalf("Unexpected disconnect error: %v", err)
} }
} }
@ -196,7 +197,7 @@ func TestBroker(t *testing.T) {
t.Fatalf("Unexpected init error: %v", err) t.Fatalf("Unexpected init error: %v", err)
} }
if err := b.Connect(); err != nil { if err := b.Connect(context.TODO()); err != nil {
t.Fatalf("Unexpected connect error: %v", err) t.Fatalf("Unexpected connect error: %v", err)
} }
@ -209,7 +210,7 @@ func TestBroker(t *testing.T) {
done := make(chan bool) done := make(chan bool)
sub, err := b.Subscribe("test", func(p broker.Event) error { sub, err := b.Subscribe(context.TODO(), "test", func(p broker.Event) error {
m := p.Message() m := p.Message()
if string(m.Body) != string(msg.Body) { if string(m.Body) != string(msg.Body) {
@ -223,14 +224,14 @@ func TestBroker(t *testing.T) {
t.Fatalf("Unexpected subscribe error: %v", err) t.Fatalf("Unexpected subscribe error: %v", err)
} }
if err := b.Publish("test", msg); err != nil { if err := b.Publish(context.TODO(), "test", msg); err != nil {
t.Fatalf("Unexpected publish error: %v", err) t.Fatalf("Unexpected publish error: %v", err)
} }
<-done <-done
sub.Unsubscribe() sub.Unsubscribe(context.TODO())
if err := b.Disconnect(); err != nil { if err := b.Disconnect(context.TODO()); err != nil {
t.Fatalf("Unexpected disconnect error: %v", err) t.Fatalf("Unexpected disconnect error: %v", err)
} }
} }
@ -243,7 +244,7 @@ func TestConcurrentSubBroker(t *testing.T) {
t.Fatalf("Unexpected init error: %v", err) t.Fatalf("Unexpected init error: %v", err)
} }
if err := b.Connect(); err != nil { if err := b.Connect(context.TODO()); err != nil {
t.Fatalf("Unexpected connect error: %v", err) t.Fatalf("Unexpected connect error: %v", err)
} }
@ -258,7 +259,7 @@ func TestConcurrentSubBroker(t *testing.T) {
var wg sync.WaitGroup var wg sync.WaitGroup
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
sub, err := b.Subscribe("test", func(p broker.Event) error { sub, err := b.Subscribe(context.TODO(), "test", func(p broker.Event) error {
defer wg.Done() defer wg.Done()
m := p.Message() m := p.Message()
@ -277,17 +278,17 @@ func TestConcurrentSubBroker(t *testing.T) {
subs = append(subs, sub) subs = append(subs, sub)
} }
if err := b.Publish("test", msg); err != nil { if err := b.Publish(context.TODO(), "test", msg); err != nil {
t.Fatalf("Unexpected publish error: %v", err) t.Fatalf("Unexpected publish error: %v", err)
} }
wg.Wait() wg.Wait()
for _, sub := range subs { for _, sub := range subs {
sub.Unsubscribe() sub.Unsubscribe(context.TODO())
} }
if err := b.Disconnect(); err != nil { if err := b.Disconnect(context.TODO()); err != nil {
t.Fatalf("Unexpected disconnect error: %v", err) t.Fatalf("Unexpected disconnect error: %v", err)
} }
} }
@ -300,7 +301,7 @@ func TestConcurrentPubBroker(t *testing.T) {
t.Fatalf("Unexpected init error: %v", err) t.Fatalf("Unexpected init error: %v", err)
} }
if err := b.Connect(); err != nil { if err := b.Connect(context.TODO()); err != nil {
t.Fatalf("Unexpected connect error: %v", err) t.Fatalf("Unexpected connect error: %v", err)
} }
@ -313,7 +314,7 @@ func TestConcurrentPubBroker(t *testing.T) {
var wg sync.WaitGroup var wg sync.WaitGroup
sub, err := b.Subscribe("test", func(p broker.Event) error { sub, err := b.Subscribe(context.TODO(), "test", func(p broker.Event) error {
defer wg.Done() defer wg.Done()
m := p.Message() m := p.Message()
@ -331,16 +332,16 @@ func TestConcurrentPubBroker(t *testing.T) {
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
wg.Add(1) wg.Add(1)
if err := b.Publish("test", msg); err != nil { if err := b.Publish(context.TODO(), "test", msg); err != nil {
t.Fatalf("Unexpected publish error: %v", err) t.Fatalf("Unexpected publish error: %v", err)
} }
} }
wg.Wait() wg.Wait()
sub.Unsubscribe() sub.Unsubscribe(context.TODO())
if err := b.Disconnect(); err != nil { if err := b.Disconnect(context.TODO()); err != nil {
t.Fatalf("Unexpected disconnect error: %v", err) t.Fatalf("Unexpected disconnect error: %v", err)
} }
} }

18
go.mod
View File

@ -7,14 +7,16 @@ require (
github.com/google/uuid v1.1.2 github.com/google/uuid v1.1.2
github.com/opentracing/opentracing-go v1.2.0 github.com/opentracing/opentracing-go v1.2.0
github.com/stretchr/testify v1.5.1 github.com/stretchr/testify v1.5.1
github.com/unistack-org/micro-broker-http v0.0.0-20200922090138-225f968e7987 github.com/unistack-org/micro-broker-http v0.0.0-20201016091727-9b556114b216
github.com/unistack-org/micro-broker-memory v0.0.0-20200905101815-4594aa2807e9 github.com/unistack-org/micro-broker-memory v0.0.2-0.20201016070326-b0839e582a1f
github.com/unistack-org/micro-client-grpc v0.0.0-20200929074245-854839ba45c6 github.com/unistack-org/micro-client-grpc v0.0.2-0.20201028070730-15a5d7d2cde8
github.com/unistack-org/micro-registry-memory v0.0.0-20200922085412-e854aa749c33 github.com/unistack-org/micro-registry-memory v0.0.2-0.20201016083512-540f3b8acc71
github.com/unistack-org/micro-router-registry v0.0.0-20200920130103-a1ccc75a7761 github.com/unistack-org/micro-router-registry v0.0.1
github.com/unistack-org/micro-server-grpc v0.0.0-20200929074212-371cc6044cac github.com/unistack-org/micro-server-grpc v0.0.2-0.20201029181124-edaf9eaaa616
github.com/unistack-org/micro-wrapper-opentracing v0.0.0-20200929081121-432ff27b1f2c github.com/unistack-org/micro-server-http v0.0.2-0.20201016134639-e20ed5dc3269
github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20200928100853-efd9075d9b4a github.com/unistack-org/micro-server-tcp v0.0.2-0.20201016134852-ee43cf634964
github.com/unistack-org/micro-wrapper-opentracing v0.0.1
github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20201029131631-ddb53bf8e4c8
google.golang.org/grpc v1.31.1 google.golang.org/grpc v1.31.1
google.golang.org/protobuf v1.25.0 google.golang.org/protobuf v1.25.0
) )

52
go.sum
View File

@ -132,6 +132,7 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/gophercloud/gophercloud v0.3.0/go.mod h1:vxM41WHh5uqHVBMZHzuwNOHh8XEoIEcSTewFxm1c5g8= github.com/gophercloud/gophercloud v0.3.0/go.mod h1:vxM41WHh5uqHVBMZHzuwNOHh8XEoIEcSTewFxm1c5g8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
@ -151,6 +152,7 @@ github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCV
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
@ -178,6 +180,7 @@ github.com/micro/cli/v2 v2.1.2 h1:43J1lChg/rZCC1rvdqZNFSQDrGT7qfMrtp6/ztpIkEM=
github.com/micro/cli/v2 v2.1.2/go.mod h1:EguNh6DAoWKm9nmk+k/Rg0H3lQnDxqzu5x5srOtGtYg= github.com/micro/cli/v2 v2.1.2/go.mod h1:EguNh6DAoWKm9nmk+k/Rg0H3lQnDxqzu5x5srOtGtYg=
github.com/miekg/dns v1.1.15/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.15/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/miekg/dns v1.1.27/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM= github.com/miekg/dns v1.1.27/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM=
github.com/miekg/dns v1.1.31 h1:sJFOl9BgwbYAWOGEwr61FU28pqsBNdpRBnhGXtO06Oo=
github.com/miekg/dns v1.1.31/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM= github.com/miekg/dns v1.1.31/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-vnc v0.0.0-20150629162542-723ed9867aed/go.mod h1:3rdaFaCv4AyBgu5ALFM0+tSuHrBh6v692nyQe3ikrq0= github.com/mitchellh/go-vnc v0.0.0-20150629162542-723ed9867aed/go.mod h1:3rdaFaCv4AyBgu5ALFM0+tSuHrBh6v692nyQe3ikrq0=
@ -211,6 +214,7 @@ github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTK
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
@ -242,7 +246,9 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/skratchdot/open-golang v0.0.0-20160302144031-75fb7ed4208c/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog= github.com/skratchdot/open-golang v0.0.0-20160302144031-75fb7ed4208c/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a h1:pa8hGb/2YqsZKovtsgrwcDH1RZhVbTKCjLp47XpqCDs=
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
@ -254,37 +260,42 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
github.com/timewasted/linode v0.0.0-20160829202747-37e84520dcf7/go.mod h1:imsgLplxEC/etjIhdr3dNzV3JeT27LbVu5pYWm0JCBY= github.com/timewasted/linode v0.0.0-20160829202747-37e84520dcf7/go.mod h1:imsgLplxEC/etjIhdr3dNzV3JeT27LbVu5pYWm0JCBY=
github.com/transip/gotransip v0.0.0-20190812104329-6d8d9179b66f/go.mod h1:i0f4R4o2HM0m3DZYQWsj6/MEowD57VzoH0v3d7igeFY= github.com/transip/gotransip v0.0.0-20190812104329-6d8d9179b66f/go.mod h1:i0f4R4o2HM0m3DZYQWsj6/MEowD57VzoH0v3d7igeFY=
github.com/uber-go/atomic v1.3.2/go.mod h1:/Ct5t2lcmbJ4OSe/waGBoaVvVqtO0bmtfVNex1PFV8g= github.com/uber-go/atomic v1.3.2/go.mod h1:/Ct5t2lcmbJ4OSe/waGBoaVvVqtO0bmtfVNex1PFV8g=
github.com/unistack-org/micro-broker-http v0.0.0-20200922090138-225f968e7987 h1:Jbo+qaAI5vkG0Rhn9q6n6+XaO3FtDsecAoGOLtZhmO0= github.com/unistack-org/micro-broker-http v0.0.0-20201016091727-9b556114b216 h1:TnXkXcoL38ur7FgZUVIivMqVhEMt9Fa1LzcGmBVHkek=
github.com/unistack-org/micro-broker-http v0.0.0-20200922090138-225f968e7987/go.mod h1:YGEdVyk2lIWZ8cFuA/ja1HqvWy0R6mhOpOz2S2DzyGM= github.com/unistack-org/micro-broker-http v0.0.0-20201016091727-9b556114b216/go.mod h1:FR70aAKQS3YgqgwaCz1QtfVnfe3wI5pb5LYaqyXHhGM=
github.com/unistack-org/micro-broker-memory v0.0.0-20200905101815-4594aa2807e9 h1:SHiNeIiNjs7BOjmS4tpb3amZKldUTigFiYtWzWOvHCU= github.com/unistack-org/micro-broker-memory v0.0.2-0.20201016070326-b0839e582a1f h1:493n3a+jy+UOZh+aGoaCrdVJI/MEreZzcAPVE+TN5VM=
github.com/unistack-org/micro-broker-memory v0.0.0-20200905101815-4594aa2807e9/go.mod h1:j19KFne7Y8JvNXHwhjgjVJWAZDoqbnArZTMDEjyVWu0= github.com/unistack-org/micro-broker-memory v0.0.2-0.20201016070326-b0839e582a1f/go.mod h1:DvqNKOik/6Tfbv8wVkxv76ozArlwC8yXZbKXTQlnANo=
github.com/unistack-org/micro-client-grpc v0.0.0-20200929074245-854839ba45c6 h1:ETVDejpcJJIjcncTJl/DrzKqeJqMYyXIakgw42eJmys= github.com/unistack-org/micro-client-grpc v0.0.2-0.20201028070730-15a5d7d2cde8 h1:ozSg+KCknYKVYrRAH4j1kssc2TBJhuvrxl6z3xXmXsQ=
github.com/unistack-org/micro-client-grpc v0.0.0-20200929074245-854839ba45c6/go.mod h1:NH2+tji2EM4TD4oKX1JqXVsBh8MjhFI8orEQPPN/7vc= github.com/unistack-org/micro-client-grpc v0.0.2-0.20201028070730-15a5d7d2cde8/go.mod h1:VQQ0HUGgk1IWrtTUetEV7UMuy2KWsLX5GV3UWUZBpQQ=
github.com/unistack-org/micro-codec-bytes v0.0.0-20200828083432-4e49e953d844 h1:5b1yuSllbsMm/9fUIlIXSr8DbsKT/sAKSCgOx6+SAfI= github.com/unistack-org/micro-codec-bytes v0.0.0-20200828083432-4e49e953d844 h1:5b1yuSllbsMm/9fUIlIXSr8DbsKT/sAKSCgOx6+SAfI=
github.com/unistack-org/micro-codec-bytes v0.0.0-20200828083432-4e49e953d844/go.mod h1:g5sOI8TWgGZiVHe8zoUPdtz7+0oLnqTnfBoai6Qb7jE= github.com/unistack-org/micro-codec-bytes v0.0.0-20200828083432-4e49e953d844/go.mod h1:g5sOI8TWgGZiVHe8zoUPdtz7+0oLnqTnfBoai6Qb7jE=
github.com/unistack-org/micro-config-cmd v0.0.0-20200828075439-d859b9d7265b/go.mod h1:6pm1cadbwsFcEW1ZbV5Fp0i3goR3TNfROMNSPih3I8k=
github.com/unistack-org/micro-config-cmd v0.0.0-20200909210346-ec89783dc46c/go.mod h1:6pm1cadbwsFcEW1ZbV5Fp0i3goR3TNfROMNSPih3I8k= github.com/unistack-org/micro-config-cmd v0.0.0-20200909210346-ec89783dc46c/go.mod h1:6pm1cadbwsFcEW1ZbV5Fp0i3goR3TNfROMNSPih3I8k=
github.com/unistack-org/micro-config-cmd v0.0.0-20200909210755-6e7e85eeab34/go.mod h1:fT1gYn+TtfVZZ5tNx56bZIncJjmlji66g7GKdWua5hE= github.com/unistack-org/micro-config-cmd v0.0.0-20200909210755-6e7e85eeab34/go.mod h1:fT1gYn+TtfVZZ5tNx56bZIncJjmlji66g7GKdWua5hE=
github.com/unistack-org/micro-config-cmd v0.0.0-20200920140133-0853deb2e5dc h1:hHAU3rgeiA0LaudfNdMLf9/jkOBeFxvJdnwXevviZF8= github.com/unistack-org/micro-config-cmd v0.0.0-20200920140133-0853deb2e5dc h1:hHAU3rgeiA0LaudfNdMLf9/jkOBeFxvJdnwXevviZF8=
github.com/unistack-org/micro-config-cmd v0.0.0-20200920140133-0853deb2e5dc/go.mod h1:il8nz4ZEcX3Usyfrtwy+YtQcb7xSUSFJdSe8PBJ9gOA= github.com/unistack-org/micro-config-cmd v0.0.0-20200920140133-0853deb2e5dc/go.mod h1:il8nz4ZEcX3Usyfrtwy+YtQcb7xSUSFJdSe8PBJ9gOA=
github.com/unistack-org/micro-registry-memory v0.0.0-20200922085412-e854aa749c33 h1:W1wJ4BwMFc3YVfNf8oOP2CCF4oNC5q03CKE0qMuEcxY= github.com/unistack-org/micro-config-cmd v0.0.0-20201028144621-5a55f1aad70a h1:VjlqP1qZkjC0Chmx5MKFPIbtSCigeICFDf8vaLZGh9o=
github.com/unistack-org/micro-registry-memory v0.0.0-20200922085412-e854aa749c33/go.mod h1:yJXBTGKhp3bGm2SboQlxxNlViAuF8hQlYf1PntdYryA= github.com/unistack-org/micro-config-cmd v0.0.0-20201028144621-5a55f1aad70a/go.mod h1:MzMg+qh1wORZwYtg5AVgFkNFrXVVbdPKW7s/Is+A994=
github.com/unistack-org/micro-router-registry v0.0.0-20200920130103-a1ccc75a7761 h1:ojJXjWNqSXF6LGkiOKpDp+Cq5pfGcu1EmTBPbyWTYZg= github.com/unistack-org/micro-registry-memory v0.0.2-0.20201016083512-540f3b8acc71 h1:AxW65Wddbcj98G/GhiH9Hm7sqcaOgJnLsAdRAqFb7gU=
github.com/unistack-org/micro-router-registry v0.0.0-20200920130103-a1ccc75a7761/go.mod h1:mobzF4hd2yI5aZcxdE2Q5bUAGA+g0mV6o/k228berxY= github.com/unistack-org/micro-registry-memory v0.0.2-0.20201016083512-540f3b8acc71/go.mod h1:rpxpieyrpBxus+oOTSzkJY0iFK+qNpYXOhAdogvmtGE=
github.com/unistack-org/micro-server-grpc v0.0.0-20200929074212-371cc6044cac h1:/ZBDN/rn0tRcCg1koi33FjFu2q1ADbit1ZbOu/I/PEQ= github.com/unistack-org/micro-router-registry v0.0.1 h1:Gs8FbyHixp/h2aXXEqOxaa95MrXR2LgjBAdQE6WOAic=
github.com/unistack-org/micro-server-grpc v0.0.0-20200929074212-371cc6044cac/go.mod h1:3q7iOC9p1EEyC12gsiUL7HiYD9I44IdnhdW6y8ZkrgQ= github.com/unistack-org/micro-router-registry v0.0.1/go.mod h1:mobzF4hd2yI5aZcxdE2Q5bUAGA+g0mV6o/k228berxY=
github.com/unistack-org/micro-wrapper-opentracing v0.0.0-20200929081121-432ff27b1f2c h1:LRY9I4Ed16B7KkitEe4KOjlxzrQYeMECT9e1epkIZEE= github.com/unistack-org/micro-server-grpc v0.0.2-0.20201029181124-edaf9eaaa616 h1:B68bEEfDdwEzB0FEGtWk0CEc6jacXANgdw/EaYpQ7VU=
github.com/unistack-org/micro-wrapper-opentracing v0.0.0-20200929081121-432ff27b1f2c/go.mod h1:cSUWWr/frBBcKV4f5VRSN9dsFv6PWRV3rPaa6ULnZCw= github.com/unistack-org/micro-server-grpc v0.0.2-0.20201029181124-edaf9eaaa616/go.mod h1:n55+gdhJnH8iDtu+qkpAR2ybizq8U2UUDRDvpFUG74Y=
github.com/unistack-org/micro/v3 v3.0.0-20200827081802-b4ccde222831/go.mod h1:rPQbnry3nboAnMczj8B1Gzlcyv/HYoMZLgd3/3nttJ4= github.com/unistack-org/micro-server-http v0.0.2-0.20201016134639-e20ed5dc3269 h1:qnfrkgQDoNeKfLKustqZh8qjxWQ7+MTbMJSkUoN7hzs=
github.com/unistack-org/micro-server-http v0.0.2-0.20201016134639-e20ed5dc3269/go.mod h1:ZjDi96CESDSOsKBuEIlqWn44RjKFJyjn0yxcolV7zU8=
github.com/unistack-org/micro-server-tcp v0.0.2-0.20201016134852-ee43cf634964 h1:b+cmhYBflJJuD7n+lQ6VhciQYp/6L90oWVtMYJUxJVY=
github.com/unistack-org/micro-server-tcp v0.0.2-0.20201016134852-ee43cf634964/go.mod h1:Or7lx8k2jdz+foN+a8wEe7NWE49P6f/9Y92aLBZ4680=
github.com/unistack-org/micro-wrapper-opentracing v0.0.1 h1:GOyN4CMbtJxEW8knB9DrRbgyaCtwOxqFtNqr2FVwoMk=
github.com/unistack-org/micro-wrapper-opentracing v0.0.1/go.mod h1:cSUWWr/frBBcKV4f5VRSN9dsFv6PWRV3rPaa6ULnZCw=
github.com/unistack-org/micro/v3 v3.0.0-20200827083227-aa99378adc6e/go.mod h1:rPQbnry3nboAnMczj8B1Gzlcyv/HYoMZLgd3/3nttJ4= github.com/unistack-org/micro/v3 v3.0.0-20200827083227-aa99378adc6e/go.mod h1:rPQbnry3nboAnMczj8B1Gzlcyv/HYoMZLgd3/3nttJ4=
github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20200904234316-e7d418183b62/go.mod h1:mB0h+i3Sa4jD8G2dv97cAAdyh01hVQWKw4xSdmTpyOo=
github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20200909210629-caec730248b1/go.mod h1:mmqHR9WelHUXqg2mELjsQ+FJHcWs6mNmXg+wEYO2T3c= github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20200909210629-caec730248b1/go.mod h1:mmqHR9WelHUXqg2mELjsQ+FJHcWs6mNmXg+wEYO2T3c=
github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20200920124807-9b11ea527aeb/go.mod h1:HUzMG4Mcy97958VxWTg8zuazZgwQ/aoLZ8wtBVONwRE= github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20200920124807-9b11ea527aeb/go.mod h1:HUzMG4Mcy97958VxWTg8zuazZgwQ/aoLZ8wtBVONwRE=
github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20200920135754-1cbd1d2bad83/go.mod h1:HUzMG4Mcy97958VxWTg8zuazZgwQ/aoLZ8wtBVONwRE= github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20200920135754-1cbd1d2bad83/go.mod h1:HUzMG4Mcy97958VxWTg8zuazZgwQ/aoLZ8wtBVONwRE=
github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20200920140241-dc5dc6ab5b47 h1:D/xvvOXZgcHcVjHz7ICjHkt+Ka5g+ZwaPlbngFkNWd8= github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20200922103357-4c4fa00a5d94/go.mod h1:aL+8VhSXpx0SuEeXPOWUo5BgS7kyvWYobeXFay90UUM=
github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20200920140241-dc5dc6ab5b47/go.mod h1:aL+8VhSXpx0SuEeXPOWUo5BgS7kyvWYobeXFay90UUM=
github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20200928100853-efd9075d9b4a h1:v3r3lbYNH3yHPHhHpmR/TZUnOzMMlVbq0HSe65lWp3I= github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20200928100853-efd9075d9b4a h1:v3r3lbYNH3yHPHhHpmR/TZUnOzMMlVbq0HSe65lWp3I=
github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20200928100853-efd9075d9b4a/go.mod h1:aL+8VhSXpx0SuEeXPOWUo5BgS7kyvWYobeXFay90UUM= github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20200928100853-efd9075d9b4a/go.mod h1:aL+8VhSXpx0SuEeXPOWUo5BgS7kyvWYobeXFay90UUM=
github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20201016063857-14c97d59c15f/go.mod h1:aL+8VhSXpx0SuEeXPOWUo5BgS7kyvWYobeXFay90UUM=
github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20201029131631-ddb53bf8e4c8 h1:Mo2EJcbwCA96yzzrpoCgGj+lqRZ2RGes8/hKlkzChQs=
github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20201029131631-ddb53bf8e4c8/go.mod h1:/api3BpIGjf/9C3G75SGQ/byDpgpuyXIDe36n8lWl7s=
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/vultr/govultr v0.1.4/go.mod h1:9H008Uxr/C4vFNGLqKx232C206GL0PBHzOP0809bGNA= github.com/vultr/govultr v0.1.4/go.mod h1:9H008Uxr/C4vFNGLqKx232C206GL0PBHzOP0809bGNA=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
@ -307,6 +318,7 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a h1:vclmkQCjlDX5OydZ9wv8rBCcS0QyQY66Mpf/7BZbInM=
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
@ -348,7 +360,6 @@ golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20190930134127-c5a3c61f89f3/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190930134127-c5a3c61f89f3/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191027093000-83d349e8ac1a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191027093000-83d349e8ac1a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20200904194848-62affa334b73 h1:MXfv8rhZWmFeqX3GNZRsd6vOLoaCHjYEX3qkRo3YBUA= golang.org/x/net v0.0.0-20200904194848-62affa334b73 h1:MXfv8rhZWmFeqX3GNZRsd6vOLoaCHjYEX3qkRo3YBUA=
golang.org/x/net v0.0.0-20200904194848-62affa334b73/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200904194848-62affa334b73/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
@ -391,6 +402,7 @@ golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0 h1:xQwXv67TxFo9nC1GJFyab5eq/5B590r6RlnL/G8Sz7w=
golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

73
server/http/http_test.go Normal file
View File

@ -0,0 +1,73 @@
package http_test
import (
"fmt"
"io/ioutil"
"net/http"
"testing"
memory "github.com/unistack-org/micro-registry-memory"
httpsrv "github.com/unistack-org/micro-server-http"
"github.com/unistack-org/micro/v3/server"
)
func TestHTTPServer(t *testing.T) {
reg := memory.NewRegistry()
// create server
srv := httpsrv.NewServer(server.Registry(reg))
// create server mux
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`hello world`))
})
// create handler
hd := srv.NewHandler(mux)
// register handler
if err := srv.Handle(hd); err != nil {
t.Fatal(err)
}
// start server
if err := srv.Start(); err != nil {
t.Fatal(err)
}
// lookup server
service, err := reg.GetService(server.DefaultName)
if err != nil {
t.Fatal(err)
}
if len(service) != 1 {
t.Fatalf("Expected 1 service got %d: %+v", len(service), service)
}
if len(service[0].Nodes) != 1 {
t.Fatalf("Expected 1 node got %d: %+v", len(service[0].Nodes), service[0].Nodes)
}
// make request
rsp, err := http.Get(fmt.Sprintf("http://%s", service[0].Nodes[0].Address))
if err != nil {
t.Fatal(err)
}
defer rsp.Body.Close()
b, err := ioutil.ReadAll(rsp.Body)
if err != nil {
t.Fatal(err)
}
if s := string(b); s != "hello world" {
t.Fatalf("Expected response %s, got %s", "hello world", s)
}
// stop server
if err := srv.Stop(); err != nil {
t.Fatal(err)
}
}

92
server/tcp/tcp_test.go Normal file
View File

@ -0,0 +1,92 @@
package tcp_test
import (
"fmt"
"io"
"net"
"testing"
"time"
bmemory "github.com/unistack-org/micro-broker-memory"
rmemory "github.com/unistack-org/micro-registry-memory"
tcp "github.com/unistack-org/micro-server-tcp"
"github.com/unistack-org/micro/v3/broker"
"github.com/unistack-org/micro/v3/logger"
"github.com/unistack-org/micro/v3/server"
)
type testHandler struct {
done chan struct{}
}
func TestTCPServer(t *testing.T) {
reg := rmemory.NewRegistry()
brk := bmemory.NewBroker(broker.Registry(reg))
// create server
srv := tcp.NewServer(server.Registry(reg), server.Broker(brk), server.Address("127.0.0.1:65000"))
// create handler
h := &testHandler{done: make(chan struct{})}
// register handler
if err := srv.Handle(srv.NewHandler(h)); err != nil {
t.Fatal(err)
}
// start server
if err := srv.Start(); err != nil {
t.Fatal(err)
}
// lookup server
service, err := reg.GetService(server.DefaultName)
if err != nil {
t.Fatal(err)
}
if len(service) != 1 {
t.Fatalf("Expected 1 service got %d: %+v", len(service), service)
}
if len(service[0].Nodes) != 1 {
t.Fatalf("Expected 1 node got %d: %+v", len(service[0].Nodes), service[0].Nodes)
}
go func() {
<-h.done
// stop server
if err := srv.Stop(); err != nil {
t.Fatal(err)
}
}()
c, err := net.DialTimeout("tcp", srv.Options().Address, 5*time.Second)
if err != nil {
t.Fatal(err)
}
defer c.Close()
if _, err = c.Write([]byte("test")); err != nil {
t.Fatal(err)
}
}
func (h *testHandler) Serve(c net.Conn) {
var n int
var err error
defer c.Close()
buf := make([]byte, 1024*8) // 8k buffer
for {
n, err = c.Read(buf)
if err != nil && err == io.EOF {
return
} else if err != nil {
logger.Fatal(err)
}
fmt.Printf("%s", buf[:n])
close(h.done)
}
}

View File

@ -0,0 +1,83 @@
// +build ignore
package gobreaker
import (
"context"
"testing"
"github.com/sony/gobreaker"
"github.com/unistack-org/micro/registry/memory"
"github.com/unistack-org/micro/v3/client"
"github.com/unistack-org/micro/v3/errors"
"github.com/unistack-org/micro/v3/router"
)
func TestBreaker(t *testing.T) {
// setup
r := memory.NewRegistry()
c := client.NewClient(
// set the selector
client.Router(rrouter.NewRouter(router.Registry(registry))),
// add the breaker wrapper
client.Wrap(NewClientWrapper()),
)
req := c.NewRequest("test.service", "Test.Method", map[string]string{
"foo": "bar",
}, client.WithContentType("application/json"))
var rsp map[string]interface{}
// Force to point of trip
for i := 0; i < 6; i++ {
c.Call(context.TODO(), req, rsp)
}
err := c.Call(context.TODO(), req, rsp)
if err == nil {
t.Error("Expecting tripped breaker, got nil error")
}
merr := err.(*errors.Error)
if merr.Code != 502 {
t.Errorf("Expecting tripped breaker, got %v", err)
}
}
func TestCustomBreaker(t *testing.T) {
// setup
r := memory.NewRegistry()
c := client.NewClient(
// set the selector
client.Router(rrouter.NewRouter(router.Registry(registry))),
// add the breaker wrapper
client.Wrap(NewCustomClientWrapper(
gobreaker.Settings{},
BreakService,
)),
)
req := c.NewRequest("test.service", "Test.Method", map[string]string{
"foo": "bar",
}, client.WithContentType("application/json"))
var rsp map[string]interface{}
// Force to point of trip
for i := 0; i < 6; i++ {
c.Call(context.TODO(), req, rsp)
}
err := c.Call(context.TODO(), req, rsp)
if err == nil {
t.Error("Expecting tripped breaker, got nil error")
}
merr := err.(*errors.Error)
if merr.Code != 502 {
t.Errorf("Expecting tripped breaker, got %v", err)
}
}

View File

@ -0,0 +1,46 @@
// +build ignore
package hystrix
import (
"context"
"testing"
"github.com/afex/hystrix-go/hystrix"
rrouter "github.com/unistack-org/micro-router-registry"
"github.com/unistack-org/micro/registry/memory"
"github.com/unistack-org/micro/v3/client"
"github.com/unistack-org/micro/v3/router"
)
func TestBreaker(t *testing.T) {
// setup
registry := memory.NewRegistry()
c := client.NewClient(
// set the selector
client.Router(rrouter.NewRouter(router.Registry(registry))),
// add the breaker wrapper
client.Wrap(NewClientWrapper()),
)
req := c.NewRequest("test.service", "Test.Method", map[string]string{
"foo": "bar",
}, client.WithContentType("application/json"))
var rsp map[string]interface{}
// Force to point of trip
for i := 0; i < (hystrix.DefaultVolumeThreshold * 3); i++ {
c.Call(context.TODO(), req, rsp)
}
err := c.Call(context.TODO(), req, rsp)
if err == nil {
t.Error("Expecting tripped breaker, got nil error")
}
if err.Error() != "hystrix: circuit open" {
t.Errorf("Expecting tripped breaker, got %v", err)
}
}

View File

@ -0,0 +1,133 @@
// +build ignore
package ratelimit
import (
"context"
"fmt"
"testing"
"time"
"github.com/juju/ratelimit"
bmemory "github.com/unistack-org/micro-broker-memory"
tmemory "github.com/unistack-org/micro-network-transport-memory"
rmemory "github.com/unistack-org/micro-registry-memory"
rrouter "github.com/unistack-org/micro-router-registry"
"github.com/unistack-org/micro/v3/client"
"github.com/unistack-org/micro/v3/errors"
"github.com/unistack-org/micro/v3/router"
"github.com/unistack-org/micro/v3/server"
)
type testHandler struct{}
type TestRequest struct{}
type TestResponse struct{}
func (t *testHandler) Method(ctx context.Context, req *TestRequest, rsp *TestResponse) error {
return nil
}
func TestRateClientLimit(t *testing.T) {
// setup
r := rmemory.NewRegistry()
tr := tmemory.NewTransport()
testRates := []int{1, 10, 20}
for _, limit := range testRates {
b := ratelimit.NewBucketWithRate(float64(limit), int64(limit))
c := client.NewClient(
client.Router(rrouter.NewRouter(router.Registry(registry))),
client.Transport(tr),
// add the breaker wrapper
client.Wrap(NewClientWrapper(b, false)),
)
req := c.NewRequest(
"test.service",
"Test.Method",
&TestRequest{},
client.WithContentType("application/json"),
)
rsp := TestResponse{}
for j := 0; j < limit; j++ {
err := c.Call(context.TODO(), req, &rsp)
e := errors.Parse(err.Error())
if e.Code == 429 {
t.Errorf("Unexpected rate limit error: %v", err)
}
}
err := c.Call(context.TODO(), req, rsp)
e := errors.Parse(err.Error())
if e.Code != 429 {
t.Errorf("Expected rate limit error, got: %v", err)
}
}
}
func TestRateServerLimit(t *testing.T) {
// setup
testRates := []int{1, 5, 6, 10}
for _, limit := range testRates {
r := rmemory.NewRegistry()
b := bmemory.NewBroker()
tr := tmemory.NewTransport()
_ = b
br := ratelimit.NewBucketWithRate(float64(limit), int64(limit))
c := client.NewClient(
client.Router(rrouter.NewRouter(router.Registry(registry))),
client.Transport(tr))
name := fmt.Sprintf("test.service.%d", limit)
srv := server.NewServer(
server.Name(name),
// add registry
server.Registry(r),
server.Transport(tr),
// add broker
//server.Broker(b),
// add the breaker wrapper
server.WrapHandler(NewHandlerWrapper(br, false)),
)
type Test struct {
*testHandler
}
srv.Handle(
srv.NewHandler(&Test{new(testHandler)}),
)
if err := srv.Start(); err != nil {
t.Fatalf("Unexpected error starting server: %v", err)
}
req := c.NewRequest(name, "Test.Method", &TestRequest{}, client.WithContentType("application/json"))
rsp := TestResponse{}
for j := 0; j < limit; j++ {
if err := c.Call(context.TODO(), req, &rsp); err != nil {
t.Fatalf("Unexpected request error: %v", err)
}
}
err := c.Call(context.TODO(), req, &rsp)
if err == nil {
t.Fatalf("Expected rate limit error, got nil: rate %d, err %v", limit, err)
}
e := errors.Parse(err.Error())
if e.Code != 429 {
t.Fatalf("Expected rate limit error, got %v", err)
}
srv.Stop()
// artificial test delay
time.Sleep(500 * time.Millisecond)
}
}

View File

@ -0,0 +1,208 @@
// +build ignore
package datadog
import (
"context"
"sync"
"testing"
"github.com/stretchr/testify/assert"
rrouter "github.com/unistack-org/micro-router-registry"
"github.com/unistack-org/micro/registry/memory"
"github.com/unistack-org/micro/v3/client"
microerr "github.com/unistack-org/micro/v3/errors"
"github.com/unistack-org/micro/v3/router"
"github.com/unistack-org/micro/v3/server"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/ext"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/mocktracer"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
cli "github.com/unistack-org/micro/v3/client"
srv "github.com/unistack-org/micro/v3/server"
)
type Test interface {
Method(ctx context.Context, in *TestRequest, opts ...client.CallOption) (*TestResponse, error)
}
type TestRequest struct {
IsError bool
}
type TestResponse struct {
Message string
}
type testHandler struct{}
func (t *testHandler) Method(ctx context.Context, req *TestRequest, rsp *TestResponse) error {
if req.IsError {
return microerr.BadRequest("bad", "test error")
}
rsp.Message = "passed"
return nil
}
func TestClient(t *testing.T) {
// setup
assert := assert.New(t)
for name, tt := range map[string]struct {
message string
isError bool
wantMessage string
wantStatus string
}{
"OK": {
message: "passed",
isError: false,
wantMessage: "passed",
wantStatus: "OK",
},
"Invalid": {
message: "",
isError: true,
wantMessage: "",
wantStatus: "InvalidArgument",
},
} {
t.Run(name, func(t *testing.T) {
mt := mocktracer.Start()
defer mt.Stop()
registry := memory.NewRegistry()
serverName := "micro.server.name"
serverID := "id-1234567890"
serverVersion := "1.0.0"
c := cli.NewClient(
client.Router(rrouter.NewRouter(router.Registry(registry))),
client.WrapCall(NewCallWrapper()),
)
s := srv.NewServer(
server.Name(serverName),
server.Version(serverVersion),
server.Id(serverID),
server.Registry(registry),
server.WrapSubscriber(NewSubscriberWrapper()),
server.WrapHandler(NewHandlerWrapper()),
)
defer s.Stop()
type Test struct {
*testHandler
}
s.Handle(s.NewHandler(&Test{new(testHandler)}))
if err := s.Start(); err != nil {
t.Fatalf("Unexpected error starting server: %v", err)
}
span, ctx := StartSpanFromContext(context.Background(), "root", tracer.ServiceName("root"), tracer.ResourceName("root"))
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 {
assert.NoError(err)
}
assert.Equal(rsp.Message, tt.message)
span.Finish()
spans := mt.FinishedSpans()
assert.Len(spans, 3)
var serverSpan, clientSpan, rootSpan mocktracer.Span
for _, s := range spans {
// order of traces in buffer is not garanteed
switch s.OperationName() {
case "micro.server":
serverSpan = s
case "micro.client":
clientSpan = s
case "root":
rootSpan = s
}
}
assert.NotNil(serverSpan)
assert.NotNil(clientSpan)
assert.NotNil(rootSpan)
assert.Equal(rootSpan.TraceID(), clientSpan.TraceID())
assert.Equal(serverSpan.Tag(tagStatus), tt.wantStatus)
assert.Equal("Test.Method", serverSpan.Tag(ext.ResourceName))
assert.Equal(rootSpan.TraceID(), serverSpan.TraceID())
})
}
}
func TestRace(t *testing.T) {
// setup
assert := assert.New(t)
mt := mocktracer.Start()
defer mt.Stop()
registry := memory.NewRegistry()
serverName := "micro.server.name"
serverID := "id-1234567890"
serverVersion := "1.0.0"
c := cli.NewClient(
client.Router(rrouter.NewRouter(router.Registry(registry))),
client.WrapCall(NewCallWrapper()),
)
s := srv.NewServer(
server.Name(serverName),
server.Version(serverVersion),
server.Id(serverID),
server.Registry(registry),
server.WrapSubscriber(NewSubscriberWrapper()),
server.WrapHandler(NewHandlerWrapper()),
)
defer s.Stop()
type Test struct {
*testHandler
}
s.Handle(s.NewHandler(&Test{new(testHandler)}))
if err := s.Start(); err != nil {
t.Fatalf("Unexpected error starting server: %v", err)
}
span, ctx := StartSpanFromContext(context.Background(), "root", tracer.ServiceName("root"), tracer.ResourceName("root"))
num := 100
var wg sync.WaitGroup
wg.Add(num)
for i := 0; i < num; i++ {
func() {
go func(i int) {
defer wg.Done()
req := c.NewRequest(serverName, "Test.Method", &TestRequest{IsError: false}, client.WithContentType("application/json"))
rsp := TestResponse{}
err := c.Call(ctx, req, &rsp)
assert.NoError(err)
}(i)
}()
}
wg.Wait()
span.Finish()
spans := mt.FinishedSpans()
assert.Len(spans, (num*2)+1)
}