# Testing http handler that executes a workflow

**URL:** <https://community.temporal.io/t/testing-http-handler-that-executes-a-workflow/2712>\
**Category:** Community Support\
**Tags:** go-sdk\
**Created:** [August 13, 2021, 2:31pm UTC](https://community.temporal.io/t/testing-http-handler-that-executes-a-workflow/2712 "2021-08-13T14:31:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yeshwanth\_Kumar](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/yeshwanth_kumar/32/1206_2.png) [@yeshwanth\_Kumar](https://community.temporal.io/u/yeshwanth_Kumar)\
**Post date:** [August 13, 2021, 2:31pm UTC](https://community.temporal.io/t/testing-http-handler-that-executes-a-workflow/2712/1 "2021-08-13T14:31:06Z")

</div>

I have an HTTP handler that executes a workflow.

````auto
func () someHandler(w http.ResponseWriter, r *http.Request) {
	workflowOptions := client.StartWorkflowOptions{
		ID: id,
		TaskQueue: c.OrderTasksQueueName,
	}
	we, err = c.TemporalClient.ExecuteWorkflow(context.Background(), workflowOptions, "MyWorkflow")
response := ""
	responseErr := we.Get(context.Background(), &response)
	if responseErr != nil {
		c.Logger.Error("Cannot get workflow result")
	}
	if err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		_, _ = w.Write([]byte("Unable to execute workflow"))
		return
	}

	w.WriteHeader(http.StatusAccepted)

result := fmt.Sprintf("{WorkflowRunID: %s, OrderID: %s, Result: %s}", we.GetRunID(), we.GetID(),
		response)	_, _ = w.Write([]byte(result))
}```

1. How do I write unit tests for this handler. How can I get this workflow to execute without mocking. 
2. Can I mock the workflow execution somehow and just test the handler logic?

Any help is appreciated. 
Thanks
````

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [August 13, 2021, 4:14pm UTC](https://community.temporal.io/t/testing-http-handler-that-executes-a-workflow/2712/2 "2021-08-13T16:14:06Z")

</div>

Use the [Client mock](https://github.com/temporalio/sdk-go/blob/master/mocks/Client.go) included in the Go SDK.

---

<div class="post-metadata">

**Author:** ![yeshwanth\_Kumar](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/yeshwanth_kumar/32/1206_2.png) [@yeshwanth\_Kumar](https://community.temporal.io/u/yeshwanth_Kumar)\
**Post date:** [August 13, 2021, 7:14pm UTC](https://community.temporal.io/t/testing-http-handler-that-executes-a-workflow/2712/3 "2021-08-13T19:14:47Z")

</div>

Thanks for the reply i was able to mock my workflow execution and now ran into an issue with workflowRun.Get(ctx, valuePtr) function.

How do i mock it ? i have this - `workflowRunMock.On("Get", mock.Anything, mock.Anything)`
