central_api_gateway_event/event/event_test.go
snoop 42afe8ef97 fixed
address
2017-05-29 19:43:27 +09:00

100 lines
1.4 KiB
Go

package event
import (
"testing"
"net"
"google.golang.org/grpc"
gt "git.loafle.net/overflow/central_api_gateway/event"
"golang.org/x/net/context"
"time"
)
func TestDefault(t *testing.T) {
t.Log("aaa")
}
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()
}