flow: create tests
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
@@ -5,21 +5,40 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
pb "github.com/unistack-org/micro-tests/client/http/proto"
|
||||
httpcli "github.com/unistack-org/micro-client-http/v3"
|
||||
jsonpbcodec "github.com/unistack-org/micro-codec-jsonpb/v3"
|
||||
httpsrv "github.com/unistack-org/micro-server-http/v3"
|
||||
pb "github.com/unistack-org/micro-tests/flow/proto"
|
||||
"github.com/unistack-org/micro/v3"
|
||||
"github.com/unistack-org/micro/v3/client"
|
||||
"github.com/unistack-org/micro/v3/flow"
|
||||
"github.com/unistack-org/micro/v3/logger"
|
||||
"github.com/unistack-org/micro/v3/meter"
|
||||
"github.com/unistack-org/micro/v3/server"
|
||||
"github.com/unistack-org/micro/v3/store"
|
||||
"github.com/unistack-org/micro/v3/tracer"
|
||||
)
|
||||
|
||||
type handler struct{}
|
||||
|
||||
func (h *handler) LookupUser(ctx context.Context, req *pb.LookupUserReq, rsp *pb.LookupUserRsp) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestFlow(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
logger.DefaultLogger = logger.NewLogger(logger.WithLevel(logger.TraceLevel))
|
||||
|
||||
s := store.DefaultStore
|
||||
c := client.DefaultClient
|
||||
c := client.NewClientCallOptions(
|
||||
httpcli.NewClient(
|
||||
client.ContentType("application/json"),
|
||||
client.Codec("application/json", jsonpbcodec.NewCodec()),
|
||||
),
|
||||
client.WithAddress("http://127.0.0.1:7989"),
|
||||
)
|
||||
m := meter.DefaultMeter
|
||||
tr := tracer.DefaultTracer
|
||||
l := logger.DefaultLogger
|
||||
@@ -30,18 +49,47 @@ func TestFlow(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
options := append([]micro.Option{},
|
||||
micro.Server(
|
||||
httpsrv.NewServer(
|
||||
server.Codec("application/json", jsonpbcodec.NewCodec()),
|
||||
server.Address("127.0.0.1:7989"),
|
||||
),
|
||||
),
|
||||
micro.Context(ctx),
|
||||
)
|
||||
|
||||
svc := micro.NewService(options...)
|
||||
|
||||
if err := svc.Init(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
h := &handler{}
|
||||
|
||||
if err := pb.RegisterTestServiceServer(svc.Server(), h); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
go func() {
|
||||
if err := svc.Run(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}()
|
||||
|
||||
time.Sleep(2 * time.Second)
|
||||
steps := []flow.Step{
|
||||
flow.NewCallStep("test", "Github.LookupUser", flow.StepID("test.Github.LookupUser")),
|
||||
flow.NewCallStep("test", "Github.UpdateUser", flow.StepRequires("test.Github.LookupUser")),
|
||||
flow.NewCallStep("test", "Github.RemoveUser", flow.StepRequires("test.Github.UpdateUser")),
|
||||
flow.NewCallStep("test", "Github.MailUser", flow.StepRequires("test.Github.UpdateUser")),
|
||||
flow.NewCallStep("test", pb.TestServiceName, "LookupUser", flow.StepID("test.TestService.LookupUser")),
|
||||
flow.NewCallStep("test", pb.TestServiceName, "UpdateUser", flow.StepRequires("test.TestService.LookupUser")),
|
||||
flow.NewCallStep("test", pb.TestServiceName, "RemoveUser", flow.StepRequires("test.TestService.UpdateUser")),
|
||||
flow.NewCallStep("test", pb.TestServiceName, "MailUser", flow.StepRequires("test.TestService.UpdateUser")),
|
||||
}
|
||||
w, err := f.WorkflowCreate(ctx, "test", steps...)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
req := &pb.LookupUserReq{Username: "vtolstov"}
|
||||
req := &pb.LookupUserReq{Name: "vtolstov"}
|
||||
id, err := w.Execute(ctx, req, flow.ExecuteTimeout(2*time.Second))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
Reference in New Issue
Block a user