1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-24 10:07:04 +02:00
go-micro/server/mock/mock_test.go
2016-04-16 00:02:55 +01:00

58 lines
1.1 KiB
Go

package mock
import (
"testing"
"github.com/micro/go-micro/server"
)
func TestMockServer(t *testing.T) {
srv := NewServer(
server.Name("mock"),
server.Version("latest"),
)
if srv.Options().Name != "mock" {
t.Fatalf("Expected name mock, got %s", srv.Options().Name)
}
if srv.Options().Version != "latest" {
t.Fatalf("Expected version latest, got %s", srv.Options().Version)
}
srv.Init(server.Version("test"))
if srv.Options().Version != "test" {
t.Fatalf("Expected version test, got %s", srv.Options().Version)
}
h := srv.NewHandler(func() string { return "foo" })
if err := srv.Handle(h); err != nil {
t.Fatal(err)
}
sub := srv.NewSubscriber("test", func() string { return "foo" })
if err := srv.Subscribe(sub); err != nil {
t.Fatal(err)
}
if sub.Topic() != "test" {
t.Fatalf("Expected topic test got %s", sub.Topic())
}
if err := srv.Start(); err != nil {
t.Fatal(err)
}
if err := srv.Register(); err != nil {
t.Fatal(err)
}
if err := srv.Deregister(); err != nil {
t.Fatal(err)
}
if err := srv.Stop(); err != nil {
t.Fatal(err)
}
}