test
This commit is contained in:
snoop 2017-05-22 12:12:20 +09:00
parent 92e8bed70e
commit 444c83a371
2 changed files with 99 additions and 1 deletions

View File

@ -1,7 +1,100 @@
package event
import "testing"
import (
"testing"
"net"
"google.golang.org/grpc"
gt "loafle.com/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()
}

View File

@ -4,6 +4,7 @@ package event
import (
gt "loafle.com/overflow/central_api_gateway/event"
"golang.org/x/net/context"
"log"
)
@ -15,6 +16,8 @@ type TaskResultServerImpl struct {
func (d *TaskResultServerImpl)Event(c context.Context,te *gt.TaskResultEvent) (*gt.Empty, error) {
et := &gt.Empty{}
log.Println(te.Data["Description"])
return et, nil
}
@ -27,5 +30,7 @@ type EventServerImpl struct {
func (d *EventServerImpl)Event(c context.Context,ae *gt.AgentEvent) (*gt.Empty, error) {
et := &gt.Empty{}
log.Println(ae.Description)
return et, nil
}