central_api_gateway_event/event/event_test.go

100 lines
1.4 KiB
Go
Raw Normal View History

2017-05-20 09:48:36 +00:00
package event
2017-05-22 03:12:20 +00:00
import (
"testing"
"net"
"google.golang.org/grpc"
gt "loafle.com/overflow/central_api_gateway/event"
"golang.org/x/net/context"
"time"
)
2017-05-20 09:48:36 +00:00
func TestDefault(t *testing.T) {
t.Log("aaa")
2017-05-22 03:12:20 +00:00
}
func RunServer( t *testing.T) {
lis, err := net.Listen("tcp","localhost:50000")
if err != nil {
t.Fatal(err)
}
s := grpc.NewServer()
gt.RegisterEventServer(s, &EventServerImpl{})
gt.RegisterTaskResultServer(s, &TaskResultServerImpl{})
if err := s.Serve(lis); err != nil {
t.Fatalf("failed to serve: %v", err)
}
}
func TestGateWayEvent(t *testing.T) {
go RunServer(t)
time.Sleep(time.Second * 2)
conn, err := grpc.Dial("localhost:50000", grpc.WithInsecure())
if err != nil {
t.Fatal(err)
}
defer conn.Close()
ec := gt.NewEventClient(conn)
ae := &gt.AgentEvent{}
ae.Description = "test description222222222"
out, err := ec.Event(context.Background(), ae)
if err != nil {
t.Fatal(err)
}
out.String()
}
func TestGateWayTaskResult(t *testing.T) {
go RunServer(t)
time.Sleep(time.Second * 2)
conn, err := grpc.Dial("localhost:50000", grpc.WithInsecure())
if err != nil {
t.Fatal(err)
}
defer conn.Close()
ec := gt.NewTaskResultClient(conn)
re := &gt.TaskResultEvent{}
re.Data = make(map[string]string)
re.Data["Description"] = "Task Result Event Test"
out, err := ec.Event(context.Background(), re)
if err != nil {
t.Fatal(err)
}
out.String()
2017-05-20 09:48:36 +00:00
}