From e870bffef294132534b9bab242b15f8a4a25f14e Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 1 Jun 2017 12:11:52 +0100 Subject: [PATCH] add function test --- function_test.go | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 function_test.go diff --git a/function_test.go b/function_test.go new file mode 100644 index 00000000..49209648 --- /dev/null +++ b/function_test.go @@ -0,0 +1,55 @@ +package micro + +import ( + "sync" + "testing" + + "github.com/micro/go-micro/registry/mock" + proto "github.com/micro/go-micro/server/debug/proto" + + "golang.org/x/net/context" +) + +func TestFunction(t *testing.T) { + var wg sync.WaitGroup + wg.Add(1) + + // create service + fn := NewFunction( + Name("test.function"), + Registry(mock.NewRegistry()), + AfterStart(func() error { + wg.Done() + return nil + }), + ) + + // we can't test fn.Init as it parses the command line + // fn.Init() + + go func() { + // wait for start + wg.Wait() + + // test call debug + req := fn.Client().NewRequest( + "test.function", + "Debug.Health", + new(proto.HealthRequest), + ) + + rsp := new(proto.HealthResponse) + + err := fn.Client().Call(context.TODO(), req, rsp) + if err != nil { + t.Fatal(err) + } + + if rsp.Status != "ok" { + t.Fatalf("function response: %s", rsp.Status) + } + }() + + // run service + fn.Run() +}