mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
add a test framework for grpc
This commit is contained in:
parent
c4e6545197
commit
02cb799481
47
weed/mq/broker/broker_test.go
Normal file
47
weed/mq/broker/broker_test.go
Normal file
|
@ -0,0 +1,47 @@
|
|||
package broker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/mq_pb"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/test/bufconn"
|
||||
)
|
||||
|
||||
var lis *bufconn.Listener
|
||||
|
||||
func init() {
|
||||
lis = bufconn.Listen(1024 * 1024)
|
||||
server := grpc.NewServer()
|
||||
mq_pb.RegisterSeaweedMessagingServer(server, &MessageQueueBroker{})
|
||||
go func() {
|
||||
if err := server.Serve(lis); err != nil {
|
||||
fmt.Printf("Server exited with error: %v", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func bufDialer(string, time.Duration) (net.Conn, error) {
|
||||
return lis.Dial()
|
||||
}
|
||||
|
||||
func TestMessageQueueBroker_ListTopics(t *testing.T) {
|
||||
conn, err := grpc.DialContext(context.Background(), "bufnet", grpc.WithDialer(bufDialer), grpc.WithInsecure())
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to dial bufnet: %v", err)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
client := mq_pb.NewSeaweedMessagingClient(conn)
|
||||
request := &mq_pb.ListTopicsRequest{}
|
||||
|
||||
_, err = client.ListTopics(context.Background(), request)
|
||||
if err == nil {
|
||||
t.Fatalf("Add failed: %v", err)
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue