444c83a371
test
100 lines
1.4 KiB
Go
100 lines
1.4 KiB
Go
package event
|
|
|
|
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()
|
|
|
|
|
|
} |