From 444c83a37146cc8966cc066e9dde197c02314922 Mon Sep 17 00:00:00 2001 From: snoop Date: Mon, 22 May 2017 12:12:20 +0900 Subject: [PATCH] added test --- event/event_test.go | 95 ++++++++++++++++++++++++++++++++++++++++++++- event/rpc_impl.go | 5 +++ 2 files changed, 99 insertions(+), 1 deletion(-) diff --git a/event/event_test.go b/event/event_test.go index f31389c..20c8de5 100644 --- a/event/event_test.go +++ b/event/event_test.go @@ -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 := >.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 := >.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() + + } \ No newline at end of file diff --git a/event/rpc_impl.go b/event/rpc_impl.go index a1df31c..90b828f 100644 --- a/event/rpc_impl.go +++ b/event/rpc_impl.go @@ -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 := >.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 := >.Empty{} + log.Println(ae.Description) + return et, nil }